quiesco 0.1.1 → 0.3.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 +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +16 -1
- package/dist/cli.js.map +1 -1
- package/dist/commands/build.d.ts +21 -0
- package/dist/commands/build.d.ts.map +1 -0
- package/dist/commands/build.js +142 -0
- package/dist/commands/build.js.map +1 -0
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +12 -2
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +8 -7
- 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 +28 -1
- package/dist/commands/test.d.ts.map +1 -1
- package/dist/commands/test.js +72 -9
- 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 +43 -0
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +85 -0
- package/dist/context.js.map +1 -1
- package/dist/dev-server.d.ts +17 -0
- package/dist/dev-server.d.ts.map +1 -0
- package/dist/dev-server.js +83 -0
- package/dist/dev-server.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/package.json +3 -3
- package/src/cli.ts +16 -1
- package/src/commands/build.ts +152 -0
- package/src/commands/doctor.ts +12 -2
- package/src/commands/init.ts +9 -7
- package/src/commands/list.ts +65 -0
- package/src/commands/test.ts +83 -10
- package/src/commands/ui.ts +152 -0
- package/src/context.ts +114 -0
- package/src/dev-server.ts +91 -0
- package/src/progress/render.ts +117 -0
- package/src/progress/run.ts +105 -0
- package/src/progress/sticky.ts +95 -0
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `quiesco build ios|android [--force]` (issue #5): the e2e build of the app, written where the config's
|
|
3
|
+
* `binaryPath` says, so `quiesco test` finds it. `expo prebuild` with EXPO_PUBLIC_QUIESCO=1, then
|
|
4
|
+
* - iOS: `xcodebuild` for the simulator, with the derived data path, configuration and scheme read from
|
|
5
|
+
* `apps.ios.binaryPath` (`<derivedData>/Build/Products/<Configuration>-iphonesimulator/<Name>.app`);
|
|
6
|
+
* - Android: `gradlew assemble<Variant>` (debug / release from `apps.android.binaryPath`), the APK copied to
|
|
7
|
+
* `binaryPath` when that is somewhere else.
|
|
8
|
+
* A Debug build is skipped when its native inputs (app config, dependencies and their installed versions)
|
|
9
|
+
* did not change since the last build and the binary is still there; `--force` builds anyway. Release builds
|
|
10
|
+
* embed the JS bundle, so they are always built.
|
|
11
|
+
*/
|
|
12
|
+
import { createHash } from 'node:crypto';
|
|
13
|
+
import fs from 'node:fs';
|
|
14
|
+
import path from 'node:path';
|
|
15
|
+
|
|
16
|
+
import type { QuiescoConfig } from '@quiesco/core';
|
|
17
|
+
import { loadConfig } from '@quiesco/core';
|
|
18
|
+
|
|
19
|
+
import type { CliContext } from '../context.js';
|
|
20
|
+
import { takeOption } from '../context.js';
|
|
21
|
+
|
|
22
|
+
export const BUILD_HELP = `Usage: quiesco build ios|android [--force]
|
|
23
|
+
|
|
24
|
+
Builds the app for e2e tests (EXPO_PUBLIC_QUIESCO=1: expo prebuild, then xcodebuild / gradle) and writes it
|
|
25
|
+
to apps.<platform>.binaryPath in quiesco.config. A Debug build is skipped when the native inputs (app config,
|
|
26
|
+
dependencies) did not change since the last one; --force builds anyway.`;
|
|
27
|
+
|
|
28
|
+
export interface BuildDeps {
|
|
29
|
+
loadConfig: (cwd: string) => Promise<QuiescoConfig>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const defaultBuildDeps: BuildDeps = {
|
|
33
|
+
loadConfig: async (cwd) => (await loadConfig({ cwd, worker: { workerIndex: 0, workerCount: 1 } })).config,
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/** What `apps.ios.binaryPath` says about the xcodebuild that produces it, or null when it is not such a path. */
|
|
37
|
+
export function iosBuildTarget(binaryPath: string): { derivedData: string; configuration: string; name: string } | null {
|
|
38
|
+
const m = /^(.*?)[\\/]Build[\\/]Products[\\/]([^\\/]+)-iphonesimulator[\\/]([^\\/]+)\.app[\\/]?$/.exec(binaryPath);
|
|
39
|
+
if (m === null) return null;
|
|
40
|
+
return { derivedData: m[1] as string, configuration: m[2] as string, name: m[3] as string };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** The gradle variant for `apps.android.binaryPath`: release when the path says so, else debug. */
|
|
44
|
+
export function androidVariant(binaryPath: string): 'debug' | 'release' {
|
|
45
|
+
return /(^|[\\/_-])release([\\/_.-]|$)/i.test(binaryPath) ? 'release' : 'debug';
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const APP_CONFIGS = ['app.json', 'app.config.js', 'app.config.ts', 'app.config.mjs', 'app.config.cjs'];
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* A hash of what goes into the native project: the app config files, and every dependency with its
|
|
52
|
+
* installed version (a native module upgrade changes the build; JS-only ones only cost a rebuild).
|
|
53
|
+
*/
|
|
54
|
+
export function nativeFingerprint(ctx: CliContext, platform: 'ios' | 'android', binaryPath: string): string {
|
|
55
|
+
const h = createHash('sha256');
|
|
56
|
+
h.update(`${platform}\n${binaryPath}\n`);
|
|
57
|
+
for (const f of APP_CONFIGS) {
|
|
58
|
+
const text = ctx.readFile(path.join(ctx.cwd, f));
|
|
59
|
+
if (text !== null) h.update(`${f}\n${text}\n`);
|
|
60
|
+
}
|
|
61
|
+
const pkg = JSON.parse(ctx.readFile(path.join(ctx.cwd, 'package.json')) ?? '{}') as { dependencies?: Record<string, string>; devDependencies?: Record<string, string> };
|
|
62
|
+
const deps = { ...pkg.devDependencies, ...pkg.dependencies };
|
|
63
|
+
for (const name of Object.keys(deps).sort()) {
|
|
64
|
+
const installed = ctx.readFile(path.join(ctx.cwd, 'node_modules', name, 'package.json'));
|
|
65
|
+
const version = installed === null ? '' : ((JSON.parse(installed) as { version?: string }).version ?? '');
|
|
66
|
+
h.update(`${name}@${deps[name] ?? ''}=${version}\n`);
|
|
67
|
+
}
|
|
68
|
+
return h.digest('hex').slice(0, 16);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export async function buildCommand(args: readonly string[], ctx: CliContext, deps: BuildDeps = defaultBuildDeps): Promise<number> {
|
|
72
|
+
if (args.includes('-h') || args.includes('--help')) {
|
|
73
|
+
ctx.out(BUILD_HELP);
|
|
74
|
+
return 0;
|
|
75
|
+
}
|
|
76
|
+
const force = args.includes('--force');
|
|
77
|
+
const rest = takeOption(args.filter((a) => a !== '--force'), '--platform');
|
|
78
|
+
const platform = rest.value ?? rest.rest[0];
|
|
79
|
+
if (platform !== 'ios' && platform !== 'android') {
|
|
80
|
+
ctx.err(`quiesco build: choose ios or android (quiesco build ios). The web needs no build: quiesco test starts Metro, or export it with EXPO_PUBLIC_QUIESCO=1 npx expo export --platform web.`);
|
|
81
|
+
return 2;
|
|
82
|
+
}
|
|
83
|
+
let config: QuiescoConfig;
|
|
84
|
+
try {
|
|
85
|
+
config = await deps.loadConfig(ctx.cwd);
|
|
86
|
+
} catch (e) {
|
|
87
|
+
ctx.err(`quiesco build: ${(e as Error).message}`);
|
|
88
|
+
return 1;
|
|
89
|
+
}
|
|
90
|
+
const binaryPath = config.apps[platform]?.binaryPath;
|
|
91
|
+
if (binaryPath === undefined) {
|
|
92
|
+
ctx.err(`quiesco build: apps.${platform}.binaryPath is not set in quiesco.config: that is where the build goes (npx quiesco init writes it).`);
|
|
93
|
+
return 2;
|
|
94
|
+
}
|
|
95
|
+
const ios = platform === 'ios' ? iosBuildTarget(binaryPath) : null;
|
|
96
|
+
if (platform === 'ios' && ios === null) {
|
|
97
|
+
ctx.err(`quiesco build: apps.ios.binaryPath must look like <dir>/Build/Products/Debug-iphonesimulator/<Name>.app (xcodebuild -derivedDataPath <dir>); it is ${binaryPath}`);
|
|
98
|
+
return 2;
|
|
99
|
+
}
|
|
100
|
+
const release = platform === 'ios' ? !/^debug$/i.test(ios?.configuration ?? '') : androidVariant(binaryPath) === 'release';
|
|
101
|
+
const binary = path.resolve(ctx.cwd, binaryPath);
|
|
102
|
+
const stampFile = path.join(ctx.cwd, '.expo', 'quiesco', `build-${platform}.json`);
|
|
103
|
+
const fingerprint = nativeFingerprint(ctx, platform, binaryPath);
|
|
104
|
+
if (!force && !release && ctx.exists(binary)) {
|
|
105
|
+
const stamp = ctx.readFile(stampFile);
|
|
106
|
+
if (stamp !== null && (JSON.parse(stamp) as { fingerprint?: string }).fingerprint === fingerprint) {
|
|
107
|
+
ctx.out(`quiesco build: ${binaryPath} is up to date (the app config and dependencies did not change; --force builds anyway).`);
|
|
108
|
+
return 0;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const env = { ...ctx.env, EXPO_PUBLIC_QUIESCO: '1' };
|
|
113
|
+
ctx.out(`quiesco build: expo prebuild --platform ${platform} (EXPO_PUBLIC_QUIESCO=1)`);
|
|
114
|
+
let code = await ctx.run('npx', ['expo', 'prebuild', '--platform', platform], { cwd: ctx.cwd, env });
|
|
115
|
+
if (code !== 0) return fail(ctx, 'expo prebuild', code);
|
|
116
|
+
|
|
117
|
+
if (ios !== null) {
|
|
118
|
+
const workspace = path.join('ios', `${ios.name}.xcworkspace`);
|
|
119
|
+
if (!ctx.exists(path.join(ctx.cwd, workspace))) {
|
|
120
|
+
ctx.err(`quiesco build: ${workspace} not found after prebuild. The .app name in apps.ios.binaryPath must be the Xcode scheme (expo prebuild names it after expo.name).`);
|
|
121
|
+
return 1;
|
|
122
|
+
}
|
|
123
|
+
const xcode = ['-workspace', workspace, '-scheme', ios.name, '-configuration', ios.configuration, '-sdk', 'iphonesimulator', '-destination', 'generic/platform=iOS Simulator', '-derivedDataPath', ios.derivedData, '-quiet', 'build'];
|
|
124
|
+
ctx.out(`quiesco build: xcodebuild ${xcode.join(' ')}`);
|
|
125
|
+
code = await ctx.run('xcodebuild', xcode, { cwd: ctx.cwd, env });
|
|
126
|
+
if (code !== 0) return fail(ctx, 'xcodebuild', code);
|
|
127
|
+
} else {
|
|
128
|
+
const variant = androidVariant(binaryPath);
|
|
129
|
+
const task = `assemble${variant === 'release' ? 'Release' : 'Debug'}`;
|
|
130
|
+
const gradlew = ctx.platform === 'win32' ? 'gradlew.bat' : './gradlew';
|
|
131
|
+
ctx.out(`quiesco build: ${gradlew} ${task} (in android/)`);
|
|
132
|
+
code = await ctx.run(gradlew, [task], { cwd: path.join(ctx.cwd, 'android'), env });
|
|
133
|
+
if (code !== 0) return fail(ctx, `gradle ${task}`, code);
|
|
134
|
+
const output = path.join(ctx.cwd, 'android', 'app', 'build', 'outputs', 'apk', variant, `app-${variant}.apk`);
|
|
135
|
+
if (path.resolve(output) !== binary) {
|
|
136
|
+
fs.mkdirSync(path.dirname(binary), { recursive: true });
|
|
137
|
+
fs.copyFileSync(output, binary);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
if (!ctx.exists(binary)) {
|
|
141
|
+
ctx.err(`quiesco build: the build finished but ${binaryPath} is not there; check apps.${platform}.binaryPath.`);
|
|
142
|
+
return 1;
|
|
143
|
+
}
|
|
144
|
+
ctx.writeFile(stampFile, `${JSON.stringify({ fingerprint, binaryPath, builtAt: new Date().toISOString() }, null, 2)}\n`);
|
|
145
|
+
ctx.out(`quiesco build: ${binaryPath} is ready.`);
|
|
146
|
+
return 0;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function fail(ctx: CliContext, step: string, code: number): number {
|
|
150
|
+
ctx.err(`quiesco build: ${step} failed (exit code ${code}).`);
|
|
151
|
+
return code === 0 ? 1 : code;
|
|
152
|
+
}
|
package/src/commands/doctor.ts
CHANGED
|
@@ -170,7 +170,7 @@ async function platformChecks(ctx: CliContext, platform: CliPlatform, config: Qu
|
|
|
170
170
|
out.push(
|
|
171
171
|
ctx.exists(abs(bin))
|
|
172
172
|
? { name: 'iOS: app build', status: 'ok', detail: bin }
|
|
173
|
-
: { name: 'iOS: app build', status: 'warn', detail: `${bin} not found`, fix: '
|
|
173
|
+
: { name: 'iOS: app build', status: 'warn', detail: `${bin} not found`, fix: 'npx quiesco build ios (or an EAS e2e build made with EXPO_PUBLIC_QUIESCO=1).' },
|
|
174
174
|
);
|
|
175
175
|
}
|
|
176
176
|
}
|
|
@@ -196,7 +196,7 @@ async function platformChecks(ctx: CliContext, platform: CliPlatform, config: Qu
|
|
|
196
196
|
out.push(
|
|
197
197
|
ctx.exists(abs(bin))
|
|
198
198
|
? { name: 'Android: app build', status: 'ok', detail: bin }
|
|
199
|
-
: { name: 'Android: app build', status: 'warn', detail: `${bin} not found`, fix: '
|
|
199
|
+
: { name: 'Android: app build', status: 'warn', detail: `${bin} not found`, fix: 'npx quiesco build android (or an EAS e2e build made with EXPO_PUBLIC_QUIESCO=1).' },
|
|
200
200
|
);
|
|
201
201
|
}
|
|
202
202
|
}
|
|
@@ -246,6 +246,16 @@ export async function runChecks(ctx: CliContext, only: CliPlatform | undefined,
|
|
|
246
246
|
? { name: 'Node.js', status: 'ok', detail: `v${ctx.nodeVersion}` }
|
|
247
247
|
: { name: 'Node.js', status: 'fail', detail: `v${ctx.nodeVersion}`, fix: `Quiesco needs Node.js ${MIN_NODE_MAJOR} or later.` },
|
|
248
248
|
);
|
|
249
|
+
// Issue #3: Expo starts Metro without a file watcher when CI is set, so edits never reach the app.
|
|
250
|
+
const ci = ctx.env['CI'];
|
|
251
|
+
if (ctx.interactive && ci !== undefined && ci !== '' && ci !== '0' && ci.toLowerCase() !== 'false') {
|
|
252
|
+
results.push({
|
|
253
|
+
name: 'CI',
|
|
254
|
+
status: 'warn',
|
|
255
|
+
detail: `CI=${ci} is set in this terminal`,
|
|
256
|
+
fix: 'Metro started with CI set does not watch files, so code changes do not reach the app under test. Unset it (unset CI) before EXPO_PUBLIC_QUIESCO=1 npx expo start.',
|
|
257
|
+
});
|
|
258
|
+
}
|
|
249
259
|
results.push(...projectChecks(ctx));
|
|
250
260
|
const sources = ['app/_layout.tsx', 'src/app/_layout.tsx', 'App.tsx', 'App.js', 'src/App.tsx', 'app/_layout.js', 'src/app/_layout.js'].map((f) => path.join(ctx.cwd, f));
|
|
251
261
|
results.push(rootCheck(ctx, sources));
|
package/src/commands/init.ts
CHANGED
|
@@ -121,9 +121,9 @@ function quiescoConfig(app: AppJson, platforms: readonly CliPlatform[]): string
|
|
|
121
121
|
lines.push(
|
|
122
122
|
' ios: {',
|
|
123
123
|
` bundleId: '${app.expo?.ios?.bundleIdentifier ?? 'com.example.app'}',${app.expo?.ios?.bundleIdentifier === undefined ? ' // TODO: expo.ios.bundleIdentifier' : ''}`,
|
|
124
|
-
' // Simulator build made with EXPO_PUBLIC_QUIESCO=1
|
|
124
|
+
' // Simulator build made with EXPO_PUBLIC_QUIESCO=1: `npx quiesco build ios` writes it here (or an EAS e2e build).',
|
|
125
125
|
` binaryPath: 'ios/build/Build/Products/Debug-iphonesimulator/${ios.name}.app',${ios.exact ? '' : ' // TODO: check the .app name'}`,
|
|
126
|
-
" // A dev client loading JS from Metro (
|
|
126
|
+
" // A dev client loading JS from Metro (quiesco test starts it when it is not running). Remove for a bundled build.",
|
|
127
127
|
" devClient: { metroUrl: 'http://localhost:8081' },",
|
|
128
128
|
' },',
|
|
129
129
|
);
|
|
@@ -132,6 +132,7 @@ function quiescoConfig(app: AppJson, platforms: readonly CliPlatform[]): string
|
|
|
132
132
|
lines.push(
|
|
133
133
|
' android: {',
|
|
134
134
|
` package: '${app.expo?.android?.package ?? 'com.example.app'}',${app.expo?.android?.package === undefined ? ' // TODO: expo.android.package' : ''}`,
|
|
135
|
+
" // `npx quiesco build android` writes it here (EXPO_PUBLIC_QUIESCO=1).",
|
|
135
136
|
" binaryPath: 'android/app/build/outputs/apk/debug/app-debug.apk',",
|
|
136
137
|
` devClient: { scheme: '${scheme ?? 'myapp'}', metroUrl: 'http://localhost:8081' },${scheme === undefined ? ' // TODO: expo.scheme' : ''}`,
|
|
137
138
|
' },',
|
|
@@ -162,8 +163,9 @@ function quiescoConfig(app: AppJson, platforms: readonly CliPlatform[]): string
|
|
|
162
163
|
return lines.join('\n');
|
|
163
164
|
}
|
|
164
165
|
|
|
166
|
+
// No `paths`: cucumber-js already defaults to features/**/*.feature, and paths set here are merged with the
|
|
167
|
+
// ones given on the command line, so `quiesco test features/x.feature` would run every feature (issue #8).
|
|
165
168
|
const CUCUMBER_CONFIG = `export default {
|
|
166
|
-
paths: ['features/**/*.feature'],
|
|
167
169
|
import: ['features/support/**/*.ts', 'features/step_definitions/**/*.ts'],
|
|
168
170
|
format: ['progress'],
|
|
169
171
|
};
|
|
@@ -342,7 +344,7 @@ export async function initCommand(args: readonly string[], ctx: CliContext): Pro
|
|
|
342
344
|
steps.push({ status: 'created', what: rel, note });
|
|
343
345
|
};
|
|
344
346
|
write('quiesco.config.mts', quiescoConfig(app, platforms), `apps: ${platforms.join(', ')}`, ['quiesco.config.ts', 'quiesco.config.mts', 'quiesco.config.js', 'quiesco.config.mjs']);
|
|
345
|
-
write('cucumber.mjs', CUCUMBER_CONFIG, 'features/**/*.feature', ['cucumber.mjs', 'cucumber.js', 'cucumber.cjs', 'cucumber.json', 'cucumber.yaml', 'cucumber.yml']);
|
|
347
|
+
write('cucumber.mjs', CUCUMBER_CONFIG, 'step files and format (features/**/*.feature by default)', ['cucumber.mjs', 'cucumber.js', 'cucumber.cjs', 'cucumber.json', 'cucumber.yaml', 'cucumber.yml']);
|
|
346
348
|
write('features/package.json', '{ "type": "module" }\n', 'step files are ES modules');
|
|
347
349
|
write('features/support/quiesco.ts', SUPPORT, 'this.app and the lifecycle hooks');
|
|
348
350
|
write('features/app.feature', FEATURE, 'a first scenario');
|
|
@@ -353,8 +355,8 @@ export async function initCommand(args: readonly string[], ctx: CliContext): Pro
|
|
|
353
355
|
const wanted: Record<string, string> = {
|
|
354
356
|
'e2e:start': 'EXPO_PUBLIC_QUIESCO=1 expo start',
|
|
355
357
|
...(platforms.includes('web') ? { 'e2e:web': 'EXPO_PUBLIC_QUIESCO=1 expo export --platform web && quiesco test --platform web' } : {}),
|
|
356
|
-
...(platforms.includes('android') ? { 'e2e:android': 'quiesco test --platform android' } : {}),
|
|
357
|
-
...(platforms.includes('ios') ? { 'e2e:ios': 'quiesco test --platform ios' } : {}),
|
|
358
|
+
...(platforms.includes('android') ? { 'e2e:build:android': 'quiesco build android', 'e2e:android': 'quiesco test --platform android' } : {}),
|
|
359
|
+
...(platforms.includes('ios') ? { 'e2e:build:ios': 'quiesco build ios', 'e2e:ios': 'quiesco test --platform ios' } : {}),
|
|
358
360
|
};
|
|
359
361
|
const added = Object.keys(wanted).filter((k) => scripts[k] === undefined);
|
|
360
362
|
if (added.length > 0) {
|
|
@@ -373,7 +375,7 @@ export async function initCommand(args: readonly string[], ctx: CliContext): Pro
|
|
|
373
375
|
ctx.out(" 1. Wrap the root layout in <QuiescoRoot> (import { QuiescoRoot } from '@quiesco/agent').");
|
|
374
376
|
ctx.out(' 2. Give the home screen testID="home" (features/step_definitions/app.steps.ts looks for it).');
|
|
375
377
|
if (platforms.includes('web')) ctx.out(' 3. npx playwright install chromium, then npm run e2e:web');
|
|
376
|
-
if (platforms.some((p) => p !== 'web')) ctx.out(' • iOS / Android: build the app
|
|
378
|
+
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.');
|
|
377
379
|
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.');
|
|
378
380
|
return 0;
|
|
379
381
|
}
|
|
@@ -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
|
@@ -3,30 +3,85 @@
|
|
|
3
3
|
* (requirements.md §6.12, Phase 6.10): sets QUIESCO_PLATFORM and runs the project's test runner with the
|
|
4
4
|
* remaining arguments unchanged. Default runner: cucumber-js. `--workers N` (Phase 6.12) runs N workers,
|
|
5
5
|
* each on its own device, with the runner's own flags; those flags can also be passed directly.
|
|
6
|
+
* Everything after a `--` goes to the runner as-is, and the `--` itself is dropped (issue #7): cucumber-js
|
|
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).
|
|
6
10
|
*/
|
|
11
|
+
import type { QuiescoConfig } from '@quiesco/core';
|
|
12
|
+
import { loadConfig } from '@quiesco/core';
|
|
13
|
+
|
|
7
14
|
import type { CliContext } from '../context.js';
|
|
8
|
-
import { parsePlatform, takeOption } from '../context.js';
|
|
15
|
+
import { parsePlatform, takeFlag, takeOption } from '../context.js';
|
|
16
|
+
import { ensureDevServer } from '../dev-server.js';
|
|
17
|
+
import { cucumberFormatArgs, progressWanted, runWithProgress } from '../progress/run.js';
|
|
18
|
+
|
|
19
|
+
export interface TestDeps {
|
|
20
|
+
/** The project's quiesco.config (null when there is none: the runner reports that itself). */
|
|
21
|
+
loadConfig: (cwd: string, env: NodeJS.ProcessEnv) => Promise<QuiescoConfig | null>;
|
|
22
|
+
}
|
|
9
23
|
|
|
10
|
-
const
|
|
24
|
+
export const defaultTestDeps: TestDeps = {
|
|
25
|
+
loadConfig: async (cwd, env) => {
|
|
26
|
+
try {
|
|
27
|
+
return (await loadConfig({ cwd, ...(env['QUIESCO_CONFIG'] !== undefined ? { file: env['QUIESCO_CONFIG'] } : {}), worker: { workerIndex: 0, workerCount: 1 } })).config;
|
|
28
|
+
} catch {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const RUNNERS = {
|
|
11
35
|
cucumber: { command: ['cucumber-js'], workers: (n: number) => (n > 1 ? ['--parallel', String(n)] : []) },
|
|
12
36
|
// `jest` reads jest.config.*.
|
|
13
37
|
jest: { command: ['jest'], workers: (n: number) => ['--maxWorkers', String(n)] },
|
|
14
38
|
vitest: { command: ['vitest', 'run'], workers: (n: number) => (n > 1 ? ['--fileParallelism', '--maxWorkers', String(n)] : ['--no-file-parallelism', '--maxWorkers', '1']) },
|
|
15
39
|
} as const;
|
|
16
|
-
type Runner = keyof typeof RUNNERS;
|
|
40
|
+
export type Runner = keyof typeof RUNNERS;
|
|
41
|
+
|
|
42
|
+
export const TEST_HELP = `Usage: quiesco test [options] [runner arguments…]
|
|
43
|
+
|
|
44
|
+
Sets QUIESCO_PLATFORM and runs the project's test runner. Arguments Quiesco does not know go to the runner
|
|
45
|
+
unchanged; everything after \`--\` goes to the runner as well (the \`--\` itself is dropped).
|
|
17
46
|
|
|
18
|
-
|
|
47
|
+
When nothing answers at devClient.metroUrl (native) or apps.web.url (web) on this machine, it starts
|
|
48
|
+
\`npx expo start\` first and stops it afterwards (config: devServer; log: artifacts/metro.log).
|
|
49
|
+
|
|
50
|
+
Options:
|
|
51
|
+
--platform ios|android|web Platform to test (or set QUIESCO_PLATFORM)
|
|
52
|
+
--runner cucumber|jest|vitest Test runner (default: cucumber, i.e. cucumber-js)
|
|
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)
|
|
55
|
+
-h, --help Show this help (\`quiesco test -- --help\` shows the runner's)
|
|
56
|
+
|
|
57
|
+
Examples:
|
|
58
|
+
quiesco test --platform ios --tags @smoke
|
|
59
|
+
quiesco test --platform web features/login.feature
|
|
60
|
+
quiesco test --platform android --name "Add a todo"
|
|
61
|
+
quiesco test --platform web -- --tags @debug
|
|
62
|
+
quiesco test --platform ios --runner vitest --config vitest.e2e.config.mts`;
|
|
63
|
+
|
|
64
|
+
export function isRunner(v: string | undefined): v is Runner {
|
|
19
65
|
return v !== undefined && Object.hasOwn(RUNNERS, v);
|
|
20
66
|
}
|
|
21
67
|
|
|
22
|
-
export async function testCommand(args: readonly string[], ctx: CliContext): Promise<number> {
|
|
23
|
-
|
|
68
|
+
export async function testCommand(args: readonly string[], ctx: CliContext, deps: TestDeps = defaultTestDeps): Promise<number> {
|
|
69
|
+
// Quiesco reads its own options only before a `--`; what follows goes to the runner untouched.
|
|
70
|
+
const dashDash = args.indexOf('--');
|
|
71
|
+
const own = dashDash === -1 ? args : args.slice(0, dashDash);
|
|
72
|
+
const passThrough = dashDash === -1 ? [] : args.slice(dashDash + 1);
|
|
73
|
+
if (own.includes('-h') || own.includes('--help')) {
|
|
74
|
+
ctx.out(TEST_HELP);
|
|
75
|
+
return 0;
|
|
76
|
+
}
|
|
77
|
+
const p = takeOption(own, '--platform');
|
|
24
78
|
const r = takeOption(p.rest, '--runner');
|
|
25
79
|
const w = takeOption(r.rest, '--workers');
|
|
26
|
-
const
|
|
80
|
+
const np = takeFlag(w.rest, '--no-progress');
|
|
81
|
+
const rest = [...np.rest, ...passThrough];
|
|
27
82
|
const platform = parsePlatform(p.value) ?? parsePlatform(ctx.env['QUIESCO_PLATFORM']);
|
|
28
83
|
if (platform === undefined) {
|
|
29
|
-
ctx.err('quiesco test: choose a platform with --platform ios|android|web (or set QUIESCO_PLATFORM).');
|
|
84
|
+
ctx.err('quiesco test: choose a platform with --platform ios|android|web (or set QUIESCO_PLATFORM). See quiesco test --help.');
|
|
30
85
|
return 2;
|
|
31
86
|
}
|
|
32
87
|
const runner = r.value ?? 'cucumber';
|
|
@@ -44,6 +99,24 @@ export async function testCommand(args: readonly string[], ctx: CliContext): Pro
|
|
|
44
99
|
}
|
|
45
100
|
workerArgs = [...spec.workers(n)];
|
|
46
101
|
}
|
|
47
|
-
//
|
|
48
|
-
|
|
102
|
+
// The Metro dev server the app loads its JS from, started when nothing answers there (issue #5).
|
|
103
|
+
const config = await deps.loadConfig(ctx.cwd, ctx.env);
|
|
104
|
+
let devServer;
|
|
105
|
+
try {
|
|
106
|
+
devServer = config === null ? null : await ensureDevServer(ctx, config, platform);
|
|
107
|
+
} catch (e) {
|
|
108
|
+
ctx.err(`quiesco test: ${(e as Error).message}`);
|
|
109
|
+
return 1;
|
|
110
|
+
}
|
|
111
|
+
try {
|
|
112
|
+
// npx runs the project's own runner (node_modules/.bin), the one the tests import.
|
|
113
|
+
const env = { ...ctx.env, QUIESCO_PLATFORM: platform };
|
|
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 });
|
|
119
|
+
} finally {
|
|
120
|
+
await devServer?.stop();
|
|
121
|
+
}
|
|
49
122
|
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `quiesco ui [--platform …] [--runner …] [--workers N] [--port N] [--no-open] [runner arguments…]` (P5):
|
|
3
|
+
* the test UI. Serves @quiesco/ui (installed in the project, loaded only here so the CLI stays small)
|
|
4
|
+
* on 127.0.0.1, keeps the Metro dev server up while it runs, and runs what the browser asks for the way
|
|
5
|
+
* `quiesco test` would (same runner, runner arguments, workers and cucumber formatter) with the chosen
|
|
6
|
+
* tests added. Ctrl-C stops it.
|
|
7
|
+
*/
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
import { pathToFileURL } from 'node:url';
|
|
10
|
+
|
|
11
|
+
import type { QuiescoConfig, RunnerName, TestList } from '@quiesco/core';
|
|
12
|
+
import { listTests } from '@quiesco/core';
|
|
13
|
+
|
|
14
|
+
import type { CliContext } from '../context.js';
|
|
15
|
+
import { parsePlatform, takeFlag, takeOption } from '../context.js';
|
|
16
|
+
import { ensureDevServer } from '../dev-server.js';
|
|
17
|
+
import { cucumberFormatArgs } from '../progress/run.js';
|
|
18
|
+
import { RUNNERS, defaultTestDeps, isRunner } from './test.js';
|
|
19
|
+
|
|
20
|
+
export const UI_HELP = `Usage: quiesco ui [options] [runner arguments…]
|
|
21
|
+
|
|
22
|
+
Opens the test UI in the browser: the test tree, run all / a file / a test with a click, live progress,
|
|
23
|
+
failures with Quiesco's evidence. Needs @quiesco/ui in the project (npm i -D @quiesco/ui).
|
|
24
|
+
|
|
25
|
+
Options:
|
|
26
|
+
--platform ios|android|web Platform to test (or set QUIESCO_PLATFORM)
|
|
27
|
+
--runner cucumber|jest|vitest Test runner (default: cucumber)
|
|
28
|
+
--workers N Run N workers, each on a device of its own
|
|
29
|
+
--port N Port of the UI (default: a free one)
|
|
30
|
+
--no-open Do not open the browser
|
|
31
|
+
-h, --help Show this help
|
|
32
|
+
|
|
33
|
+
Runner arguments (e.g. --config vitest.e2e.config.mts) are used for every run and for listing the tests.
|
|
34
|
+
|
|
35
|
+
Examples:
|
|
36
|
+
quiesco ui --platform web
|
|
37
|
+
quiesco ui --platform ios --runner vitest --config vitest.e2e.config.mts`;
|
|
38
|
+
|
|
39
|
+
/** The parts of @quiesco/ui the CLI uses (structural: the CLI does not depend on it). */
|
|
40
|
+
interface RunHandleLike {
|
|
41
|
+
readonly exited: Promise<number>;
|
|
42
|
+
stop(graceMs?: number): void;
|
|
43
|
+
}
|
|
44
|
+
export interface UiModule {
|
|
45
|
+
startUiServer(options: {
|
|
46
|
+
cwd: string;
|
|
47
|
+
runner: RunnerName;
|
|
48
|
+
platform: string;
|
|
49
|
+
startRun(args: string[], env: Record<string, string>, onOutput: (stream: 'stdout' | 'stderr', text: string) => void): RunHandleLike;
|
|
50
|
+
listTests(): Promise<TestList>;
|
|
51
|
+
artifactsDir: string;
|
|
52
|
+
staticDir: string | null;
|
|
53
|
+
port?: number;
|
|
54
|
+
}): Promise<{ url: string; close(): Promise<void> }>;
|
|
55
|
+
spawnRun(command: string, args: readonly string[], options: { cwd: string; env: NodeJS.ProcessEnv; onOutput: (stream: 'stdout' | 'stderr', text: string) => void }): RunHandleLike;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface UiDeps {
|
|
59
|
+
loadUi(ctx: CliContext): Promise<{ module: UiModule; staticDir: string | null } | null>;
|
|
60
|
+
loadConfig(cwd: string, env: NodeJS.ProcessEnv): Promise<QuiescoConfig | null>;
|
|
61
|
+
listTests: typeof listTests;
|
|
62
|
+
/** Resolves when the user stops the UI (Ctrl-C). */
|
|
63
|
+
untilInterrupted(ctx: CliContext): Promise<void>;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export const defaultUiDeps: UiDeps = {
|
|
67
|
+
loadUi: async (ctx) => {
|
|
68
|
+
const entry = ctx.resolveFrom(ctx.cwd, '@quiesco/ui');
|
|
69
|
+
if (entry === null) return null;
|
|
70
|
+
const module = (await import(pathToFileURL(entry).href)) as UiModule;
|
|
71
|
+
const staticDir = path.join(path.dirname(entry), 'web');
|
|
72
|
+
return { module, staticDir: ctx.exists(path.join(staticDir, 'index.html')) ? staticDir : null };
|
|
73
|
+
},
|
|
74
|
+
loadConfig: defaultTestDeps.loadConfig,
|
|
75
|
+
listTests,
|
|
76
|
+
untilInterrupted: (ctx) => new Promise<void>((resolve) => void ctx.onInterrupt(async () => resolve())),
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
function openBrowser(ctx: CliContext, url: string): void {
|
|
80
|
+
const [command, args] = ctx.platform === 'darwin' ? ['open', [url]] : ctx.platform === 'win32' ? ['cmd', ['/c', 'start', '', url]] : ['xdg-open', [url]];
|
|
81
|
+
void ctx.exec(command as string, args as string[]).catch(() => undefined);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export async function uiCommand(args: readonly string[], ctx: CliContext, deps: UiDeps = defaultUiDeps): Promise<number> {
|
|
85
|
+
if (args.includes('-h') || args.includes('--help')) {
|
|
86
|
+
ctx.out(UI_HELP);
|
|
87
|
+
return 0;
|
|
88
|
+
}
|
|
89
|
+
const p = takeOption(args, '--platform');
|
|
90
|
+
const r = takeOption(p.rest, '--runner');
|
|
91
|
+
const w = takeOption(r.rest, '--workers');
|
|
92
|
+
const portOpt = takeOption(w.rest, '--port');
|
|
93
|
+
const noOpen = takeFlag(portOpt.rest, '--no-open');
|
|
94
|
+
const rest = noOpen.rest.filter((a) => a !== '--');
|
|
95
|
+
const platform = parsePlatform(p.value) ?? parsePlatform(ctx.env['QUIESCO_PLATFORM']);
|
|
96
|
+
if (platform === undefined) {
|
|
97
|
+
ctx.err('quiesco ui: choose a platform with --platform ios|android|web (or set QUIESCO_PLATFORM). See quiesco ui --help.');
|
|
98
|
+
return 2;
|
|
99
|
+
}
|
|
100
|
+
const runner = r.value ?? 'cucumber';
|
|
101
|
+
if (!isRunner(runner)) {
|
|
102
|
+
ctx.err(`quiesco ui: unknown runner "${runner}" (cucumber, jest or vitest).`);
|
|
103
|
+
return 2;
|
|
104
|
+
}
|
|
105
|
+
const workers = w.value !== undefined ? Number(w.value) : undefined;
|
|
106
|
+
if (workers !== undefined && (!Number.isInteger(workers) || workers < 1)) {
|
|
107
|
+
ctx.err(`quiesco ui: --workers takes a whole number ≥ 1 (got "${w.value}").`);
|
|
108
|
+
return 2;
|
|
109
|
+
}
|
|
110
|
+
const port = portOpt.value !== undefined ? Number(portOpt.value) : undefined;
|
|
111
|
+
if (port !== undefined && (!Number.isInteger(port) || port < 0 || port > 65535)) {
|
|
112
|
+
ctx.err(`quiesco ui: --port takes a port number (got "${portOpt.value}").`);
|
|
113
|
+
return 2;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const ui = await deps.loadUi(ctx);
|
|
117
|
+
if (ui === null) {
|
|
118
|
+
ctx.err('quiesco ui: @quiesco/ui is not installed in this project. Install it: npm i -D @quiesco/ui');
|
|
119
|
+
return 1;
|
|
120
|
+
}
|
|
121
|
+
const config = await deps.loadConfig(ctx.cwd, ctx.env);
|
|
122
|
+
let devServer;
|
|
123
|
+
try {
|
|
124
|
+
devServer = config === null ? null : await ensureDevServer(ctx, config, platform);
|
|
125
|
+
} catch (e) {
|
|
126
|
+
ctx.err(`quiesco ui: ${(e as Error).message}`);
|
|
127
|
+
return 1;
|
|
128
|
+
}
|
|
129
|
+
const spec = RUNNERS[runner];
|
|
130
|
+
const base = [...spec.command, ...(workers !== undefined ? spec.workers(workers) : []), ...(runner === 'cucumber' ? cucumberFormatArgs(ctx) : []), ...rest];
|
|
131
|
+
try {
|
|
132
|
+
const server = await ui.module.startUiServer({
|
|
133
|
+
cwd: ctx.cwd,
|
|
134
|
+
runner,
|
|
135
|
+
platform,
|
|
136
|
+
artifactsDir: path.resolve(ctx.cwd, config?.artifacts?.dir ?? 'artifacts'),
|
|
137
|
+
staticDir: ui.staticDir,
|
|
138
|
+
...(port !== undefined ? { port } : {}),
|
|
139
|
+
listTests: () => deps.listTests({ runner, cwd: ctx.cwd, args: rest, env: ctx.env }),
|
|
140
|
+
// npx runs the project's own runner; the chosen tests go last (after the user's arguments).
|
|
141
|
+
startRun: (targetArgs, env, onOutput) => ui.module.spawnRun('npx', [...base, ...targetArgs], { cwd: ctx.cwd, env: { ...ctx.env, QUIESCO_PLATFORM: platform, ...env }, onOutput }),
|
|
142
|
+
});
|
|
143
|
+
ctx.out(`quiesco ui: ${server.url}`);
|
|
144
|
+
ctx.out('quiesco ui: Ctrl-C stops it.');
|
|
145
|
+
if (!noOpen.present && ctx.interactive) openBrowser(ctx, server.url);
|
|
146
|
+
await deps.untilInterrupted(ctx);
|
|
147
|
+
await server.close();
|
|
148
|
+
return 0;
|
|
149
|
+
} finally {
|
|
150
|
+
await devServer?.stop();
|
|
151
|
+
}
|
|
152
|
+
}
|