quiesco 0.6.0 → 0.7.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 +2 -2
- package/dist/cli.d.ts +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +3 -2
- package/dist/cli.js.map +1 -1
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +5 -2
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +85 -16
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/list.d.ts +1 -1
- package/dist/commands/list.d.ts.map +1 -1
- package/dist/commands/list.js +4 -2
- package/dist/commands/list.js.map +1 -1
- package/dist/commands/test.d.ts +2 -2
- package/dist/commands/test.d.ts.map +1 -1
- package/dist/commands/test.js +4 -2
- package/dist/commands/test.js.map +1 -1
- package/dist/commands/ui.d.ts +1 -1
- package/dist/commands/ui.d.ts.map +1 -1
- package/dist/commands/ui.js +4 -2
- package/dist/commands/ui.js.map +1 -1
- package/dist/context.d.ts +8 -0
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +22 -0
- package/dist/context.js.map +1 -1
- package/dist/runner.d.ts +15 -0
- package/dist/runner.d.ts.map +1 -0
- package/dist/runner.js +41 -0
- package/dist/runner.js.map +1 -0
- package/dist/setup-steps.d.ts +8 -3
- package/dist/setup-steps.d.ts.map +1 -1
- package/dist/setup-steps.js +18 -8
- package/dist/setup-steps.js.map +1 -1
- package/package.json +2 -2
- package/src/cli.ts +3 -2
- package/src/commands/doctor.ts +5 -2
- package/src/commands/init.ts +95 -15
- package/src/commands/list.ts +4 -2
- package/src/commands/test.ts +5 -3
- package/src/commands/ui.ts +4 -2
- package/src/context.ts +23 -0
- package/src/runner.ts +47 -0
- package/src/setup-steps.ts +20 -8
package/src/commands/init.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `quiesco init [--platforms ios,android,web] [--packages <dir>] [--skip-install]`
|
|
3
|
-
* §6.12): set Quiesco up in an Expo project.
|
|
2
|
+
* `quiesco init [--platforms ios,android,web] [--runner vitest|jest|cucumber] [--packages <dir>] [--skip-install]`
|
|
3
|
+
* (requirements.md §6.12): set Quiesco up in an Expo project. Without `--runner` it asks which test runner
|
|
4
|
+
* to use when a person is at the terminal, and takes Vitest otherwise. Every step says what it did; existing files are never
|
|
4
5
|
* overwritten — when one needs a change Quiesco cannot make safely, the step prints what to add.
|
|
5
6
|
*
|
|
6
7
|
* `--packages <dir>`: install Quiesco from the tarballs in <dir> (`pnpm pack` output) instead of the
|
|
@@ -13,7 +14,9 @@ import { PLATFORMS, takeFlag, takeOption } from '../context.js';
|
|
|
13
14
|
import { MIN_EXPO_SDK, UPGRADE_SDK_FIX, expoSdk } from '../expo-sdk.js';
|
|
14
15
|
import { entryFile, registeredRoot, rootSourceFiles, wrapRegisteredRoot } from '../project.js';
|
|
15
16
|
import type { AppJson, InitStep, PackageJson, StepLog } from '../setup-steps.js';
|
|
16
|
-
import {
|
|
17
|
+
import type { RunnerName } from '../runner.js';
|
|
18
|
+
import { RUNNER_LABELS, RUNNER_NAMES, RUNNER_PACKAGES, isRunnerName } from '../runner.js';
|
|
19
|
+
import { DEV, RUNTIME, WEB_DEV, detectPackageManager, ensureAppIds, ensureScripts, ensureTsconfig, execBin, firstScheme, installPackages, printSteps, readJson, runScript, writeJson } from '../setup-steps.js';
|
|
17
20
|
import { upgradeCommand } from './upgrade.js';
|
|
18
21
|
|
|
19
22
|
export { detectPackageManager, findTarballs } from '../setup-steps.js';
|
|
@@ -125,6 +128,49 @@ Then('the home screen is visible', async function (this: QuiescoWorld) {
|
|
|
125
128
|
});
|
|
126
129
|
`;
|
|
127
130
|
|
|
131
|
+
const VITEST_CONFIG = `// Quiesco's e2e tests. quiesco(): one app session per worker, kept across files, run one file at a time
|
|
132
|
+
// (quiesco({ workers: N }) runs them on N devices); the platform tags (@ios, @android, @web …).
|
|
133
|
+
// quiescoPlugin(): the run's progress for \`quiesco test\` and \`quiesco ui\`.
|
|
134
|
+
import { quiesco, quiescoPlugin } from '@quiesco/vitest/config';
|
|
135
|
+
import { defineConfig } from 'vitest/config';
|
|
136
|
+
|
|
137
|
+
export default defineConfig({
|
|
138
|
+
plugins: [quiescoPlugin()],
|
|
139
|
+
test: { ...quiesco(), include: ['e2e/**/*.test.ts'] },
|
|
140
|
+
});
|
|
141
|
+
`;
|
|
142
|
+
|
|
143
|
+
const VITEST_TEST = `import { test } from '@quiesco/vitest';
|
|
144
|
+
|
|
145
|
+
// Tests talk to the app through the \`app\` fixture and never wait or sleep: every call waits for the app
|
|
146
|
+
// to become idle first. Give the element testID="home" (or change the id here).
|
|
147
|
+
test('the home screen is shown', async ({ app }) => {
|
|
148
|
+
await app.expectVisible({ id: 'home' });
|
|
149
|
+
});
|
|
150
|
+
`;
|
|
151
|
+
|
|
152
|
+
const JEST_CONFIG = `// Quiesco's e2e tests. The preset: the Quiesco test environment (the global \`quiesco\`) and the reporter for
|
|
153
|
+
// \`quiesco test\` / \`quiesco ui\`. maxWorkers: N runs the files on N devices; testTimeout covers Quiesco's waits.
|
|
154
|
+
module.exports = {
|
|
155
|
+
preset: '@quiesco/jest',
|
|
156
|
+
rootDir: __dirname,
|
|
157
|
+
testMatch: ['<rootDir>/e2e/**/*.test.js'],
|
|
158
|
+
transform: {},
|
|
159
|
+
maxWorkers: 1,
|
|
160
|
+
testTimeout: 120_000,
|
|
161
|
+
};
|
|
162
|
+
`;
|
|
163
|
+
|
|
164
|
+
const JEST_TEST = `// Tests talk to the app through quiesco.app and never wait or sleep: every call waits for the app to
|
|
165
|
+
// become idle first. Give the element testID="home" (or change the id here).
|
|
166
|
+
test('the home screen is shown', async () => {
|
|
167
|
+
await quiesco.app.expectVisible({ id: 'home' });
|
|
168
|
+
});
|
|
169
|
+
`;
|
|
170
|
+
|
|
171
|
+
const VITEST_CONFIGS = ['ts', 'mts', 'cts', 'js', 'mjs', 'cjs'].map((e) => `vitest.config.${e}`);
|
|
172
|
+
const JEST_CONFIGS = ['js', 'ts', 'mjs', 'cjs', 'json'].map((e) => `jest.config.${e}`);
|
|
173
|
+
|
|
128
174
|
export async function initCommand(args: readonly string[], ctx: CliContext): Promise<number> {
|
|
129
175
|
if (args.includes('--upgrade')) return upgradeCommand(args.filter((a) => a !== '--upgrade'), ctx);
|
|
130
176
|
let rest = [...args];
|
|
@@ -134,10 +180,16 @@ export async function initCommand(args: readonly string[], ctx: CliContext): Pro
|
|
|
134
180
|
rest = packagesOpt.rest;
|
|
135
181
|
const skipInstall = takeFlag(rest, '--skip-install');
|
|
136
182
|
rest = skipInstall.rest;
|
|
183
|
+
const runnerOpt = takeOption(rest, '--runner');
|
|
184
|
+
rest = runnerOpt.rest;
|
|
137
185
|
if (rest.length > 0) {
|
|
138
186
|
ctx.err(`quiesco init: unknown arguments ${rest.join(' ')}`);
|
|
139
187
|
return 2;
|
|
140
188
|
}
|
|
189
|
+
if (runnerOpt.value !== undefined && !isRunnerName(runnerOpt.value)) {
|
|
190
|
+
ctx.err(`quiesco init: unknown runner "${runnerOpt.value}" (${RUNNER_NAMES.join(', ')}).`);
|
|
191
|
+
return 2;
|
|
192
|
+
}
|
|
141
193
|
|
|
142
194
|
const pkgFile = path.join(ctx.cwd, 'package.json');
|
|
143
195
|
const pkg = readJson<PackageJson>(ctx, pkgFile);
|
|
@@ -156,13 +208,24 @@ export async function initCommand(args: readonly string[], ctx: CliContext): Pro
|
|
|
156
208
|
})
|
|
157
209
|
: ['ios', 'android', ...(hasWebDeps ? (['web'] as const) : [])];
|
|
158
210
|
|
|
211
|
+
const runner: RunnerName =
|
|
212
|
+
runnerOpt.value !== undefined
|
|
213
|
+
? (runnerOpt.value as RunnerName)
|
|
214
|
+
: ctx.interactive
|
|
215
|
+
? ((await ctx.choose(
|
|
216
|
+
'Which test runner should drive Quiesco?',
|
|
217
|
+
RUNNER_NAMES.map((r) => ({ value: r, label: RUNNER_LABELS[r] })),
|
|
218
|
+
'vitest',
|
|
219
|
+
)) as RunnerName)
|
|
220
|
+
: 'vitest';
|
|
221
|
+
|
|
159
222
|
const steps: InitStep[] = [];
|
|
160
223
|
const log: StepLog = { ctx, steps, dryRun: false };
|
|
161
224
|
const pm = detectPackageManager(ctx);
|
|
162
225
|
|
|
163
226
|
// 1. Dependencies.
|
|
164
227
|
const runtime = [...RUNTIME];
|
|
165
|
-
const dev = [...DEV, ...(platforms.includes('web') ? WEB_DEV : [])];
|
|
228
|
+
const dev = [...DEV, ...RUNNER_PACKAGES[runner], ...(platforms.includes('web') ? WEB_DEV : [])];
|
|
166
229
|
const installed = await installPackages(log, {
|
|
167
230
|
pm,
|
|
168
231
|
runtime,
|
|
@@ -250,7 +313,7 @@ export async function initCommand(args: readonly string[], ctx: CliContext): Pro
|
|
|
250
313
|
}
|
|
251
314
|
}
|
|
252
315
|
|
|
253
|
-
// 5. quiesco.config.mts (.mts: an ES module whatever package.json says),
|
|
316
|
+
// 5. quiesco.config.mts (.mts: an ES module whatever package.json says), the runner's config, a first test.
|
|
254
317
|
const write = (rel: string, content: string, note: string, alternatives: readonly string[] = [rel]): void => {
|
|
255
318
|
const existing = alternatives.find((f) => ctx.exists(path.join(ctx.cwd, f)));
|
|
256
319
|
if (existing !== undefined) {
|
|
@@ -261,17 +324,32 @@ export async function initCommand(args: readonly string[], ctx: CliContext): Pro
|
|
|
261
324
|
steps.push({ status: 'created', what: rel, note });
|
|
262
325
|
};
|
|
263
326
|
write('quiesco.config.mts', quiescoConfig(appWithIds, platforms), `apps: ${platforms.join(', ')}`, ['quiesco.config.ts', 'quiesco.config.mts', 'quiesco.config.js', 'quiesco.config.mjs']);
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
327
|
+
/** A config of the runner's own name may be the unit tests': then Quiesco's goes next to it and the scripts name it. */
|
|
328
|
+
let testArgs = '';
|
|
329
|
+
let firstTest: string;
|
|
330
|
+
if (runner === 'cucumber') {
|
|
331
|
+
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']);
|
|
332
|
+
write('features/package.json', '{ "type": "module" }\n', 'step files are ES modules');
|
|
333
|
+
write('features/support/quiesco.ts', SUPPORT, 'this.app and the lifecycle hooks');
|
|
334
|
+
write('features/app.feature', FEATURE, 'a first scenario');
|
|
335
|
+
write('features/step_definitions/app.steps.ts', STEPS, 'its step');
|
|
336
|
+
firstTest = 'features/step_definitions/app.steps.ts';
|
|
337
|
+
} else {
|
|
338
|
+
const [names, standard, e2eName, content] =
|
|
339
|
+
runner === 'vitest' ? [VITEST_CONFIGS, 'vitest.config.mts', 'vitest.e2e.config.mts', VITEST_CONFIG] : [JEST_CONFIGS, 'jest.config.cjs', 'jest.e2e.config.cjs', JEST_CONFIG];
|
|
340
|
+
const own = names.find((f) => ctx.exists(path.join(ctx.cwd, f))) ?? (runner === 'jest' && latest.jest !== undefined ? 'package.json "jest"' : undefined);
|
|
341
|
+
const configFile = own === undefined ? standard : e2eName;
|
|
342
|
+
write(configFile, content, own === undefined ? 'Quiesco for the e2e tests in e2e/' : `next to ${own} (your unit tests'); the e2e scripts pass --config ${e2eName}`);
|
|
343
|
+
if (own !== undefined) testArgs = `--config ${configFile}`;
|
|
344
|
+
firstTest = runner === 'vitest' ? 'e2e/app.test.ts' : 'e2e/app.test.js';
|
|
345
|
+
write(firstTest, runner === 'vitest' ? VITEST_TEST : JEST_TEST, 'a first test');
|
|
346
|
+
}
|
|
269
347
|
|
|
270
348
|
// 5b. tsconfig.json (issue #21): step files import each other with .ts (Node's type stripping needs it).
|
|
271
|
-
ensureTsconfig(log);
|
|
349
|
+
if (runner === 'cucumber') ensureTsconfig(log);
|
|
272
350
|
|
|
273
351
|
// 6. Scripts.
|
|
274
|
-
ensureScripts(log, platforms);
|
|
352
|
+
ensureScripts(log, platforms, testArgs);
|
|
275
353
|
|
|
276
354
|
printSteps(ctx, steps);
|
|
277
355
|
ctx.out('');
|
|
@@ -281,10 +359,12 @@ export async function initCommand(args: readonly string[], ctx: CliContext): Pro
|
|
|
281
359
|
if (!rootSourceFiles(ctx, finalMain).some((f) => (ctx.readFile(f) ?? '').includes('QuiescoRoot'))) {
|
|
282
360
|
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.");
|
|
283
361
|
}
|
|
284
|
-
next.push(
|
|
285
|
-
if (platforms.includes('web')) next.push('
|
|
362
|
+
next.push(`Give the home screen testID="home" (${firstTest} looks for it).`);
|
|
363
|
+
if (platforms.includes('web')) next.push(`${execBin(pm, 'playwright install chromium')}, then ${runScript(pm, 'e2e:web')}`);
|
|
286
364
|
next.forEach((line, i) => ctx.out(` ${i + 1}. ${line}`));
|
|
287
|
-
if (platforms.some((p) => p !== 'web'))
|
|
365
|
+
if (platforms.some((p) => p !== 'web')) {
|
|
366
|
+
ctx.out(` • iOS / Android: ${runScript(pm, 'e2e:build:ios')} (or :android) builds the app into binaryPath, then ${runScript(pm, 'e2e:ios')}; quiesco test starts Metro when it is not running. \`${execBin(pm, 'quiesco doctor')}\` checks the setup.`);
|
|
367
|
+
}
|
|
288
368
|
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.');
|
|
289
369
|
return 0;
|
|
290
370
|
}
|
package/src/commands/list.ts
CHANGED
|
@@ -9,13 +9,15 @@ import { listTests } from '@quiesco/core';
|
|
|
9
9
|
|
|
10
10
|
import type { CliContext } from '../context.js';
|
|
11
11
|
import { takeFlag, takeOption } from '../context.js';
|
|
12
|
+
import { projectRunner } from '../runner.js';
|
|
12
13
|
|
|
13
14
|
export const LIST_HELP = `Usage: quiesco list [options] [runner arguments…]
|
|
14
15
|
|
|
15
16
|
Lists the tests the runner would run, without running them (no device is started).
|
|
16
17
|
|
|
17
18
|
Options:
|
|
18
|
-
--runner cucumber|jest|vitest Test runner (default:
|
|
19
|
+
--runner cucumber|jest|vitest Test runner (default: the one whose @quiesco package
|
|
20
|
+
is installed; cucumber when several or none are)
|
|
19
21
|
--json Print the list as JSON (ids as in the run events)
|
|
20
22
|
-h, --help Show this help
|
|
21
23
|
|
|
@@ -53,7 +55,7 @@ export async function listCommand(args: readonly string[], ctx: CliContext, deps
|
|
|
53
55
|
}
|
|
54
56
|
const r = takeOption(args, '--runner');
|
|
55
57
|
const json = takeFlag(r.rest, '--json');
|
|
56
|
-
const runner = r.value ??
|
|
58
|
+
const runner = r.value ?? projectRunner(ctx);
|
|
57
59
|
if (!(RUNNERS as readonly string[]).includes(runner)) {
|
|
58
60
|
ctx.err(`quiesco list: unknown runner "${runner}" (cucumber, jest or vitest).`);
|
|
59
61
|
return 2;
|
package/src/commands/test.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `quiesco test [--platform ios|android|web] [--runner cucumber|jest|vitest] [--workers N] [runner arguments…]`
|
|
3
3
|
* (requirements.md §6.12, Phase 6.10): sets QUIESCO_PLATFORM and runs the project's test runner with the
|
|
4
|
-
* remaining arguments unchanged. Default runner:
|
|
4
|
+
* remaining arguments unchanged. Default runner: the project's (projectRunner). `--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
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.
|
|
@@ -13,6 +13,7 @@ import { loadConfig } from '@quiesco/core';
|
|
|
13
13
|
|
|
14
14
|
import type { CliContext } from '../context.js';
|
|
15
15
|
import { parsePlatform, takeFlag, takeOption } from '../context.js';
|
|
16
|
+
import { projectRunner } from '../runner.js';
|
|
16
17
|
import { ensureDevServer } from '../dev-server.js';
|
|
17
18
|
import { cucumberFormatArgs, progressWanted, runWithProgress } from '../progress/run.js';
|
|
18
19
|
|
|
@@ -49,7 +50,8 @@ When nothing answers at devClient.metroUrl (native) or apps.web.url (web) on thi
|
|
|
49
50
|
|
|
50
51
|
Options:
|
|
51
52
|
--platform ios|android|web Platform to test (or set QUIESCO_PLATFORM)
|
|
52
|
-
--runner cucumber|jest|vitest Test runner (default:
|
|
53
|
+
--runner cucumber|jest|vitest Test runner (default: the one whose @quiesco package
|
|
54
|
+
is installed; cucumber when several or none are)
|
|
53
55
|
--workers N Run N workers, each on a device of its own
|
|
54
56
|
--no-progress No progress bar (it shows on a terminal, not in CI; or QUIESCO_PROGRESS=0)
|
|
55
57
|
-h, --help Show this help (\`quiesco test -- --help\` shows the runner's)
|
|
@@ -84,7 +86,7 @@ export async function testCommand(args: readonly string[], ctx: CliContext, deps
|
|
|
84
86
|
ctx.err('quiesco test: choose a platform with --platform ios|android|web (or set QUIESCO_PLATFORM). See quiesco test --help.');
|
|
85
87
|
return 2;
|
|
86
88
|
}
|
|
87
|
-
const runner = r.value ??
|
|
89
|
+
const runner = r.value ?? projectRunner(ctx);
|
|
88
90
|
if (!isRunner(runner)) {
|
|
89
91
|
ctx.err(`quiesco test: unknown runner "${runner}" (cucumber, jest or vitest).`);
|
|
90
92
|
return 2;
|
package/src/commands/ui.ts
CHANGED
|
@@ -13,6 +13,7 @@ import { listTests } from '@quiesco/core';
|
|
|
13
13
|
|
|
14
14
|
import type { CliContext } from '../context.js';
|
|
15
15
|
import { parsePlatform, takeFlag, takeOption } from '../context.js';
|
|
16
|
+
import { projectRunner } from '../runner.js';
|
|
16
17
|
import { ensureDevServer } from '../dev-server.js';
|
|
17
18
|
import { cucumberFormatArgs } from '../progress/run.js';
|
|
18
19
|
import { RUNNERS, defaultTestDeps, isRunner } from './test.js';
|
|
@@ -24,7 +25,8 @@ failures with Quiesco's evidence. Needs @quiesco/ui in the project (npm i -D @qu
|
|
|
24
25
|
|
|
25
26
|
Options:
|
|
26
27
|
--platform ios|android|web Platform to test (or set QUIESCO_PLATFORM)
|
|
27
|
-
--runner cucumber|jest|vitest Test runner (default:
|
|
28
|
+
--runner cucumber|jest|vitest Test runner (default: the one whose @quiesco package
|
|
29
|
+
is installed; cucumber when several or none are)
|
|
28
30
|
--workers N Run N workers, each on a device of its own
|
|
29
31
|
--port N Port of the UI (default: a free one)
|
|
30
32
|
--no-open Do not open the browser
|
|
@@ -97,7 +99,7 @@ export async function uiCommand(args: readonly string[], ctx: CliContext, deps:
|
|
|
97
99
|
ctx.err('quiesco ui: choose a platform with --platform ios|android|web (or set QUIESCO_PLATFORM). See quiesco ui --help.');
|
|
98
100
|
return 2;
|
|
99
101
|
}
|
|
100
|
-
const runner = r.value ??
|
|
102
|
+
const runner = r.value ?? projectRunner(ctx);
|
|
101
103
|
if (!isRunner(runner)) {
|
|
102
104
|
ctx.err(`quiesco ui: unknown runner "${runner}" (cucumber, jest or vitest).`);
|
|
103
105
|
return 2;
|
package/src/context.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { spawn as nodeSpawn } from 'node:child_process';
|
|
|
6
6
|
import fs from 'node:fs';
|
|
7
7
|
import { createRequire } from 'node:module';
|
|
8
8
|
import path from 'node:path';
|
|
9
|
+
import { createInterface } from 'node:readline/promises';
|
|
9
10
|
|
|
10
11
|
export interface ExecResult {
|
|
11
12
|
code: number;
|
|
@@ -37,6 +38,11 @@ export interface CliContext {
|
|
|
37
38
|
nodeVersion: string;
|
|
38
39
|
/** Whether a person is at the terminal (stdout is a TTY), not a CI job. */
|
|
39
40
|
interactive: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Ask the person at the terminal to pick one of `options` (numbered; Enter takes `defaultValue`).
|
|
43
|
+
* Returns `defaultValue` when stdin is not a terminal.
|
|
44
|
+
*/
|
|
45
|
+
choose(question: string, options: readonly { value: string; label: string }[], defaultValue: string): Promise<string>;
|
|
40
46
|
/** Start a long-running process (Metro) in its own process group, its output appended to `logFile`. */
|
|
41
47
|
spawnBackground(command: string, args: readonly string[], options: { cwd: string; env: NodeJS.ProcessEnv; logFile: string }): BackgroundProcess;
|
|
42
48
|
/** GET `url`; null when nothing answers (connection refused, timeout). */
|
|
@@ -120,6 +126,23 @@ export function defaultContext(): CliContext {
|
|
|
120
126
|
platform: process.platform,
|
|
121
127
|
nodeVersion: process.versions.node,
|
|
122
128
|
interactive: process.stdout.isTTY === true,
|
|
129
|
+
choose: async (question, options, defaultValue) => {
|
|
130
|
+
if (process.stdin.isTTY !== true) return defaultValue;
|
|
131
|
+
const def = Math.max(0, options.findIndex((o) => o.value === defaultValue));
|
|
132
|
+
process.stdout.write(`${question}\n${options.map((o, i) => ` ${i + 1}) ${o.label}`).join('\n')}\n`);
|
|
133
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
134
|
+
try {
|
|
135
|
+
for (;;) {
|
|
136
|
+
const answer = (await rl.question(`Choose 1-${options.length} [${def + 1}]: `)).trim();
|
|
137
|
+
if (answer === '') return defaultValue;
|
|
138
|
+
const byNumber = options[Number(answer) - 1];
|
|
139
|
+
const picked = /^\d+$/.test(answer) ? byNumber : options.find((o) => o.value === answer.toLowerCase());
|
|
140
|
+
if (picked !== undefined) return picked.value;
|
|
141
|
+
}
|
|
142
|
+
} finally {
|
|
143
|
+
rl.close();
|
|
144
|
+
}
|
|
145
|
+
},
|
|
123
146
|
spawnBackground: (command, args, options) => {
|
|
124
147
|
fs.mkdirSync(path.dirname(options.logFile), { recursive: true });
|
|
125
148
|
const log = fs.openSync(options.logFile, 'a');
|
package/src/runner.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The test runners Quiesco drives, and which one a project uses. `quiesco init` asks for one (Vitest by
|
|
3
|
+
* default) and installs its packages; `quiesco test` / `ui` / `list` without `--runner` use the one whose
|
|
4
|
+
* Quiesco package the project has.
|
|
5
|
+
*/
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
|
|
8
|
+
import type { CliContext } from './context.js';
|
|
9
|
+
|
|
10
|
+
/** In the order `quiesco init` offers them: the first is the default. */
|
|
11
|
+
export const RUNNER_NAMES = ['vitest', 'jest', 'cucumber'] as const;
|
|
12
|
+
export type RunnerName = (typeof RUNNER_NAMES)[number];
|
|
13
|
+
|
|
14
|
+
export function isRunnerName(v: string | undefined): v is RunnerName {
|
|
15
|
+
return v !== undefined && (RUNNER_NAMES as readonly string[]).includes(v);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** The devDependencies each runner needs: Quiesco's integration and the runner itself. */
|
|
19
|
+
export const RUNNER_PACKAGES: Record<RunnerName, readonly string[]> = {
|
|
20
|
+
vitest: ['@quiesco/vitest', 'vitest'],
|
|
21
|
+
jest: ['@quiesco/jest', 'jest'],
|
|
22
|
+
cucumber: ['@quiesco/cucumber', '@cucumber/cucumber'],
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const RUNNER_LABELS: Record<RunnerName, string> = {
|
|
26
|
+
vitest: 'Vitest (recommended): tests in TypeScript, app as a test fixture',
|
|
27
|
+
jest: 'Jest: tests in JavaScript, app as the global quiesco.app',
|
|
28
|
+
cucumber: 'Cucumber: Gherkin features with step definitions',
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The runner whose Quiesco package (@quiesco/vitest, @quiesco/jest, @quiesco/cucumber) is in package.json.
|
|
33
|
+
* With none or several of them: cucumber, the default of Quiesco 0.6 and earlier (projects set up then
|
|
34
|
+
* keep running the same way); `--runner` picks another.
|
|
35
|
+
*/
|
|
36
|
+
export function projectRunner(ctx: CliContext): RunnerName {
|
|
37
|
+
const text = ctx.readFile(path.join(ctx.cwd, 'package.json'));
|
|
38
|
+
let pkg: { dependencies?: Record<string, string>; devDependencies?: Record<string, string> } = {};
|
|
39
|
+
try {
|
|
40
|
+
pkg = text === null ? {} : (JSON.parse(text) as typeof pkg);
|
|
41
|
+
} catch {
|
|
42
|
+
// unreadable package.json: the default
|
|
43
|
+
}
|
|
44
|
+
const has = (name: string): boolean => pkg.dependencies?.[name] !== undefined || pkg.devDependencies?.[name] !== undefined;
|
|
45
|
+
const found = RUNNER_NAMES.filter((r) => has(RUNNER_PACKAGES[r][0] as string));
|
|
46
|
+
return found.length === 1 ? (found[0] as RunnerName) : 'cucumber';
|
|
47
|
+
}
|
package/src/setup-steps.ts
CHANGED
|
@@ -49,8 +49,8 @@ export interface StepLog {
|
|
|
49
49
|
|
|
50
50
|
/** Installed into `dependencies`: the app bundles them (stubbed / excluded in production builds). */
|
|
51
51
|
export const RUNTIME = ['@quiesco/agent', '@quiesco/native'];
|
|
52
|
-
/** Installed into `devDependencies
|
|
53
|
-
export const DEV = ['quiesco', '@quiesco/core', '@quiesco/
|
|
52
|
+
/** Installed into `devDependencies`, with the chosen runner's packages (RUNNER_PACKAGES). */
|
|
53
|
+
export const DEV = ['quiesco', '@quiesco/core', '@quiesco/expo-plugin'];
|
|
54
54
|
export const WEB_DEV = ['@quiesco/web', 'playwright'];
|
|
55
55
|
/** Internal packages pulled in by the ones above; only pinned when installing from tarballs. */
|
|
56
56
|
const TRANSITIVE = ['@quiesco/protocol'];
|
|
@@ -295,22 +295,34 @@ export function ensureTsconfig(log: StepLog): void {
|
|
|
295
295
|
|
|
296
296
|
// ---- scripts ----
|
|
297
297
|
|
|
298
|
-
|
|
298
|
+
/** `testArgs`: appended to each `quiesco test` (`--config vitest.e2e.config.mts` when init wrote that file). */
|
|
299
|
+
export function e2eScripts(platforms: readonly CliPlatform[], testArgs = ''): Record<string, string> {
|
|
300
|
+
const extra = testArgs === '' ? '' : ` ${testArgs}`;
|
|
299
301
|
return {
|
|
300
302
|
'e2e:start': 'EXPO_PUBLIC_QUIESCO=1 expo start',
|
|
301
|
-
...(platforms.includes('web') ? { 'e2e:web':
|
|
302
|
-
...(platforms.includes('android') ? { 'e2e:build:android': 'quiesco build android', 'e2e:android':
|
|
303
|
-
...(platforms.includes('ios') ? { 'e2e:build:ios': 'quiesco build ios', 'e2e:ios':
|
|
303
|
+
...(platforms.includes('web') ? { 'e2e:web': `EXPO_PUBLIC_QUIESCO=1 expo export --platform web && quiesco test --platform web${extra}` } : {}),
|
|
304
|
+
...(platforms.includes('android') ? { 'e2e:build:android': 'quiesco build android', 'e2e:android': `quiesco test --platform android${extra}` } : {}),
|
|
305
|
+
...(platforms.includes('ios') ? { 'e2e:build:ios': 'quiesco build ios', 'e2e:ios': `quiesco test --platform ios${extra}` } : {}),
|
|
304
306
|
};
|
|
305
307
|
}
|
|
306
308
|
|
|
309
|
+
/** `pm run <script>` as the person types it (`npm run x`, `pnpm x`, `yarn x`, `bun run x`). */
|
|
310
|
+
export function runScript(pm: PackageManager, script: string): string {
|
|
311
|
+
return pm === 'pnpm' || pm === 'yarn' ? `${pm} ${script}` : `${pm} run ${script}`;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/** `npx <command>` for the package manager (`pnpm exec`, `yarn`, `bunx`): runs the project's own binary. */
|
|
315
|
+
export function execBin(pm: PackageManager, command: string): string {
|
|
316
|
+
return { npm: 'npx', pnpm: 'pnpm exec', yarn: 'yarn', bun: 'bunx' }[pm] + ` ${command}`;
|
|
317
|
+
}
|
|
318
|
+
|
|
307
319
|
/** Add the e2e scripts that are missing; existing scripts of the same name are left alone. */
|
|
308
|
-
export function ensureScripts(log: StepLog, platforms: readonly CliPlatform[]): void {
|
|
320
|
+
export function ensureScripts(log: StepLog, platforms: readonly CliPlatform[], testArgs = ''): void {
|
|
309
321
|
const { ctx, steps } = log;
|
|
310
322
|
const pkgFile = path.join(ctx.cwd, 'package.json');
|
|
311
323
|
const pkg = readJson<PackageJson>(ctx, pkgFile) as PackageJson;
|
|
312
324
|
const scripts = { ...(pkg.scripts ?? {}) };
|
|
313
|
-
const wanted = e2eScripts(platforms);
|
|
325
|
+
const wanted = e2eScripts(platforms, testArgs);
|
|
314
326
|
const added = Object.keys(wanted).filter((k) => scripts[k] === undefined);
|
|
315
327
|
if (added.length === 0) {
|
|
316
328
|
steps.push({ status: 'skipped', what: 'scripts', note: 'the e2e scripts exist' });
|