@quiesco/vitest 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 CHANGED
@@ -9,9 +9,9 @@ npm i -D @quiesco/vitest @quiesco/core vitest
9
9
 
10
10
  ```ts
11
11
  // vitest.config.ts
12
- import { quiesco } from '@quiesco/vitest/config';
12
+ import { quiesco, quiescoPlugin } from '@quiesco/vitest/config';
13
13
  import { defineConfig } from 'vitest/config';
14
- export default defineConfig({ test: { ...quiesco(), include: ['e2e/**/*.test.ts'] } });
14
+ export default defineConfig({ plugins: [quiescoPlugin()], test: { ...quiesco(), include: ['e2e/**/*.test.ts'] } });
15
15
 
16
16
  // e2e/todo.test.ts
17
17
  import { test } from '@quiesco/vitest';
@@ -22,7 +22,8 @@ test('a new todo appears at the top', async ({ app }) => {
22
22
  });
23
23
  ```
24
24
 
25
- Run with `npx quiesco test --platform ios --runner vitest`. Details:
25
+ `quiescoPlugin()` sends the run's progress to the progress bar of `quiesco test` and to `quiesco ui` (your
26
+ own reporters stay). Run with `npx quiesco test --platform ios --runner vitest`. Details:
26
27
  [using Quiesco without Cucumber](https://shift-14cc7601.mintlify.site/api#using-quiesco-without-cucumber).
27
28
 
28
29
  Part of [Quiesco](https://github.com/h2nology/quiesco): gray-box end-to-end testing for Expo apps on iOS, Android and the web. Setup: `npx quiesco init` ([quick start](https://github.com/h2nology/quiesco#quick-start-web-about-10-minutes)).
package/dist/config.d.ts CHANGED
@@ -20,5 +20,25 @@ export declare function quiesco(options?: QuiescoVitestOptions): {
20
20
  tags: {
21
21
  name: string;
22
22
  }[];
23
+ includeTaskLocation: boolean;
23
24
  };
25
+ /** The parts of Vitest's `configureVitest` context used here (structural: no vitest import). */
26
+ interface ConfigureVitestContext {
27
+ vitest: {
28
+ config: {
29
+ reporters: unknown[];
30
+ };
31
+ };
32
+ }
33
+ /**
34
+ * Vite plugin that adds Quiesco's reporter when `quiesco test` / `quiesco ui` runs Vitest (it sets
35
+ * QUIESCO_EVENTS), keeping the reporters you configured or passed with `--reporter`:
36
+ *
37
+ * export default defineConfig({ plugins: [quiescoPlugin()], test: { ...quiesco() } });
38
+ */
39
+ export declare function quiescoPlugin(): {
40
+ name: string;
41
+ configureVitest({ vitest }: ConfigureVitestContext): void;
42
+ };
43
+ export {};
24
44
  //# sourceMappingURL=config.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C,MAAM,WAAW,oBAAoB;IACnC,iEAAiE;IACjE,IAAI,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;IACzB,oEAAoE;IACpE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,4DAA4D;IAC5D,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC9B,mFAAmF;IACnF,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,wBAAgB,OAAO,CAAC,OAAO,GAAE,oBAAyB;;;;;;;;;;;EAczD"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C,MAAM,WAAW,oBAAoB;IACnC,iEAAiE;IACjE,IAAI,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;IACzB,oEAAoE;IACpE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,4DAA4D;IAC5D,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC9B,mFAAmF;IACnF,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,wBAAgB,OAAO,CAAC,OAAO,GAAE,oBAAyB;;;;;;;;;;;;EAgBzD;AAED,gGAAgG;AAChG,UAAU,sBAAsB;IAC9B,MAAM,EAAE;QAAE,MAAM,EAAE;YAAE,SAAS,EAAE,OAAO,EAAE,CAAA;SAAE,CAAA;KAAE,CAAC;CAC9C;AAED;;;;;GAKG;AACH,wBAAgB,aAAa;;gCAGG,sBAAsB,GAAG,IAAI;EAM5D"}
package/dist/config.js CHANGED
@@ -11,8 +11,10 @@
11
11
  * (Phase 6.12): `quiesco({ workers: 2 })`, or `--fileParallelism --maxWorkers 2` on the command line.
12
12
  * - The platform tags are declared, so `test(name, { tags: ['@ios'] }, …)` is accepted.
13
13
  * - `testTimeout`: the first test also waits for the session (booting a device can take minutes).
14
+ * - `quiescoPlugin()` (in `plugins`) sends the run's progress to `quiesco test` / `quiesco ui`.
14
15
  */
15
- import { DEFAULT_TAGS } from '@quiesco/core';
16
+ import { fileURLToPath } from 'node:url';
17
+ import { DEFAULT_TAGS, RUN_EVENTS_ENV } from '@quiesco/core';
16
18
  export function quiesco(options = {}) {
17
19
  const names = { ...DEFAULT_TAGS, ...options.tags };
18
20
  const declared = [...new Set([names.ios, names.android, names.web, names.native, names.hardReset, ...(options.extraTags ?? [])])];
@@ -26,6 +28,25 @@ export function quiesco(options = {}) {
26
28
  hookTimeout: options.testTimeout ?? 300_000,
27
29
  teardownTimeout: 120_000,
28
30
  tags: declared.map((name) => ({ name })),
31
+ // Lines for the run events (progress bar, `quiesco ui`: run one test by file:line).
32
+ includeTaskLocation: true,
33
+ };
34
+ }
35
+ /**
36
+ * Vite plugin that adds Quiesco's reporter when `quiesco test` / `quiesco ui` runs Vitest (it sets
37
+ * QUIESCO_EVENTS), keeping the reporters you configured or passed with `--reporter`:
38
+ *
39
+ * export default defineConfig({ plugins: [quiescoPlugin()], test: { ...quiesco() } });
40
+ */
41
+ export function quiescoPlugin() {
42
+ return {
43
+ name: 'quiesco:run-events',
44
+ configureVitest({ vitest }) {
45
+ const address = process.env[RUN_EVENTS_ENV];
46
+ if (address === undefined || address === '')
47
+ return;
48
+ vitest.config.reporters.push([fileURLToPath(new URL('./reporter.js', import.meta.url)), {}]);
49
+ },
29
50
  };
30
51
  }
31
52
  //# sourceMappingURL=config.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAc7C,MAAM,UAAU,OAAO,CAAC,UAAgC,EAAE;IACxD,MAAM,KAAK,GAAG,EAAE,GAAG,YAAY,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IACnD,MAAM,QAAQ,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,SAAS,EAAE,GAAG,CAAC,OAAO,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IAClI,OAAO;QACL,IAAI,EAAE,OAAgB;QACtB,OAAO,EAAE,KAAK;QACd,qFAAqF;QACrF,eAAe,EAAE,CAAC,OAAO,CAAC,OAAO,IAAI,CAAC,CAAC,GAAG,CAAC;QAC3C,UAAU,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,OAAO,IAAI,CAAC,CAAC;QAC7C,WAAW,EAAE,OAAO,CAAC,WAAW,IAAI,OAAO;QAC3C,WAAW,EAAE,OAAO,CAAC,WAAW,IAAI,OAAO;QAC3C,eAAe,EAAE,OAAO;QACxB,IAAI,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;KACzC,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,EAAE,Y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AM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,aAAa,CAAC,IAAI,GAAG,CAAC,eAAe,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;QAC/F,CAAC;KACF,CAAC;AACJ,CAAC"}
package/dist/index.d.ts CHANGED
@@ -19,7 +19,7 @@
19
19
  import { Lifecycle } from '@quiesco/core';
20
20
  import type { Driver, Session, WorkerInfo } from '@quiesco/core';
21
21
  import type { TaskLike } from './tags.js';
22
- export { quiesco } from './config.js';
22
+ export { quiesco, quiescoPlugin } from './config.js';
23
23
  export type { QuiescoVitestOptions } from './config.js';
24
24
  export { fullName, tagLevelsOf } from './tags.js';
25
25
  export type { TaskLike } from './tags.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAIjE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAE1C,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,YAAY,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAClD,YAAY,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAE1C;;;;GAIG;AACH,wBAAgB,YAAY,CAC1B,GAAG,GAAE,MAAM,CAAC,UAAwB,EACpC,MAAM,GAAE;IAAE,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,eAAe,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,SAA6I,GACzM,UAAU,CAKZ;AAED,UAAU,UAAW,SAAQ,QAAQ;IACnC,MAAM,CAAC,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AU,UAAW,SAAQ,QAAQ;IACnC,MAAM,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE;YAAE,OAAO,CAAC,EAAE,MAAM,CAAC;YAAC,KAAK,CAAC,EAAE,MAAM,CAAA;SAAE,EAAE,CAAA;KAAE,GAAG,SAAS,CAAC;CAC1F;AAED,oHAAoH;AACpH,wBAAgB,WAAW,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAM5E;AAQD,eAAO,MAAM,IAAI;SAED,MAAM;aAAW,OAAO;;aADlB,SAAS;WA2C7B,CAAC;AAEH,eAAO,MAAM,EAAE;SA5CC,MAAM;aAAW,OAAO;;aADlB,SAAS;WA6CT,CAAC;AACvB,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC"}
package/dist/index.js CHANGED
@@ -16,10 +16,10 @@
16
16
  * - After a failed test: the evidence (screenshot, element tree, idle state, logs) is written to the
17
17
  * artifacts directory and its path is added to the failure message.
18
18
  */
19
- import { Lifecycle } from '@quiesco/core';
19
+ import { Lifecycle, connectRunEvents } from '@quiesco/core';
20
20
  import { test as base } from 'vitest';
21
21
  import { fullName, tagLevelsOf } from './tags.js';
22
- export { quiesco } from './config.js';
22
+ export { quiesco, quiescoPlugin } from './config.js';
23
23
  export { fullName, tagLevelsOf } from './tags.js';
24
24
  /**
25
25
  * The worker this process is (Phase 6.12): VITEST_POOL_ID (1…maxWorkers) is fixed for a worker process,
@@ -45,6 +45,8 @@ export function addEvidence(task, files) {
45
45
  }
46
46
  /** A session that failed to start fails the remaining tests at once instead of starting again for each. */
47
47
  let startFailure = null;
48
+ /** Evidence files go to `quiesco test` / `quiesco ui` from this worker; connected on the first failure. */
49
+ let events = null;
48
50
  export const test = base.extend({
49
51
  quiesco: [
50
52
  // Vitest reads a fixture's dependencies from the destructuring pattern: it must be `{}` here.
@@ -64,6 +66,8 @@ export const test = base.extend({
64
66
  await use(lifecycle);
65
67
  }
66
68
  finally {
69
+ await events?.close();
70
+ events = null;
67
71
  await lifecycle.afterAll();
68
72
  }
69
73
  },
@@ -72,15 +76,19 @@ export const test = base.extend({
72
76
  session: async ({ quiesco, task, skip }, use) => {
73
77
  const t = task;
74
78
  if ((await quiesco.before(tagLevelsOf(t), fullName(t))) === 'skipped')
75
- skip('tagged for another platform');
79
+ skip(quiesco.bailedOut ?? 'tagged for another platform');
76
80
  try {
77
81
  await use(quiesco.current);
78
82
  }
79
83
  finally {
80
84
  const failed = t.result?.state === 'fail';
81
- const { files } = await quiesco.after({ tags: tagLevelsOf(t).flat(), failed });
85
+ const { files } = await quiesco.after({ tags: tagLevelsOf(t).flat(), failed, error: t.result?.errors?.[0] });
82
86
  if (failed)
83
87
  addEvidence(t, files);
88
+ if (files.length > 0) {
89
+ events ??= connectRunEvents({ runner: 'vitest' });
90
+ events.send({ type: 'test:evidence', testId: task.id, files });
91
+ }
84
92
  }
85
93
  },
86
94
  app: async ({ session }, use) => {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE1C,OAAO,EAAE,IAAI,IAAI,IAAI,EAAE,MAAM,QAAQ,CAAC;AAEtC,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAGlD,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAEtC,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAGlD;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAC1B,MAAyB,OAAO,CAAC,GAAG,EACpC,SAA0E,UAAsG,CAAC,iBAAiB,EAAE,MAAM;IAE1M,MAAM,KAAK,GAAG,MAAM,EAAE,eAAe,KAAK,KAAK,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,CAAC,CAAC;YAC7G,IAAI,MAAM;gBAAE,WAAW,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;YAClC,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACrB,MAAM,KAAK,gBAAgB,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;gBAClD,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;YACjE,CAAC;QACH,CAAC;IACH,CAAC;IACD,GAAG,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,GAAG,EAAE,EAAE;QAC9B,MAAM,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAC5B,CAAC;CACF,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC;AACvB,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=list-main.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"list-main.d.ts","sourceRoot":"","sources":["../src/list-main.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ // `node list-main.js --out <file> [vitest arguments]`: see list.ts.
2
+ import { listMain } from './list.js';
3
+ await listMain(process.argv.slice(2));
4
+ //# sourceMappingURL=list-main.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"list-main.js","sourceRoot":"","sources":["../src/list-main.ts"],"names":[],"mappings":"AAAA,oEAAoE;AACpE,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC,MAAM,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC"}
package/dist/list.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ import type { TestList } from '@quiesco/core';
2
+ export interface ListArgs {
3
+ out: string;
4
+ config?: string;
5
+ filters: string[];
6
+ }
7
+ export declare function parseListArgs(argv: readonly string[]): ListArgs;
8
+ export declare function listVitestTests(args: Omit<ListArgs, 'out'>): Promise<TestList>;
9
+ export declare function listMain(argv: readonly string[]): Promise<void>;
10
+ //# sourceMappingURL=list.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../src/list.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,QAAQ,EAAW,MAAM,eAAe,CAAC;AAKvD,MAAM,WAAW,QAAQ;IACvB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,QAAQ,CAU/D;AAED,wBAAsB,eAAe,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAgBpF;AAMD,wBAAsB,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAWrE"}
package/dist/list.js ADDED
@@ -0,0 +1,66 @@
1
+ /**
2
+ * `node …/@quiesco/vitest/dist/list-main.js --out <file> [--config <file>] [filters…]`: lists the tests
3
+ * Vitest would run, without running them (`quiesco list`, the UI's test tree). Run in the project
4
+ * directory. Writes a TestList (JSON) to `--out`.
5
+ *
6
+ * A static parse (`parseSpecifications`): no globalSetup, setup files, module code or fixtures run
7
+ * (findings P0). `test.each` is listed once; skipped and todo tests are listed too. Ids are Vitest's own
8
+ * test ids, as the reporter sends them.
9
+ */
10
+ import fs from 'node:fs';
11
+ import { createVitest } from 'vitest/node';
12
+ import { testRef } from './reporter.js';
13
+ export function parseListArgs(argv) {
14
+ const args = { out: '', filters: [] };
15
+ for (let i = 0; i < argv.length; i++) {
16
+ const a = argv[i];
17
+ if (a === '--out')
18
+ args.out = argv[++i] ?? '';
19
+ else if (a === '--config' || a === '-c')
20
+ args.config = argv[++i] ?? '';
21
+ else if (a.startsWith('--config='))
22
+ args.config = a.slice('--config='.length);
23
+ else if (!a.startsWith('-'))
24
+ args.filters.push(a);
25
+ }
26
+ return args;
27
+ }
28
+ export async function listVitestTests(args) {
29
+ const vitest = await createVitest({ ...(args.config !== undefined ? { config: args.config } : {}), watch: false, reporters: [] });
30
+ try {
31
+ const root = vitest.config.root;
32
+ const specifications = await vitest.globTestSpecifications(args.filters);
33
+ const modules = await vitest.parseSpecifications(specifications);
34
+ const tests = [];
35
+ const errors = [];
36
+ for (const m of modules) {
37
+ for (const t of m.children.allTests())
38
+ tests.push(testRef(t, root));
39
+ for (const e of m.errors())
40
+ errors.push({ file: testRefFile(root, m.moduleId), message: e.message });
41
+ }
42
+ return { runner: 'vitest', files: specifications.map((s) => testRefFile(root, s.moduleId)), tests, errors };
43
+ }
44
+ finally {
45
+ await vitest.close();
46
+ }
47
+ }
48
+ function testRefFile(root, file) {
49
+ return file.startsWith(`${root}/`) ? file.slice(root.length + 1) : file;
50
+ }
51
+ export async function listMain(argv) {
52
+ const args = parseListArgs(argv);
53
+ let list;
54
+ try {
55
+ list = await listVitestTests(args);
56
+ }
57
+ catch (e) {
58
+ list = { runner: 'vitest', files: [], tests: [], errors: [{ message: e.message }] };
59
+ }
60
+ const json = JSON.stringify(list);
61
+ if (args.out === '')
62
+ process.stdout.write(`${json}\n`);
63
+ else
64
+ fs.writeFileSync(args.out, json);
65
+ }
66
+ //# sourceMappingURL=list.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"list.js","sourceRoot":"","sources":["../src/list.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,MAAM,SAAS,CAAC;AAGzB,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC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I,IAAc,CAAC;IACnB,IAAI,CAAC;QACH,IAAI,GAAG,MAAM,eAAe,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,IAAI,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,OAAO,EAAG,CAAW,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC;IACjG,CAAC;IACD,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAClC,IAAI,IAAI,CAAC,GAAG,KAAK,EAAE;QAAE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,IAAI,CAAC,CAAC;;QAClD,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;AACxC,CAAC"}
@@ -0,0 +1,22 @@
1
+ import type { TestRef } from '@quiesco/core';
2
+ import type { Reporter, SerializedError, TestCase, TestModule, TestRunEndReason, TestSpecification, Vitest } from 'vitest/node';
3
+ export declare function testRef(test: TestCase, root: string): TestRef;
4
+ export default class QuiescoReporter implements Reporter {
5
+ private client;
6
+ private vitest;
7
+ private root;
8
+ /** Tests per file: the static estimate until the file is collected. */
9
+ private readonly perFile;
10
+ private startedAt;
11
+ onInit(vitest: Vitest): void;
12
+ /** One connection per run: closed at the run's end so its last events are flushed before Vitest exits. */
13
+ onTestRunStart(specifications: ReadonlyArray<TestSpecification>): Promise<void>;
14
+ onTestModuleCollected(m: TestModule): void;
15
+ onTestModuleStart(m: TestModule): void;
16
+ onTestModuleEnd(m: TestModule): void;
17
+ onTestCaseReady(test: TestCase): void;
18
+ onTestCaseResult(test: TestCase): void;
19
+ onTestRunEnd(_modules: ReadonlyArray<TestModule>, unhandledErrors: ReadonlyArray<SerializedError>, reason: TestRunEndReason): Promise<void>;
20
+ private total;
21
+ }
22
+ //# sourceM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1,133 @@
1
+ /**
2
+ * `@quiesco/vitest/reporter`: sends run events to `quiesco test` / `quiesco ui` (progress bar, test UI)
3
+ * from Vitest's main process (findings P0, vitest 5.1.0). Added to the run by `quiescoPlugin()` from
4
+ * `@quiesco/vitest/config` — the command line `--reporter` would replace the user's reporters. Without
5
+ * QUIESCO_EVENTS it does nothing.
6
+ *
7
+ * - Total: estimated at the start from a static parse of the files (nothing executes; `test.each`
8
+ * counts once), then corrected per file once Vitest has collected it.
9
+ * - Worker: the file's `concurrencyId` (1…N, the worker slot) − 1.
10
+ * - Test id: Vitest's own test id (stable across runs of the same file).
11
+ */
12
+ import path from 'node:path';
13
+ import { connectRunEvents } from '@quiesco/core';
14
+ function relative(root, file) {
15
+ return path.relative(root, file).split(path.sep).join('/');
16
+ }
17
+ export function testRef(test, root) {
18
+ const titles = [test.name];
19
+ for (let p = test.parent; p.type === 'suite'; p = p.parent)
20
+ titles.unshift(p.name);
21
+ return { id: test.id, file: relative(root, test.module.moduleId), ...(test.location !== undefined ? { line: test.location.line } : {}), name: test.name, path: titles };
22
+ }
23
+ function runError(e) {
24
+ if (e === undefined)
25
+ return undefined;
26
+ return { message: e.message ?? 'Error', ...(e.stack !== undefined ? { stack: e.stack } : {}), ...(e.diff !== undefined ? { diff: e.diff } : {}) };
27
+ }
28
+ function countTests(m) {
29
+ return [...m.children.allTests()].length;
30
+ }
31
+ function worker(m) {
32
+ const id = m.diagnostic().concurrencyId;
33
+ return id >= 1 ? id - 1 : undefined;
34
+ }
35
+ export default class QuiescoReporter {
36
+ client = null;
37
+ vitest = null;
38
+ root = process.cwd();
39
+ /** Tests per file: the static estimate until the file is collected. */
40
+ perFile = new Map();
41
+ startedAt = 0;
42
+ onInit(vitest) {
43
+ this.vitest = vitest;
44
+ this.root = vitest.config.root;
45
+ }
46
+ /** One connection per run: closed at the run's end so its last events are flushed before Vitest exits. */
47
+ async onTestRunStart(specifications) {
48
+ const client = connectRunEvents({ runner: 'vitest', ...(this.vitest !== null ? { runnerVersion: this.vitest.version } : {}) });
49
+ if (!client.enabled)
50
+ return;
51
+ this.client = client;
52
+ this.startedAt = Date.now();
53
+ this.perFile.clear();
54
+ const files = [...new Set(specifications.map((s) => s.moduleId))];
55
+ let modules = [];
56
+ try {
57
+ modules = this.vitest !== null ? await this.vitest.parseSpecifications([...specifications]) : [];
58
+ }
59
+ catch {
60
+ // The estimate is a nicety: without it the total grows as files are collected.
61
+ }
62
+ for (const m of modules)
63
+ this.perFile.set(m.moduleId, { count: countTests(m), exact: false });
64
+ const maxWorkers = this.vitest?.config.maxWorkers;
65
+ this.client.send({
66
+ type: 'run:start',
67
+ total: this.total(),
68
+ totalIsEstimate: true,
69
+ files: files.map((f) => relative(this.root, f)),
70
+ ...(typeof maxWorkers === 'number' ? { workers: maxWorkers } : {}),
71
+ });
72
+ }
73
+ onTestModuleCollected(m) {
74
+ if (this.client === null)
75
+ return;
76
+ this.perFile.set(m.moduleId, { count: countTests(m), exact: true });
77
+ this.client.send({ type: 'total:update', total: this.total(), totalIsEstimate: [...this.perFile.values()].some((f) => !f.exact) });
78
+ }
79
+ onTestModuleStart(m) {
80
+ this.client?.send({ type: 'file:start', file: relative(this.root, m.moduleId) });
81
+ }
82
+ onTestModuleEnd(m) {
83
+ if (this.client === null)
84
+ return;
85
+ const error = m.state() === 'failed' && countTests(m) === 0 ? runError(m.errors()[0]) : undefined;
86
+ this.client.send({ type: 'file:end', file: relative(this.root, m.moduleId), ...(error !== undefined ? { error } : {}) });
87
+ }
88
+ onTestCaseReady(test) {
89
+ if (this.client === null)
90
+ return;
91
+ const w = worker(test.module);
92
+ this.client.send({ type: 'test:start', test: testRef(test, this.root), attempt: 0, startedAt: test.diagnostic()?.startTime ?? Date.now(), ...(w !== undefined ? { worker: w } : {}) });
93
+ }
94
+ onTestCaseResult(test) {
95
+ if (this.client === null)
96
+ return;
97
+ const r = test.result();
98
+ const status = test.options.mode === 'todo' ? 'todo' : r.state === 'pending' ? 'skipped' : r.state;
99
+ const error = r.state === 'failed' ? runError(r.errors[0]) : undefined;
100
+ const logs = test.logs().map((l) => ({ stream: l.type, text: l.content }));
101
+ const w = worker(test.module);
102
+ this.client.send({
103
+ type: 'test:end',
104
+ test: testRef(test, this.root),
105
+ status,
106
+ durationMs: Math.round(test.diagnostic()?.duration ?? 0),
107
+ willRetry: false, // Vitest retries inside the test and reports once
108
+ ...(error !== undefined ? { error } : {}),
109
+ ...(logs.length > 0 ? { logs } : {}),
110
+ ...(w !== undefined ? { worker: w } : {}),
111
+ });
112
+ }
113
+ async onTestRunEnd(_modules, unhandledErrors, reason) {
114
+ const client = this.client;
115
+ if (client === null)
116
+ return;
117
+ for (const e of unhandledErrors) {
118
+ const error = runError(e);
119
+ if (error !== undefined)
120
+ client.send({ type: 'run:error', error });
121
+ }
122
+ client.send({ type: 'run:end', success: reason === 'passed', interrupted: reason === 'interrupted', durationMs: Date.now() - this.startedAt });
123
+ this.client = null;
124
+ await client.close();
125
+ }
126
+ total() {
127
+ let n = 0;
128
+ for (const f of this.perFile.values())
129
+ n += f.count;
130
+ return n;
131
+ }
132
+ }
133
+ //# sourceMappingURL=reporter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reporter.js","sourceRoot":"","sources":["../src/reporter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAIjD,SAAS,QAAQ,CAAC,IAAY,EAAE,IAAY;IAC1C,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC7D,CAAC;AAED,MAAM,UAAU,OAAO,CAAC,IAAc,EAAE,IAAY;IAClD,MAAM,MAAM,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC3B,KAAK,IAAI,CAAC,GAAG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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quiesco/vitest",
3
- "version": "0.1.1",
3
+ "version": "0.3.0",
4
4
  "description": "Quiesco for Vitest: one session for the run, `app` as a test fixture, a reset before every test",
5
5
  "license": "MIT",
6
6
  "author": "h2nology",
@@ -37,6 +37,14 @@
37
37
  "./config": {
38
38
  "types": "./dist/config.d.ts",
39
39
  "import": "./dist/config.js"
40
+ },
41
+ "./reporter": {
42
+ "types": "./dist/reporter.d.ts",
43
+ "import": "./dist/reporter.js"
44
+ },
45
+ "./list": {
46
+ "types": "./dist/list-main.d.ts",
47
+ "default": "./dist/list-main.js"
40
48
  }
41
49
  },
42
50
  "files": [
@@ -44,7 +52,7 @@
44
52
  "src"
45
53
  ],
46
54
  "dependencies": {
47
- "@quiesco/core": "0.1.1"
55
+ "@quiesco/core": "0.3.0"
48
56
  },
49
57
  "peerDependencies": {
50
58
  "vitest": ">=5.1"
package/src/config.ts CHANGED
@@ -11,8 +11,11 @@
11
11
  * (Phase 6.12): `quiesco({ workers: 2 })`, or `--fileParallelism --maxWorkers 2` on the command line.
12
12
  * - The platform tags are declared, so `test(name, { tags: ['@ios'] }, …)` is accepted.
13
13
  * - `testTimeout`: the first test also waits for the session (booting a device can take minutes).
14
+ * - `quiescoPlugin()` (in `plugins`) sends the run's progress to `quiesco test` / `quiesco ui`.
14
15
  */
15
- import { DEFAULT_TAGS } from '@quiesco/core';
16
+ import { fileURLToPath } from 'node:url';
17
+
18
+ import { DEFAULT_TAGS, RUN_EVENTS_ENV } from '@quiesco/core';
16
19
  import type { TagNames } from '@quiesco/core';
17
20
 
18
21
  export interface QuiescoVitestOptions {
@@ -39,5 +42,29 @@ export function quiesco(options: QuiescoVitestOptions = {}) {
39
42
  hookTimeout: options.testTimeout ?? 300_000,
40
43
  teardownTimeout: 120_000,
41
44
  tags: declared.map((name) => ({ name })),
45
+ // Lines for the run events (progress bar, `quiesco ui`: run one test by file:line).
46
+ includeTaskLocation: true,
47
+ };
48
+ }
49
+
50
+ /** The parts of Vitest's `configureVitest` context used here (structural: no vitest import). */
51
+ interface ConfigureVitestContext {
52
+ vitest: { config: { reporters: unknown[] } };
53
+ }
54
+
55
+ /**
56
+ * Vite plugin that adds Quiesco's reporter when `quiesco test` / `quiesco ui` runs Vitest (it sets
57
+ * QUIESCO_EVENTS), keeping the reporters you configured or passed with `--reporter`:
58
+ *
59
+ * export default defineConfig({ plugins: [quiescoPlugin()], test: { ...quiesco() } });
60
+ */
61
+ export function quiescoPlugin() {
62
+ return {
63
+ name: 'quiesco:run-events',
64
+ configureVitest({ vitest }: ConfigureVitestContext): void {
65
+ const address = process.env[RUN_EVENTS_ENV];
66
+ if (address === undefined || address === '') return;
67
+ vitest.config.reporters.push([fileURLToPath(new URL('./reporter.js', import.meta.url)), {}]);
68
+ },
42
69
  };
43
70
  }
package/src/index.ts CHANGED
@@ -16,14 +16,14 @@
16
16
  * - After a failed test: the evidence (screenshot, element tree, idle state, logs) is written to the
17
17
  * artifacts directory and its path is added to the failure message.
18
18
  */
19
- import { Lifecycle } from '@quiesco/core';
20
- import type { Driver, Session, WorkerInfo } from '@quiesco/core';
19
+ import { Lifecycle, connectRunEvents } from '@quiesco/core';
20
+ import type { Driver, RunEventClient, Session, WorkerInfo } from '@quiesco/core';
21
21
  import { test as base } from 'vitest';
22
22
 
23
23
  import { fullName, tagLevelsOf } from './tags.js';
24
24
  import type { TaskLike } from './tags.js';
25
25
 
26
- export { quiesco } from './config.js';
26
+ export { quiesco, quiescoPlugin } from './config.js';
27
27
  export type { QuiescoVitestOptions } from './config.js';
28
28
  export { fullName, tagLevelsOf } from './tags.js';
29
29
  export type { TaskLike } from './tags.js';
@@ -59,6 +59,9 @@ export function addEvidence(task: FailedTask, files: readonly string[]): void {
59
59
  /** A session that failed to start fails the remaining tests at once instead of starting again for each. */
60
60
  let startFailure: unknown = null;
61
61
 
62
+ /** Evidence files go to `quiesco test` / `quiesco ui` from this worker; connected on the first failure. */
63
+ let events: RunEventClient | null = null;
64
+
62
65
  export const test = base.extend<{
63
66
  $worker: { quiesco: Lifecycle };
64
67
  $test: { app: Driver; session: Session };
@@ -78,6 +81,8 @@ export const test = base.extend<{
78
81
  try {
79
82
  await use(lifecycle);
80
83
  } finally {
84
+ await events?.close();
85
+ events = null;
81
86
  await lifecycle.afterAll();
82
87
  }
83
88
  },
@@ -85,13 +90,17 @@ export const test = base.extend<{
85
90
  ],
86
91
  session: async ({ quiesco, task, skip }, use) => {
87
92
  const t = task as unknown as FailedTask;
88
- if ((await quiesco.before(tagLevelsOf(t), fullName(t))) === 'skipped') skip('tagged for another platform');
93
+ if ((await quiesco.before(tagLevelsOf(t), fullName(t))) === 'skipped') skip(quiesco.bailedOut ?? 'tagged for another platform');
89
94
  try {
90
95
  await use(quiesco.current);
91
96
  } finally {
92
97
  const failed = t.result?.state === 'fail';
93
- const { files } = await quiesco.after({ tags: tagLevelsOf(t).flat(), failed });
98
+ const { files } = await quiesco.after({ tags: tagLevelsOf(t).flat(), failed, error: t.result?.errors?.[0] });
94
99
  if (failed) addEvidence(t, files);
100
+ if (files.length > 0) {
101
+ events ??= connectRunEvents({ runner: 'vitest' });
102
+ events.send({ type: 'test:evidence', testId: task.id, files });
103
+ }
95
104
  }
96
105
  },
97
106
  app: async ({ session }, use) => {
@@ -0,0 +1,4 @@
1
+ // `node list-main.js --out <file> [vitest arguments]`: see list.ts.
2
+ import { listMain } from './list.js';
3
+
4
+ await listMain(process.argv.slice(2));
package/src/list.ts ADDED
@@ -0,0 +1,68 @@
1
+ /**
2
+ * `node …/@quiesco/vitest/dist/list-main.js --out <file> [--config <file>] [filters…]`: lists the tests
3
+ * Vitest would run, without running them (`quiesco list`, the UI's test tree). Run in the project
4
+ * directory. Writes a TestList (JSON) to `--out`.
5
+ *
6
+ * A static parse (`parseSpecifications`): no globalSetup, setup files, module code or fixtures run
7
+ * (findings P0). `test.each` is listed once; skipped and todo tests are listed too. Ids are Vitest's own
8
+ * test ids, as the reporter sends them.
9
+ */
10
+ import fs from 'node:fs';
11
+
12
+ import type { TestList, TestRef } from '@quiesco/core';
13
+ import { createVitest } from 'vitest/node';
14
+
15
+ import { testRef } from './reporter.js';
16
+
17
+ export interface ListArgs {
18
+ out: string;
19
+ config?: string;
20
+ filters: string[];
21
+ }
22
+
23
+ export function parseListArgs(argv: readonly string[]): ListArgs {
24
+ const args: ListArgs = { out: '', filters: [] };
25
+ for (let i = 0; i < argv.length; i++) {
26
+ const a = argv[i] as string;
27
+ if (a === '--out') args.out = argv[++i] ?? '';
28
+ else if (a === '--config' || a === '-c') args.config = argv[++i] ?? '';
29
+ else if (a.startsWith('--config=')) args.config = a.slice('--config='.length);
30
+ else if (!a.startsWith('-')) args.filters.push(a);
31
+ }
32
+ return args;
33
+ }
34
+
35
+ export async function listVitestTests(args: Omit<ListArgs, 'out'>): Promise<TestList> {
36
+ const vitest = await createVitest({ ...(args.config !== undefined ? { config: args.config } : {}), watch: false, reporters: [] });
37
+ try {
38
+ const root = vitest.config.root;
39
+ const specifications = await vitest.globTestSpecifications(args.filters);
40
+ const modules = await vitest.parseSpecifications(specifications);
41
+ const tests: TestRef[] = [];
42
+ const errors: { file?: string; message: string }[] = [];
43
+ for (const m of modules) {
44
+ for (const t of m.children.allTests()) tests.push(testRef(t, root));
45
+ for (const e of m.errors()) errors.push({ file: testRefFile(root, m.moduleId), message: e.message });
46
+ }
47
+ return { runner: 'vitest', files: specifications.map((s) => testRefFile(root, s.moduleId)), tests, errors };
48
+ } finally {
49
+ await vitest.close();
50
+ }
51
+ }
52
+
53
+ function testRefFile(root: string, file: string): string {
54
+ return file.startsWith(`${root}/`) ? file.slice(root.length + 1) : file;
55
+ }
56
+
57
+ export async function listMain(argv: readonly string[]): Promise<void> {
58
+ const args = parseListArgs(argv);
59
+ let list: TestList;
60
+ try {
61
+ list = await listVitestTests(args);
62
+ } catch (e) {
63
+ list = { runner: 'vitest', files: [], tests: [], errors: [{ message: (e as Error).message }] };
64
+ }
65
+ const json = JSON.stringify(list);
66
+ if (args.out === '') process.stdout.write(`${json}\n`);
67
+ else fs.writeFileSync(args.out, json);
68
+ }
@@ -0,0 +1,138 @@
1
+ /**
2
+ * `@quiesco/vitest/reporter`: sends run events to `quiesco test` / `quiesco ui` (progress bar, test UI)
3
+ * from Vitest's main process (findings P0, vitest 5.1.0). Added to the run by `quiescoPlugin()` from
4
+ * `@quiesco/vitest/config` — the command line `--reporter` would replace the user's reporters. Without
5
+ * QUIESCO_EVENTS it does nothing.
6
+ *
7
+ * - Total: estimated at the start from a static parse of the files (nothing executes; `test.each`
8
+ * counts once), then corrected per file once Vitest has collected it.
9
+ * - Worker: the file's `concurrencyId` (1…N, the worker slot) − 1.
10
+ * - Test id: Vitest's own test id (stable across runs of the same file).
11
+ */
12
+ import path from 'node:path';
13
+
14
+ import { connectRunEvents } from '@quiesco/core';
15
+ import type { RunError, RunEventClient, TestRef } from '@quiesco/core';
16
+ import type { Reporter, SerializedError, TestCase, TestModule, TestRunEndReason, TestSpecification, Vitest } from 'vitest/node';
17
+
18
+ function relative(root: string, file: string): string {
19
+ return path.relative(root, file).split(path.sep).join('/');
20
+ }
21
+
22
+ export function testRef(test: TestCase, root: string): TestRef {
23
+ const titles = [test.name];
24
+ for (let p = test.parent; p.type === 'suite'; p = p.parent) titles.unshift(p.name);
25
+ return { id: test.id, file: relative(root, test.module.moduleId), ...(test.location !== undefined ? { line: test.location.line } : {}), name: test.name, path: titles };
26
+ }
27
+
28
+ function runError(e: { message?: string; stack?: string; diff?: string } | undefined): RunError | undefined {
29
+ if (e === undefined) return undefined;
30
+ return { message: e.message ?? 'Error', ...(e.stack !== undefined ? { stack: e.stack } : {}), ...(e.diff !== undefined ? { diff: e.diff } : {}) };
31
+ }
32
+
33
+ function countTests(m: TestModule): number {
34
+ return [...m.children.allTests()].length;
35
+ }
36
+
37
+ function worker(m: TestModule): number | undefined {
38
+ const id = m.diagnostic().concurrencyId;
39
+ return id >= 1 ? id - 1 : undefined;
40
+ }
41
+
42
+ export default class QuiescoReporter implements Reporter {
43
+ private client: RunEventClient | null = null;
44
+ private vitest: Vitest | null = null;
45
+ private root = process.cwd();
46
+ /** Tests per file: the static estimate until the file is collected. */
47
+ private readonly perFile = new Map<string, { count: number; exact: boolean }>();
48
+ private startedAt = 0;
49
+
50
+ onInit(vitest: Vitest): void {
51
+ this.vitest = vitest;
52
+ this.root = vitest.config.root;
53
+ }
54
+
55
+ /** One connection per run: closed at the run's end so its last events are flushed before Vitest exits. */
56
+ async onTestRunStart(specifications: ReadonlyArray<TestSpecification>): Promise<void> {
57
+ const client = connectRunEvents({ runner: 'vitest', ...(this.vitest !== null ? { runnerVersion: this.vitest.version } : {}) });
58
+ if (!client.enabled) return;
59
+ this.client = client;
60
+ this.startedAt = Date.now();
61
+ this.perFile.clear();
62
+ const files = [...new Set(specifications.map((s) => s.moduleId))];
63
+ let modules: TestModule[] = [];
64
+ try {
65
+ modules = this.vitest !== null ? await this.vitest.parseSpecifications([...specifications]) : [];
66
+ } catch {
67
+ // The estimate is a nicety: without it the total grows as files are collected.
68
+ }
69
+ for (const m of modules) this.perFile.set(m.moduleId, { count: countTests(m), exact: false });
70
+ const maxWorkers = this.vitest?.config.maxWorkers;
71
+ this.client.send({
72
+ type: 'run:start',
73
+ total: this.total(),
74
+ totalIsEstimate: true,
75
+ files: files.map((f) => relative(this.root, f)),
76
+ ...(typeof maxWorkers === 'number' ? { workers: maxWorkers } : {}),
77
+ });
78
+ }
79
+
80
+ onTestModuleCollected(m: TestModule): void {
81
+ if (this.client === null) return;
82
+ this.perFile.set(m.moduleId, { count: countTests(m), exact: true });
83
+ this.client.send({ type: 'total:update', total: this.total(), totalIsEstimate: [...this.perFile.values()].some((f) => !f.exact) });
84
+ }
85
+
86
+ onTestModuleStart(m: TestModule): void {
87
+ this.client?.send({ type: 'file:start', file: relative(this.root, m.moduleId) });
88
+ }
89
+
90
+ onTestModuleEnd(m: TestModule): void {
91
+ if (this.client === null) return;
92
+ const error = m.state() === 'failed' && countTests(m) === 0 ? runError(m.errors()[0]) : undefined;
93
+ this.client.send({ type: 'file:end', file: relative(this.root, m.moduleId), ...(error !== undefined ? { error } : {}) });
94
+ }
95
+
96
+ onTestCaseReady(test: TestCase): void {
97
+ if (this.client === null) return;
98
+ const w = worker(test.module);
99
+ this.client.send({ type: 'test:start', test: testRef(test, this.root), attempt: 0, startedAt: test.diagnostic()?.startTime ?? Date.now(), ...(w !== undefined ? { worker: w } : {}) });
100
+ }
101
+
102
+ onTestCaseResult(test: TestCase): void {
103
+ if (this.client === null) return;
104
+ const r = test.result();
105
+ const status = test.options.mode === 'todo' ? 'todo' : r.state === 'pending' ? 'skipped' : r.state;
106
+ const error = r.state === 'failed' ? runError(r.errors[0]) : undefined;
107
+ const logs = test.logs().map((l) => ({ stream: l.type, text: l.content }));
108
+ const w = worker(test.module);
109
+ this.client.send({
110
+ type: 'test:end',
111
+ test: testRef(test, this.root),
112
+ status,
113
+ durationMs: Math.round(test.diagnostic()?.duration ?? 0),
114
+ willRetry: false, // Vitest retries inside the test and reports once
115
+ ...(error !== undefined ? { error } : {}),
116
+ ...(logs.length > 0 ? { logs } : {}),
117
+ ...(w !== undefined ? { worker: w } : {}),
118
+ });
119
+ }
120
+
121
+ async onTestRunEnd(_modules: ReadonlyArray<TestModule>, unhandledErrors: ReadonlyArray<SerializedError>, reason: TestRunEndReason): Promise<void> {
122
+ const client = this.client;
123
+ if (client === null) return;
124
+ for (const e of unhandledErrors) {
125
+ const error = runError(e);
126
+ if (error !== undefined) client.send({ type: 'run:error', error });
127
+ }
128
+ client.send({ type: 'run:end', success: reason === 'passed', interrupted: reason === 'interrupted', durationMs: Date.now() - this.startedAt });
129
+ this.client = null;
130
+ await client.close();
131
+ }
132
+
133
+ private total(): number {
134
+ let n = 0;
135
+ for (const f of this.perFile.values()) n += f.count;
136
+ return n;
137
+ }
138
+ }