quiesco 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/dist/cli.d.ts +2 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +11 -6
- package/dist/cli.js.map +1 -1
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +81 -7
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +108 -22
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/list.d.ts +16 -0
- package/dist/commands/list.d.ts.map +1 -0
- package/dist/commands/list.js +56 -0
- package/dist/commands/list.js.map +1 -0
- package/dist/commands/test.d.ts +20 -1
- package/dist/commands/test.d.ts.map +1 -1
- package/dist/commands/test.js +14 -6
- package/dist/commands/test.js.map +1 -1
- package/dist/commands/ui.d.ts +43 -0
- package/dist/commands/ui.d.ts.map +1 -0
- package/dist/commands/ui.js +121 -0
- package/dist/commands/ui.js.map +1 -0
- package/dist/context.d.ts +22 -0
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +31 -0
- package/dist/context.js.map +1 -1
- package/dist/dev-server.d.ts +2 -0
- package/dist/dev-server.d.ts.map +1 -1
- package/dist/dev-server.js +4 -2
- package/dist/dev-server.js.map +1 -1
- package/dist/packages.d.ts +17 -0
- package/dist/packages.d.ts.map +1 -0
- package/dist/packages.js +40 -0
- package/dist/packages.js.map +1 -0
- package/dist/progress/render.d.ts +31 -0
- package/dist/progress/render.d.ts.map +1 -0
- package/dist/progress/render.js +89 -0
- package/dist/progress/render.js.map +1 -0
- package/dist/progress/run.d.ts +24 -0
- package/dist/progress/run.d.ts.map +1 -0
- package/dist/progress/run.js +95 -0
- package/dist/progress/run.js.map +1 -0
- package/dist/progress/sticky.d.ts +25 -0
- package/dist/progress/sticky.d.ts.map +1 -0
- package/dist/progress/sticky.js +90 -0
- package/dist/progress/sticky.js.map +1 -0
- package/dist/project.d.ts +23 -0
- package/dist/project.d.ts.map +1 -0
- package/dist/project.js +74 -0
- package/dist/project.js.map +1 -0
- package/package.json +3 -3
- package/src/cli.ts +11 -7
- package/src/commands/doctor.ts +83 -7
- package/src/commands/init.ts +101 -19
- package/src/commands/list.ts +65 -0
- package/src/commands/test.ts +17 -7
- package/src/commands/ui.ts +152 -0
- package/src/context.ts +50 -0
- package/src/dev-server.ts +6 -2
- package/src/packages.ts +42 -0
- package/src/progress/render.ts +117 -0
- package/src/progress/run.ts +105 -0
- package/src/progress/sticky.ts +95 -0
- package/src/project.ts +76 -0
package/src/cli.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/** Command dispatch for the `quiesco` binary (requirements.md §6.12). */
|
|
2
|
-
import { createRequire } from 'node:module';
|
|
3
2
|
|
|
4
3
|
import { buildCommand } from './commands/build.js';
|
|
5
4
|
import { devicesCommand } from './commands/devices.js';
|
|
6
5
|
import { doctorCommand } from './commands/doctor.js';
|
|
7
6
|
import { initCommand } from './commands/init.js';
|
|
7
|
+
import { listCommand } from './commands/list.js';
|
|
8
8
|
import { testCommand } from './commands/test.js';
|
|
9
9
|
import { treeCommand } from './commands/tree.js';
|
|
10
|
+
import { uiCommand } from './commands/ui.js';
|
|
10
11
|
import type { CliContext } from './context.js';
|
|
11
12
|
import { defaultContext } from './context.js';
|
|
12
13
|
|
|
@@ -19,6 +20,10 @@ Commands:
|
|
|
19
20
|
ios|android --force (also when the native inputs did not change)
|
|
20
21
|
test Run the tests with cucumber-js (or --runner jest|vitest); other arguments go to the runner unchanged
|
|
21
22
|
--platform ios|android|web --workers N (N devices in parallel) (quiesco test --help for more)
|
|
23
|
+
ui Open the test UI: run tests from the browser and watch them live (needs @quiesco/ui)
|
|
24
|
+
--platform ios|android|web --runner … --port N --no-open
|
|
25
|
+
list List the tests the runner would run, without running them
|
|
26
|
+
--runner cucumber|jest|vitest --json
|
|
22
27
|
doctor Check the tools and the project setup
|
|
23
28
|
--platform ios|android|web
|
|
24
29
|
tree Print the element tree of the running app (to find testIDs)
|
|
@@ -30,11 +35,6 @@ Options:
|
|
|
30
35
|
-h, --help Show this help
|
|
31
36
|
-v, --version Show the version`;
|
|
32
37
|
|
|
33
|
-
function version(): string {
|
|
34
|
-
const require = createRequire(import.meta.url);
|
|
35
|
-
return (require('../package.json') as { version: string }).version;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
38
|
export async function main(argv: readonly string[], ctx: CliContext = defaultContext()): Promise<number> {
|
|
39
39
|
const [command, ...args] = argv;
|
|
40
40
|
try {
|
|
@@ -45,6 +45,10 @@ export async function main(argv: readonly string[], ctx: CliContext = defaultCon
|
|
|
45
45
|
return await buildCommand(args, ctx);
|
|
46
46
|
case 'test':
|
|
47
47
|
return await testCommand(args, ctx);
|
|
48
|
+
case 'ui':
|
|
49
|
+
return await uiCommand(args, ctx);
|
|
50
|
+
case 'list':
|
|
51
|
+
return await listCommand(args, ctx);
|
|
48
52
|
case 'doctor':
|
|
49
53
|
return await doctorCommand(args, ctx);
|
|
50
54
|
case 'tree':
|
|
@@ -53,7 +57,7 @@ export async function main(argv: readonly string[], ctx: CliContext = defaultCon
|
|
|
53
57
|
return await devicesCommand(args, ctx);
|
|
54
58
|
case '-v':
|
|
55
59
|
case '--version':
|
|
56
|
-
ctx.out(version
|
|
60
|
+
ctx.out(ctx.version);
|
|
57
61
|
return 0;
|
|
58
62
|
case undefined:
|
|
59
63
|
case '-h':
|
package/src/commands/doctor.ts
CHANGED
|
@@ -11,6 +11,8 @@ import { loadConfig, serverPort } from '@quiesco/core';
|
|
|
11
11
|
|
|
12
12
|
import type { CliContext, CliPlatform } from '../context.js';
|
|
13
13
|
import { PLATFORMS, parsePlatform, takeOption } from '../context.js';
|
|
14
|
+
import { CLI_COMMANDS, installedVersion, isQuiescoPackage, scriptCommands } from '../packages.js';
|
|
15
|
+
import { rootSourceFiles } from '../project.js';
|
|
14
16
|
|
|
15
17
|
export type CheckStatus = 'ok' | 'warn' | 'fail';
|
|
16
18
|
|
|
@@ -31,6 +33,7 @@ const ICON: Record<CheckStatus, string> = { ok: '✅', warn: '⚠️ ', fail: '
|
|
|
31
33
|
|
|
32
34
|
interface PackageJson {
|
|
33
35
|
main?: string;
|
|
36
|
+
scripts?: Record<string, string>;
|
|
34
37
|
dependencies?: Record<string, string>;
|
|
35
38
|
devDependencies?: Record<string, string>;
|
|
36
39
|
}
|
|
@@ -83,6 +86,8 @@ function projectChecks(ctx: CliContext): CheckResult[] {
|
|
|
83
86
|
: { name: 'Quiesco packages', status: 'fail', detail: `missing ${missing.join(', ')}`, fix: 'Run `npx quiesco init`, or install them.' },
|
|
84
87
|
);
|
|
85
88
|
|
|
89
|
+
results.push(...versionChecks(ctx, pkg));
|
|
90
|
+
|
|
86
91
|
const appJson = readJson<{ expo?: { plugins?: unknown[] } }>(ctx, path.join(ctx.cwd, 'app.json'));
|
|
87
92
|
const plugins = appJson?.expo?.plugins ?? [];
|
|
88
93
|
const listed = plugins.some((p) => p === '@quiesco/expo-plugin' || (Array.isArray(p) && p[0] === '@quiesco/expo-plugin'));
|
|
@@ -131,11 +136,83 @@ function projectChecks(ctx: CliContext): CheckResult[] {
|
|
|
131
136
|
return results;
|
|
132
137
|
}
|
|
133
138
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
+
/**
|
|
140
|
+
* Issue #17: every Quiesco package in package.json is installed at one version, and every `quiesco <cmd>`
|
|
141
|
+
* in the scripts exists in it.
|
|
142
|
+
*/
|
|
143
|
+
function versionChecks(ctx: CliContext, pkg: PackageJson): CheckResult[] {
|
|
144
|
+
const results: CheckResult[] = [];
|
|
145
|
+
const names = [...new Set([...Object.keys(pkg.dependencies ?? {}), ...Object.keys(pkg.devDependencies ?? {})])].filter(isQuiescoPackage).sort();
|
|
146
|
+
if (names.length === 0) return results;
|
|
147
|
+
const installed = names.map((name) => ({ name, version: installedVersion(ctx, name) }));
|
|
148
|
+
const missing = installed.filter((p) => p.version === null).map((p) => p.name);
|
|
149
|
+
const versions = [...new Set(installed.flatMap((p) => (p.version !== null ? [p.version] : [])))];
|
|
150
|
+
const list = installed.map((p) => `${p.name} ${p.version ?? '(not installed)'}`).join(', ');
|
|
151
|
+
let project: string | undefined;
|
|
152
|
+
if (missing.length > 0) {
|
|
153
|
+
results.push({ name: 'Quiesco versions', status: 'fail', detail: `not installed: ${missing.join(', ')}`, fix: 'Install the dependencies (npm install / pnpm install).' });
|
|
154
|
+
} else if (versions.length > 1) {
|
|
155
|
+
const newest = [...versions].sort(compareVersions).at(-1) as string;
|
|
156
|
+
results.push({
|
|
157
|
+
name: 'Quiesco versions',
|
|
158
|
+
status: 'fail',
|
|
159
|
+
detail: `different versions: ${list}`,
|
|
160
|
+
fix: `Quiesco's packages are released together and only work with the same version. Install one version of all of them, e.g. ${names.map((n) => `${n}@${newest}`).join(' ')}.`,
|
|
161
|
+
});
|
|
162
|
+
} else {
|
|
163
|
+
project = versions[0] as string;
|
|
164
|
+
results.push(
|
|
165
|
+
project === ctx.version
|
|
166
|
+
? { name: 'Quiesco versions', status: 'ok', detail: `${names.length} packages at ${project}` }
|
|
167
|
+
: {
|
|
168
|
+
name: 'Quiesco versions',
|
|
169
|
+
status: 'warn',
|
|
170
|
+
detail: `the project has ${project}; this doctor is ${ctx.version}`,
|
|
171
|
+
fix: "Run the project's own CLI (npx quiesco doctor in the project directory), or upgrade the project's Quiesco packages to the same version.",
|
|
172
|
+
},
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
const unknown = scriptCommands(pkg.scripts).filter((c) => !(CLI_COMMANDS as readonly string[]).includes(c.command));
|
|
176
|
+
if (unknown.length > 0) {
|
|
177
|
+
results.push({
|
|
178
|
+
name: 'scripts',
|
|
179
|
+
status: 'fail',
|
|
180
|
+
detail: unknown.map((c) => `"${c.script}" runs \`quiesco ${c.command}\``).join(', '),
|
|
181
|
+
fix: `quiesco ${ctx.version} has no such command (it has ${CLI_COMMANDS.join(', ')}). ${project !== undefined && project !== ctx.version ? `The project has Quiesco ${project}; upgrade it, or ` : ''}Fix the script.`,
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
return results;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** Numeric semver order (prerelease tags compare as text). */
|
|
188
|
+
function compareVersions(a: string, b: string): number {
|
|
189
|
+
const pa = a.split(/[.-]/);
|
|
190
|
+
const pb = b.split(/[.-]/);
|
|
191
|
+
for (let i = 0; i < Math.max(pa.length, pb.length); i++) {
|
|
192
|
+
const x = pa[i] ?? '';
|
|
193
|
+
const y = pb[i] ?? '';
|
|
194
|
+
const d = /^\d+$/.test(x) && /^\d+$/.test(y) ? Number(x) - Number(y) : x.localeCompare(y);
|
|
195
|
+
if (d !== 0) return d;
|
|
196
|
+
}
|
|
197
|
+
return 0;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Issue #20: the agent connects from <QuiescoRoot> and the soft reset remounts the app through it, so a
|
|
202
|
+
* missing one fails (CONNECT_TIMEOUT on every run) whatever the reset mode.
|
|
203
|
+
*/
|
|
204
|
+
function rootCheck(ctx: CliContext, main: string | undefined): CheckResult {
|
|
205
|
+
const files = rootSourceFiles(ctx, main);
|
|
206
|
+
const found = files.find((f) => (ctx.readFile(f) ?? '').includes('QuiescoRoot'));
|
|
207
|
+
const rel = (f: string): string => path.relative(ctx.cwd, f);
|
|
208
|
+
return found !== undefined
|
|
209
|
+
? { name: '<QuiescoRoot>', status: 'ok', detail: `in ${rel(found)}` }
|
|
210
|
+
: {
|
|
211
|
+
name: '<QuiescoRoot>',
|
|
212
|
+
status: 'fail',
|
|
213
|
+
detail: `not found in ${files.length > 0 ? files.map(rel).join(', ') : 'app/_layout, src/app/_layout, App or the entry file'}`,
|
|
214
|
+
fix: "Wrap the app's root in it: import { QuiescoRoot } from '@quiesco/agent'; <QuiescoRoot>…</QuiescoRoot> (the root layout, or the component the entry registers). The app connects to Quiesco from it, and the soft reset before each scenario remounts the app through it: without it no test can run.",
|
|
215
|
+
};
|
|
139
216
|
}
|
|
140
217
|
|
|
141
218
|
async function platformChecks(ctx: CliContext, platform: CliPlatform, config: QuiescoConfig | null): Promise<CheckResult[]> {
|
|
@@ -257,8 +334,7 @@ export async function runChecks(ctx: CliContext, only: CliPlatform | undefined,
|
|
|
257
334
|
});
|
|
258
335
|
}
|
|
259
336
|
results.push(...projectChecks(ctx));
|
|
260
|
-
|
|
261
|
-
results.push(rootCheck(ctx, sources));
|
|
337
|
+
results.push(rootCheck(ctx, readJson<PackageJson>(ctx, path.join(ctx.cwd, 'package.json'))?.main));
|
|
262
338
|
|
|
263
339
|
let config: QuiescoConfig | null = null;
|
|
264
340
|
try {
|
package/src/commands/init.ts
CHANGED
|
@@ -11,6 +11,8 @@ import path from 'node:path';
|
|
|
11
11
|
|
|
12
12
|
import type { CliContext, CliPlatform } from '../context.js';
|
|
13
13
|
import { PLATFORMS, takeFlag, takeOption } from '../context.js';
|
|
14
|
+
import { installedVersion, isQuiescoPackage } from '../packages.js';
|
|
15
|
+
import { entryFile, registeredRoot, rootSourceFiles, wrapRegisteredRoot } from '../project.js';
|
|
14
16
|
|
|
15
17
|
type PackageManager = 'npm' | 'pnpm' | 'yarn' | 'bun';
|
|
16
18
|
|
|
@@ -22,7 +24,6 @@ interface PackageJson {
|
|
|
22
24
|
devDependencies?: Record<string, string>;
|
|
23
25
|
overrides?: Record<string, string>;
|
|
24
26
|
resolutions?: Record<string, string>;
|
|
25
|
-
pnpm?: { overrides?: Record<string, string> };
|
|
26
27
|
[key: string]: unknown;
|
|
27
28
|
}
|
|
28
29
|
|
|
@@ -64,6 +65,11 @@ export function findTarballs(dir: string, names: readonly string[], list: (d: st
|
|
|
64
65
|
return found;
|
|
65
66
|
}
|
|
66
67
|
|
|
68
|
+
/** An `overrides:` block for pnpm-workspace.yaml (names and paths quoted: `@` starts no plain YAML scalar). */
|
|
69
|
+
function pnpmOverrides(pins: Record<string, string>): string {
|
|
70
|
+
return `overrides:\n${Object.entries(pins).map(([n, f]) => ` ${JSON.stringify(n)}: ${JSON.stringify(f)}\n`).join('')}`;
|
|
71
|
+
}
|
|
72
|
+
|
|
67
73
|
function addCommand(pm: PackageManager, dev: boolean, specs: string[]): { command: string; args: string[] } {
|
|
68
74
|
switch (pm) {
|
|
69
75
|
case 'pnpm':
|
|
@@ -173,6 +179,10 @@ const CUCUMBER_CONFIG = `export default {
|
|
|
173
179
|
|
|
174
180
|
const SUPPORT = `// this.app (the Quiesco driver) in every step, and the lifecycle hooks: one app session per run,
|
|
175
181
|
// a soft reset before each scenario, screenshot + element tree on failure.
|
|
182
|
+
//
|
|
183
|
+
// Step and support files run with Node's type stripping, not tsc: relative imports name the .ts file
|
|
184
|
+
// (import { TodoDriver } from './todo-driver.ts'), and TypeScript syntax that generates code is not
|
|
185
|
+
// supported (parameter properties such as constructor(private app: Driver), enum, namespace).
|
|
176
186
|
import '@quiesco/cucumber/register';
|
|
177
187
|
`;
|
|
178
188
|
|
|
@@ -231,10 +241,14 @@ export async function initCommand(args: readonly string[], ctx: CliContext): Pro
|
|
|
231
241
|
// 1. Dependencies.
|
|
232
242
|
const runtime = [...RUNTIME];
|
|
233
243
|
const dev = [...DEV, ...(platforms.includes('web') ? WEB_DEV : [])];
|
|
234
|
-
|
|
244
|
+
// Issue #17: the version of this CLI, not whatever the registry metadata in the package manager's cache
|
|
245
|
+
// calls latest (a project on an older Quiesco than the scripts init writes for it).
|
|
246
|
+
let spec = (name: string): string => (isQuiescoPackage(name) ? `${name}@${ctx.version}` : name);
|
|
247
|
+
/** The version each Quiesco package must have after the install. */
|
|
248
|
+
let expected = (_name: string): string => ctx.version;
|
|
235
249
|
if (packagesOpt.value !== undefined) {
|
|
236
250
|
const dir = path.resolve(ctx.cwd, packagesOpt.value);
|
|
237
|
-
const ours = [...runtime, ...dev, ...TRANSITIVE].filter(
|
|
251
|
+
const ours = [...runtime, ...dev, ...TRANSITIVE].filter(isQuiescoPackage);
|
|
238
252
|
const tarballs = findTarballs(dir, ours);
|
|
239
253
|
const missing = ours.filter((n) => !tarballs.has(n));
|
|
240
254
|
if (missing.length > 0) {
|
|
@@ -242,18 +256,31 @@ export async function initCommand(args: readonly string[], ctx: CliContext): Pro
|
|
|
242
256
|
return 1;
|
|
243
257
|
}
|
|
244
258
|
spec = (name) => (tarballs.has(name) ? `file:${tarballs.get(name) as string}` : name);
|
|
259
|
+
expected = (name) => /-(\d[^/]*)\.tgz$/.exec(tarballs.get(name) ?? '')?.[1] ?? ctx.version;
|
|
245
260
|
// Their own dependencies on each other ("@quiesco/protocol": "0.0.0") must resolve to the tarballs too.
|
|
246
261
|
// npm refuses an override for a package that is also a direct dependency (EOVERRIDE) and reuses the
|
|
247
262
|
// directly installed tarballs for those ranges anyway: pin only the indirect ones there. pnpm and
|
|
248
263
|
// yarn resolve every dependency on its own, so they need all of them pinned.
|
|
249
264
|
const direct = new Set([...runtime, ...dev]);
|
|
250
265
|
const pins = Object.fromEntries([...tarballs].filter(([n]) => pm !== 'npm' || !direct.has(n)).map(([n, f]) => [n, `file:${f}`]));
|
|
251
|
-
const
|
|
252
|
-
if (pm === 'pnpm')
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
266
|
+
const pinned = `installing from the tarballs in ${packagesOpt.value} (${Object.keys(pins).length} indirect ${Object.keys(pins).length === 1 ? 'dependency' : 'dependencies'} pinned)`;
|
|
267
|
+
if (pm === 'pnpm') {
|
|
268
|
+
// pnpm 10+ reads overrides from pnpm-workspace.yaml only; the "pnpm" field of package.json is ignored.
|
|
269
|
+
const yamlFile = path.join(ctx.cwd, 'pnpm-workspace.yaml');
|
|
270
|
+
const yaml = ctx.readFile(yamlFile) ?? '';
|
|
271
|
+
if (/^overrides:/m.test(yaml)) {
|
|
272
|
+
ctx.err(`quiesco init: pnpm-workspace.yaml already has overrides; add these and run quiesco init again:\n${pnpmOverrides(pins)}`);
|
|
273
|
+
return 1;
|
|
274
|
+
}
|
|
275
|
+
ctx.writeFile(yamlFile, `${yaml}${yaml === '' || yaml.endsWith('\n') ? '' : '\n'}${pnpmOverrides(pins)}`);
|
|
276
|
+
steps.push({ status: 'updated', what: 'pnpm-workspace.yaml', note: pinned });
|
|
277
|
+
} else {
|
|
278
|
+
const current = readJson<PackageJson>(ctx, pkgFile) as PackageJson;
|
|
279
|
+
if (pm === 'yarn') current.resolutions = { ...current.resolutions, ...pins };
|
|
280
|
+
else current.overrides = { ...current.overrides, ...pins };
|
|
281
|
+
writeJson(ctx, pkgFile, current);
|
|
282
|
+
steps.push({ status: 'updated', what: 'package.json', note: pinned });
|
|
283
|
+
}
|
|
257
284
|
}
|
|
258
285
|
const installs = [addCommand(pm, false, runtime.map(spec)), addCommand(pm, true, dev.map(spec))];
|
|
259
286
|
for (const cmd of installs) {
|
|
@@ -271,6 +298,21 @@ export async function initCommand(args: readonly string[], ctx: CliContext): Pro
|
|
|
271
298
|
}
|
|
272
299
|
steps.push({ status: 'ran', what: 'install', note: line });
|
|
273
300
|
}
|
|
301
|
+
if (!skipInstall.present) {
|
|
302
|
+
const ours = [...runtime, ...dev].filter(isQuiescoPackage);
|
|
303
|
+
const wrong = ours.map((name) => ({ name, want: expected(name), got: installedVersion(ctx, name) })).filter((p) => p.got !== p.want);
|
|
304
|
+
if (wrong.length > 0) {
|
|
305
|
+
ctx.err(`quiesco init: the installed Quiesco packages are not the version that was asked for:`);
|
|
306
|
+
for (const p of wrong) ctx.err(` ${p.name}: ${p.got ?? 'not found in node_modules'} (wanted ${p.want})`);
|
|
307
|
+
ctx.err('All Quiesco packages must have the same version as the CLI that writes the project files. The');
|
|
308
|
+
ctx.err("package manager may have used stale registry metadata from its cache, or held a new release back");
|
|
309
|
+
ctx.err('(pnpm minimumReleaseAge). Install them again with the version given:');
|
|
310
|
+
for (const cmd of [addCommand(pm, false, runtime.map(spec)), addCommand(pm, true, dev.filter(isQuiescoPackage).map(spec))]) ctx.err(` ${cmd.command} ${cmd.args.join(' ')}`);
|
|
311
|
+
ctx.err('then run quiesco init again.');
|
|
312
|
+
return 1;
|
|
313
|
+
}
|
|
314
|
+
steps.push({ status: 'ran', what: 'versions', note: `${ours.length} Quiesco packages at ${[...new Set(ours.map(expected))].join(', ')}` });
|
|
315
|
+
}
|
|
274
316
|
|
|
275
317
|
// 2. Config plugin in app.json.
|
|
276
318
|
const appFile = path.join(ctx.cwd, 'app.json');
|
|
@@ -321,15 +363,29 @@ export async function initCommand(args: readonly string[], ctx: CliContext): Pro
|
|
|
321
363
|
steps.push({ status: 'created', what: 'index.ts', note: `imports @quiesco/agent, then ${original}; package.json "main" set to index.ts` });
|
|
322
364
|
}
|
|
323
365
|
} else {
|
|
324
|
-
const entry =
|
|
325
|
-
const src = entry !==
|
|
326
|
-
if (src === null || entry ===
|
|
366
|
+
const entry = entryFile(ctx, main);
|
|
367
|
+
const src = entry !== null ? (ctx.readFile(entry) ?? '') : null;
|
|
368
|
+
if (src === null || entry === null) {
|
|
327
369
|
steps.push({ status: 'todo', what: 'entry file', note: `cannot find "${main}"; import '@quiesco/agent' on its first line` });
|
|
328
|
-
} else if (src.includes('@quiesco/agent')) {
|
|
329
|
-
steps.push({ status: 'skipped', what: path.basename(entry), note: 'already imports @quiesco/agent' });
|
|
330
370
|
} else {
|
|
331
|
-
|
|
332
|
-
|
|
371
|
+
let next = src;
|
|
372
|
+
const notes: string[] = [];
|
|
373
|
+
if (!src.includes('@quiesco/agent')) {
|
|
374
|
+
next = `import '@quiesco/agent'; // first: Quiesco hooks into React before the app loads\n${src}`;
|
|
375
|
+
notes.push("added import '@quiesco/agent' as the first line");
|
|
376
|
+
}
|
|
377
|
+
// Issue #20: registerRootComponent(App) with a local App (the blank templates): wrap it here.
|
|
378
|
+
const wrapped = wrapRegisteredRoot(ctx, entry, next);
|
|
379
|
+
if (wrapped !== null) {
|
|
380
|
+
next = wrapped;
|
|
381
|
+
notes.push(`wrapped ${registeredRoot(ctx, entry, src)?.name ?? 'the root component'} in <QuiescoRoot>`);
|
|
382
|
+
}
|
|
383
|
+
if (next === src) {
|
|
384
|
+
steps.push({ status: 'skipped', what: path.basename(entry), note: 'already imports @quiesco/agent' });
|
|
385
|
+
} else {
|
|
386
|
+
ctx.writeFile(entry, next);
|
|
387
|
+
steps.push({ status: 'updated', what: path.basename(entry), note: notes.join('; ') });
|
|
388
|
+
}
|
|
333
389
|
}
|
|
334
390
|
}
|
|
335
391
|
|
|
@@ -350,6 +406,27 @@ export async function initCommand(args: readonly string[], ctx: CliContext): Pro
|
|
|
350
406
|
write('features/app.feature', FEATURE, 'a first scenario');
|
|
351
407
|
write('features/step_definitions/app.steps.ts', STEPS, 'its step');
|
|
352
408
|
|
|
409
|
+
// 5b. tsconfig.json (issue #21): step files import each other with .ts (Node's type stripping needs it).
|
|
410
|
+
const tsconfigFile = path.join(ctx.cwd, 'tsconfig.json');
|
|
411
|
+
const tsconfigText = ctx.readFile(tsconfigFile);
|
|
412
|
+
if (tsconfigText !== null) {
|
|
413
|
+
let tsconfig: { compilerOptions?: Record<string, unknown> } | null;
|
|
414
|
+
try {
|
|
415
|
+
tsconfig = JSON.parse(tsconfigText) as { compilerOptions?: Record<string, unknown> };
|
|
416
|
+
} catch {
|
|
417
|
+
tsconfig = null; // comments or trailing commas: leave the file to the user
|
|
418
|
+
}
|
|
419
|
+
if (tsconfig?.compilerOptions?.['allowImportingTsExtensions'] === true) {
|
|
420
|
+
steps.push({ status: 'skipped', what: 'tsconfig.json', note: 'already allows .ts imports' });
|
|
421
|
+
} else if (tsconfig === null || typeof tsconfig !== 'object' || Array.isArray(tsconfig)) {
|
|
422
|
+
steps.push({ status: 'todo', what: 'tsconfig.json', note: 'add "allowImportingTsExtensions": true to compilerOptions (step files import each other with .ts)' });
|
|
423
|
+
} else {
|
|
424
|
+
tsconfig.compilerOptions = { ...tsconfig.compilerOptions, allowImportingTsExtensions: true };
|
|
425
|
+
writeJson(ctx, tsconfigFile, tsconfig);
|
|
426
|
+
steps.push({ status: 'updated', what: 'tsconfig.json', note: 'allowImportingTsExtensions: step files import each other with .ts' });
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
|
|
353
430
|
// 6. Scripts.
|
|
354
431
|
const scripts = { ...(latest.scripts ?? {}) };
|
|
355
432
|
const wanted: Record<string, string> = {
|
|
@@ -372,9 +449,14 @@ export async function initCommand(args: readonly string[], ctx: CliContext): Pro
|
|
|
372
449
|
for (const s of steps) ctx.out(`${icon[s.status]} ${s.what}${s.note !== undefined ? ` — ${s.note}` : ''}`);
|
|
373
450
|
ctx.out('');
|
|
374
451
|
ctx.out('Next:');
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
if (
|
|
452
|
+
const next: string[] = [];
|
|
453
|
+
const finalMain = (readJson<PackageJson>(ctx, pkgFile) as PackageJson).main;
|
|
454
|
+
if (!rootSourceFiles(ctx, finalMain).some((f) => (ctx.readFile(f) ?? '').includes('QuiescoRoot'))) {
|
|
455
|
+
next.push("Wrap the root layout in <QuiescoRoot> (import { QuiescoRoot } from '@quiesco/agent'): the app connects to Quiesco from it, and the soft reset remounts it.");
|
|
456
|
+
}
|
|
457
|
+
next.push('Give the home screen testID="home" (features/step_definitions/app.steps.ts looks for it).');
|
|
458
|
+
if (platforms.includes('web')) next.push('npx playwright install chromium, then npm run e2e:web');
|
|
459
|
+
next.forEach((line, i) => ctx.out(` ${i + 1}. ${line}`));
|
|
378
460
|
if (platforms.some((p) => p !== 'web')) ctx.out(' • iOS / Android: npm run e2e:build:ios (or :android) builds the app into binaryPath, then npm run e2e:ios; quiesco test starts Metro when it is not running. `npx quiesco doctor` checks the setup.');
|
|
379
461
|
ctx.out(' • A SYNC_TIMEOUT that names a decorative animation (the default template spins a glow): give it a testID and add it to sync.ignoreElements.');
|
|
380
462
|
return 0;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `quiesco list [--runner cucumber|jest|vitest] [--json] [runner arguments…]` (P4): the tests the runner
|
|
3
|
+
* would run, without running them or starting a device. Grouped by file; `--json` prints the TestList
|
|
4
|
+
* (the ids the run events use). Runner arguments: `--config <file>`, paths / filters (cucumber also
|
|
5
|
+
* `--profile`).
|
|
6
|
+
*/
|
|
7
|
+
import type { TestList } from '@quiesco/core';
|
|
8
|
+
import { listTests } from '@quiesco/core';
|
|
9
|
+
|
|
10
|
+
import type { CliContext } from '../context.js';
|
|
11
|
+
import { takeFlag, takeOption } from '../context.js';
|
|
12
|
+
|
|
13
|
+
export const LIST_HELP = `Usage: quiesco list [options] [runner arguments…]
|
|
14
|
+
|
|
15
|
+
Lists the tests the runner would run, without running them (no device is started).
|
|
16
|
+
|
|
17
|
+
Options:
|
|
18
|
+
--runner cucumber|jest|vitest Test runner (default: cucumber)
|
|
19
|
+
--json Print the list as JSON (ids as in the run events)
|
|
20
|
+
-h, --help Show this help
|
|
21
|
+
|
|
22
|
+
Runner arguments: --config <file>, paths or filters (cucumber: also --profile <name>).
|
|
23
|
+
|
|
24
|
+
Examples:
|
|
25
|
+
quiesco list
|
|
26
|
+
quiesco list features/login.feature
|
|
27
|
+
quiesco list --runner vitest --config vitest.e2e.config.mts`;
|
|
28
|
+
|
|
29
|
+
export interface ListDeps {
|
|
30
|
+
listTests: typeof listTests;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const RUNNERS = ['cucumber', 'jest', 'vitest'] as const;
|
|
34
|
+
|
|
35
|
+
export function formatList(list: TestList): string[] {
|
|
36
|
+
const lines: string[] = [];
|
|
37
|
+
const byFile = new Map<string, TestList['tests'][number][]>();
|
|
38
|
+
for (const f of list.files) byFile.set(f, []);
|
|
39
|
+
for (const t of list.tests) byFile.set(t.file, [...(byFile.get(t.file) ?? []), t]);
|
|
40
|
+
for (const [file, tests] of byFile) {
|
|
41
|
+
lines.push(file);
|
|
42
|
+
for (const t of tests) lines.push(` ${t.path.join(' › ')}${t.line !== undefined ? ` :${t.line}` : ''}`);
|
|
43
|
+
}
|
|
44
|
+
for (const e of list.errors) lines.push(`✗ ${e.file !== undefined ? `${e.file}: ` : ''}${e.message}`);
|
|
45
|
+
lines.push(`${list.tests.length} test${list.tests.length === 1 ? '' : 's'} in ${list.files.length} file${list.files.length === 1 ? '' : 's'}`);
|
|
46
|
+
return lines;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export async function listCommand(args: readonly string[], ctx: CliContext, deps: ListDeps = { listTests }): Promise<number> {
|
|
50
|
+
if (args.includes('-h') || args.includes('--help')) {
|
|
51
|
+
ctx.out(LIST_HELP);
|
|
52
|
+
return 0;
|
|
53
|
+
}
|
|
54
|
+
const r = takeOption(args, '--runner');
|
|
55
|
+
const json = takeFlag(r.rest, '--json');
|
|
56
|
+
const runner = r.value ?? 'cucumber';
|
|
57
|
+
if (!(RUNNERS as readonly string[]).includes(runner)) {
|
|
58
|
+
ctx.err(`quiesco list: unknown runner "${runner}" (cucumber, jest or vitest).`);
|
|
59
|
+
return 2;
|
|
60
|
+
}
|
|
61
|
+
const list = await deps.listTests({ runner: runner as (typeof RUNNERS)[number], cwd: ctx.cwd, args: json.rest, env: ctx.env });
|
|
62
|
+
if (json.present) ctx.out(JSON.stringify(list, null, 2));
|
|
63
|
+
else for (const line of formatList(list)) ctx.out(line);
|
|
64
|
+
return list.errors.length > 0 && list.tests.length === 0 ? 1 : 0;
|
|
65
|
+
}
|
package/src/commands/test.ts
CHANGED
|
@@ -5,20 +5,23 @@
|
|
|
5
5
|
* each on its own device, with the runner's own flags; those flags can also be passed directly.
|
|
6
6
|
* Everything after a `--` goes to the runner as-is, and the `--` itself is dropped (issue #7): cucumber-js
|
|
7
7
|
* would read every argument after it as a path.
|
|
8
|
+
* On a terminal a progress bar stays on the last line (P3, `--no-progress` turns it off): the runner's
|
|
9
|
+
* Quiesco reporter sends run events over a local socket (QUIESCO_EVENTS).
|
|
8
10
|
*/
|
|
9
11
|
import type { QuiescoConfig } from '@quiesco/core';
|
|
10
12
|
import { loadConfig } from '@quiesco/core';
|
|
11
13
|
|
|
12
14
|
import type { CliContext } from '../context.js';
|
|
13
|
-
import { parsePlatform, takeOption } from '../context.js';
|
|
15
|
+
import { parsePlatform, takeFlag, takeOption } from '../context.js';
|
|
14
16
|
import { ensureDevServer } from '../dev-server.js';
|
|
17
|
+
import { cucumberFormatArgs, progressWanted, runWithProgress } from '../progress/run.js';
|
|
15
18
|
|
|
16
19
|
export interface TestDeps {
|
|
17
20
|
/** The project's quiesco.config (null when there is none: the runner reports that itself). */
|
|
18
21
|
loadConfig: (cwd: string, env: NodeJS.ProcessEnv) => Promise<QuiescoConfig | null>;
|
|
19
22
|
}
|
|
20
23
|
|
|
21
|
-
const defaultTestDeps: TestDeps = {
|
|
24
|
+
export const defaultTestDeps: TestDeps = {
|
|
22
25
|
loadConfig: async (cwd, env) => {
|
|
23
26
|
try {
|
|
24
27
|
return (await loadConfig({ cwd, ...(env['QUIESCO_CONFIG'] !== undefined ? { file: env['QUIESCO_CONFIG'] } : {}), worker: { workerIndex: 0, workerCount: 1 } })).config;
|
|
@@ -28,13 +31,13 @@ const defaultTestDeps: TestDeps = {
|
|
|
28
31
|
},
|
|
29
32
|
};
|
|
30
33
|
|
|
31
|
-
const RUNNERS = {
|
|
34
|
+
export const RUNNERS = {
|
|
32
35
|
cucumber: { command: ['cucumber-js'], workers: (n: number) => (n > 1 ? ['--parallel', String(n)] : []) },
|
|
33
36
|
// `jest` reads jest.config.*.
|
|
34
37
|
jest: { command: ['jest'], workers: (n: number) => ['--maxWorkers', String(n)] },
|
|
35
38
|
vitest: { command: ['vitest', 'run'], workers: (n: number) => (n > 1 ? ['--fileParallelism', '--maxWorkers', String(n)] : ['--no-file-parallelism', '--maxWorkers', '1']) },
|
|
36
39
|
} as const;
|
|
37
|
-
type Runner = keyof typeof RUNNERS;
|
|
40
|
+
export type Runner = keyof typeof RUNNERS;
|
|
38
41
|
|
|
39
42
|
export const TEST_HELP = `Usage: quiesco test [options] [runner arguments…]
|
|
40
43
|
|
|
@@ -48,6 +51,7 @@ Options:
|
|
|
48
51
|
--platform ios|android|web Platform to test (or set QUIESCO_PLATFORM)
|
|
49
52
|
--runner cucumber|jest|vitest Test runner (default: cucumber, i.e. cucumber-js)
|
|
50
53
|
--workers N Run N workers, each on a device of its own
|
|
54
|
+
--no-progress No progress bar (it shows on a terminal, not in CI; or QUIESCO_PROGRESS=0)
|
|
51
55
|
-h, --help Show this help (\`quiesco test -- --help\` shows the runner's)
|
|
52
56
|
|
|
53
57
|
Examples:
|
|
@@ -57,7 +61,7 @@ Examples:
|
|
|
57
61
|
quiesco test --platform web -- --tags @debug
|
|
58
62
|
quiesco test --platform ios --runner vitest --config vitest.e2e.config.mts`;
|
|
59
63
|
|
|
60
|
-
function isRunner(v: string | undefined): v is Runner {
|
|
64
|
+
export function isRunner(v: string | undefined): v is Runner {
|
|
61
65
|
return v !== undefined && Object.hasOwn(RUNNERS, v);
|
|
62
66
|
}
|
|
63
67
|
|
|
@@ -73,7 +77,8 @@ export async function testCommand(args: readonly string[], ctx: CliContext, deps
|
|
|
73
77
|
const p = takeOption(own, '--platform');
|
|
74
78
|
const r = takeOption(p.rest, '--runner');
|
|
75
79
|
const w = takeOption(r.rest, '--workers');
|
|
76
|
-
const
|
|
80
|
+
const np = takeFlag(w.rest, '--no-progress');
|
|
81
|
+
const rest = [...np.rest, ...passThrough];
|
|
77
82
|
const platform = parsePlatform(p.value) ?? parsePlatform(ctx.env['QUIESCO_PLATFORM']);
|
|
78
83
|
if (platform === undefined) {
|
|
79
84
|
ctx.err('quiesco test: choose a platform with --platform ios|android|web (or set QUIESCO_PLATFORM). See quiesco test --help.');
|
|
@@ -105,7 +110,12 @@ export async function testCommand(args: readonly string[], ctx: CliContext, deps
|
|
|
105
110
|
}
|
|
106
111
|
try {
|
|
107
112
|
// npx runs the project's own runner (node_modules/.bin), the one the tests import.
|
|
108
|
-
|
|
113
|
+
const env = { ...ctx.env, QUIESCO_PLATFORM: platform, ...devServer?.env };
|
|
114
|
+
if (progressWanted(ctx, np.present)) {
|
|
115
|
+
const formatArgs = runner === 'cucumber' ? cucumberFormatArgs(ctx) : [];
|
|
116
|
+
return await runWithProgress(ctx, { command: 'npx', args: [...spec.command, ...workerArgs, ...formatArgs, ...rest], env, runner });
|
|
117
|
+
}
|
|
118
|
+
return await ctx.run('npx', [...spec.command, ...workerArgs, ...rest], { cwd: ctx.cwd, env });
|
|
109
119
|
} finally {
|
|
110
120
|
await devServer?.stop();
|
|
111
121
|
}
|