@quiesco/vitest 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +31 -2
- package/dist/config.d.ts +24 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +31 -0
- package/dist/config.js.map +1 -0
- package/dist/index.d.ts +59 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +92 -0
- package/dist/index.js.map +1 -0
- package/dist/tags.d.ts +10 -0
- package/dist/tags.d.ts.map +1 -0
- package/dist/tags.js +25 -0
- package/dist/tags.js.map +1 -0
- package/package.json +53 -3
- package/src/config.ts +43 -0
- package/src/index.ts +103 -0
- package/src/tags.ts +32 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Quiesco contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,32 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @quiesco/vitest
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Quiesco for Vitest: one session for the run, `app` as a test fixture, a reset before every test,
|
|
4
|
+
platform tags.
|
|
5
|
+
|
|
6
|
+
```sh
|
|
7
|
+
npm i -D @quiesco/vitest @quiesco/core vitest
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
```ts
|
|
11
|
+
// vitest.config.ts
|
|
12
|
+
import { quiesco } from '@quiesco/vitest/config';
|
|
13
|
+
import { defineConfig } from 'vitest/config';
|
|
14
|
+
export default defineConfig({ test: { ...quiesco(), include: ['e2e/**/*.test.ts'] } });
|
|
15
|
+
|
|
16
|
+
// e2e/todo.test.ts
|
|
17
|
+
import { test } from '@quiesco/vitest';
|
|
18
|
+
|
|
19
|
+
test('a new todo appears at the top', async ({ app }) => {
|
|
20
|
+
await app.tap('add-todo');
|
|
21
|
+
await app.expectText({ id: 'todo-item', index: 0 }, 'Buy milk');
|
|
22
|
+
});
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Run with `npx quiesco test --platform ios --runner vitest`. Details:
|
|
26
|
+
[using Quiesco without Cucumber](https://shift-14cc7601.mintlify.site/api#using-quiesco-without-cucumber).
|
|
27
|
+
|
|
28
|
+
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)).
|
|
29
|
+
|
|
30
|
+
## License
|
|
31
|
+
|
|
32
|
+
MIT
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { TagNames } from '@quiesco/core';
|
|
2
|
+
export interface QuiescoVitestOptions {
|
|
3
|
+
/** Tag names when quiesco.config renames them (`tags` there). */
|
|
4
|
+
tags?: Partial<TagNames>;
|
|
5
|
+
/** Default 300 s (the first test includes starting the session). */
|
|
6
|
+
testTimeout?: number;
|
|
7
|
+
/** Extra tags of your own to declare, e.g. `['@smoke']`. */
|
|
8
|
+
extraTags?: readonly string[];
|
|
9
|
+
/** Parallel workers, each with its own device (Phase 6.12). Default 1 (serial). */
|
|
10
|
+
workers?: number;
|
|
11
|
+
}
|
|
12
|
+
export declare function quiesco(options?: QuiescoVitestOptions): {
|
|
13
|
+
pool: "forks";
|
|
14
|
+
isolate: boolean;
|
|
15
|
+
fileParallelism: boolean;
|
|
16
|
+
maxWorkers: number;
|
|
17
|
+
testTimeout: number;
|
|
18
|
+
hookTimeout: number;
|
|
19
|
+
teardownTimeout: number;
|
|
20
|
+
tags: {
|
|
21
|
+
name: string;
|
|
22
|
+
}[];
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +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"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `test` options for Vitest (Phase 6.10):
|
|
3
|
+
*
|
|
4
|
+
* // vitest.config.ts
|
|
5
|
+
* import { defineConfig } from 'vitest/config';
|
|
6
|
+
* import { quiesco } from '@quiesco/vitest/config';
|
|
7
|
+
* export default defineConfig({ test: { ...quiesco(), include: ['e2e/**\/*.test.ts'] } });
|
|
8
|
+
*
|
|
9
|
+
* - `isolate: false`: a worker keeps its session (the device and the app) across test files (findings
|
|
10
|
+
* 6.10 batch B). `workers` (default 1) worker processes run files in parallel, each on its own device
|
|
11
|
+
* (Phase 6.12): `quiesco({ workers: 2 })`, or `--fileParallelism --maxWorkers 2` on the command line.
|
|
12
|
+
* - The platform tags are declared, so `test(name, { tags: ['@ios'] }, …)` is accepted.
|
|
13
|
+
* - `testTimeout`: the first test also waits for the session (booting a device can take minutes).
|
|
14
|
+
*/
|
|
15
|
+
import { DEFAULT_TAGS } from '@quiesco/core';
|
|
16
|
+
export function quiesco(options = {}) {
|
|
17
|
+
const names = { ...DEFAULT_TAGS, ...options.tags };
|
|
18
|
+
const declared = [...new Set([names.ios, names.android, names.web, names.native, names.hardReset, ...(options.extraTags ?? [])])];
|
|
19
|
+
return {
|
|
20
|
+
pool: 'forks',
|
|
21
|
+
isolate: false,
|
|
22
|
+
// Serial unless asked for; `vitest --fileParallelism --maxWorkers N` overrides both.
|
|
23
|
+
fileParallelism: (options.workers ?? 1) > 1,
|
|
24
|
+
maxWorkers: Math.max(1, options.workers ?? 1),
|
|
25
|
+
testTimeout: options.testTimeout ?? 300_000,
|
|
26
|
+
hookTimeout: options.testTimeout ?? 300_000,
|
|
27
|
+
teardownTimeout: 120_000,
|
|
28
|
+
tags: declared.map((name) => ({ name })),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +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"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @quiesco/vitest (Phase 6.10): Quiesco for Vitest.
|
|
3
|
+
*
|
|
4
|
+
* import { test } from '@quiesco/vitest';
|
|
5
|
+
*
|
|
6
|
+
* test('a new todo appears at the top @ios', async ({ app }) => {
|
|
7
|
+
* await app.tap('add-todo');
|
|
8
|
+
* });
|
|
9
|
+
* test('Android only', { tags: ['@android'] }, async ({ app }) => { … });
|
|
10
|
+
*
|
|
11
|
+
* - One session (device + app) per worker, as a worker fixture: with `quiesco()` from
|
|
12
|
+
* `@quiesco/vitest/config` every file runs in one worker; `quiesco({ workers: N })` runs files on N
|
|
13
|
+
* devices in parallel (Phase 6.12). Closed when the worker ends.
|
|
14
|
+
* - Before each test that uses `app` (or `session`): skipped when tagged for another platform (in its
|
|
15
|
+
* title or `{ tags }`, the innermost level decides), else the app is reset.
|
|
16
|
+
* - After a failed test: the evidence (screenshot, element tree, idle state, logs) is written to the
|
|
17
|
+
* artifacts directory and its path is added to the failure message.
|
|
18
|
+
*/
|
|
19
|
+
import { Lifecycle } from '@quiesco/core';
|
|
20
|
+
import type { Driver, Session, WorkerInfo } from '@quiesco/core';
|
|
21
|
+
import type { TaskLike } from './tags.js';
|
|
22
|
+
export { quiesco } from './config.js';
|
|
23
|
+
export type { QuiescoVitestOptions } from './config.js';
|
|
24
|
+
export { fullName, tagLevelsOf } from './tags.js';
|
|
25
|
+
export type { TaskLike } from './tags.js';
|
|
26
|
+
/**
|
|
27
|
+
* The worker this process is (Phase 6.12): VITEST_POOL_ID (1…maxWorkers) is fixed for a worker process,
|
|
28
|
+
* unlike VITEST_WORKER_ID, which changes with every file (findings 6.12). The count comes from the
|
|
29
|
+
* worker's resolved config (internal, best effort): one worker when files do not run in parallel.
|
|
30
|
+
*/
|
|
31
|
+
export declare function vitestWorker(env?: NodeJS.ProcessEnv, config?: {
|
|
32
|
+
maxWorkers?: number;
|
|
33
|
+
fileParallelism?: boolean;
|
|
34
|
+
} | undefined): WorkerInfo;
|
|
35
|
+
interface FailedTask extends TaskLike {
|
|
36
|
+
result?: {
|
|
37
|
+
state?: string;
|
|
38
|
+
errors?: {
|
|
39
|
+
message?: string;
|
|
40
|
+
stack?: string;
|
|
41
|
+
}[];
|
|
42
|
+
} | undefined;
|
|
43
|
+
}
|
|
44
|
+
/** Adds where the evidence is to the first error of a failed test (Vitest has no attachments after a test ends). */
|
|
45
|
+
export declare function addEvidence(task: FailedTask, files: readonly string[]): void;
|
|
46
|
+
export declare const test: import("vitest").TestAPI<{
|
|
47
|
+
app: Driver;
|
|
48
|
+
session: Session;
|
|
49
|
+
} & {
|
|
50
|
+
quiesco: Lifecycle;
|
|
51
|
+
} & object>;
|
|
52
|
+
export declare const it: import("vitest").TestAPI<{
|
|
53
|
+
app: Driver;
|
|
54
|
+
session: Session;
|
|
55
|
+
} & {
|
|
56
|
+
quiesco: Lifecycle;
|
|
57
|
+
} & object>;
|
|
58
|
+
export { describe, expect } from 'vitest';
|
|
59
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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,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;AAKD,eAAO,MAAM,IAAI;SAED,MAAM;aAAW,OAAO;;aADlB,SAAS;WAqC7B,CAAC;AAEH,eAAO,MAAM,EAAE;SAtCC,MAAM;aAAW,OAAO;;aADlB,SAAS;WAuCT,CAAC;AACvB,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @quiesco/vitest (Phase 6.10): Quiesco for Vitest.
|
|
3
|
+
*
|
|
4
|
+
* import { test } from '@quiesco/vitest';
|
|
5
|
+
*
|
|
6
|
+
* test('a new todo appears at the top @ios', async ({ app }) => {
|
|
7
|
+
* await app.tap('add-todo');
|
|
8
|
+
* });
|
|
9
|
+
* test('Android only', { tags: ['@android'] }, async ({ app }) => { … });
|
|
10
|
+
*
|
|
11
|
+
* - One session (device + app) per worker, as a worker fixture: with `quiesco()` from
|
|
12
|
+
* `@quiesco/vitest/config` every file runs in one worker; `quiesco({ workers: N })` runs files on N
|
|
13
|
+
* devices in parallel (Phase 6.12). Closed when the worker ends.
|
|
14
|
+
* - Before each test that uses `app` (or `session`): skipped when tagged for another platform (in its
|
|
15
|
+
* title or `{ tags }`, the innermost level decides), else the app is reset.
|
|
16
|
+
* - After a failed test: the evidence (screenshot, element tree, idle state, logs) is written to the
|
|
17
|
+
* artifacts directory and its path is added to the failure message.
|
|
18
|
+
*/
|
|
19
|
+
import { Lifecycle } from '@quiesco/core';
|
|
20
|
+
import { test as base } from 'vitest';
|
|
21
|
+
import { fullName, tagLevelsOf } from './tags.js';
|
|
22
|
+
export { quiesco } from './config.js';
|
|
23
|
+
export { fullName, tagLevelsOf } from './tags.js';
|
|
24
|
+
/**
|
|
25
|
+
* The worker this process is (Phase 6.12): VITEST_POOL_ID (1…maxWorkers) is fixed for a worker process,
|
|
26
|
+
* unlike VITEST_WORKER_ID, which changes with every file (findings 6.12). The count comes from the
|
|
27
|
+
* worker's resolved config (internal, best effort): one worker when files do not run in parallel.
|
|
28
|
+
*/
|
|
29
|
+
export function vitestWorker(env = process.env, config = globalThis.__vitest_worker__?.config) {
|
|
30
|
+
const count = config?.fileParallelism === false || config?.maxWorkers === undefined ? 1 : Math.max(1, config.maxWorkers);
|
|
31
|
+
const id = Number.parseInt(env['VITEST_POOL_ID'] ?? '', 10);
|
|
32
|
+
if (count === 1 || !(id >= 1))
|
|
33
|
+
return { index: 0, count };
|
|
34
|
+
return { index: Math.min(id, count) - 1, count };
|
|
35
|
+
}
|
|
36
|
+
/** Adds where the evidence is to the first error of a failed test (Vitest has no attachments after a test ends). */
|
|
37
|
+
export function addEvidence(task, files) {
|
|
38
|
+
const err = task.result?.errors?.[0];
|
|
39
|
+
if (err === undefined || files.length === 0)
|
|
40
|
+
return;
|
|
41
|
+
const note = `\n\nQuiesco evidence:\n${files.map((f) => ` ${f}`).join('\n')}`;
|
|
42
|
+
err.message = `${err.message ?? ''}${note}`;
|
|
43
|
+
if (typeof err.stack === 'string')
|
|
44
|
+
err.stack = err.stack.replace(/\n|$/, `${note}\n`);
|
|
45
|
+
}
|
|
46
|
+
/** A session that failed to start fails the remaining tests at once instead of starting again for each. */
|
|
47
|
+
let startFailure = null;
|
|
48
|
+
export const test = base.extend({
|
|
49
|
+
quiesco: [
|
|
50
|
+
// Vitest reads a fixture's dependencies from the destructuring pattern: it must be `{}` here.
|
|
51
|
+
// eslint-disable-next-line no-empty-pattern
|
|
52
|
+
async ({}, use) => {
|
|
53
|
+
if (startFailure !== null)
|
|
54
|
+
throw startFailure;
|
|
55
|
+
const lifecycle = new Lifecycle({ worker: vitestWorker() });
|
|
56
|
+
try {
|
|
57
|
+
await lifecycle.beforeAll();
|
|
58
|
+
}
|
|
59
|
+
catch (e) {
|
|
60
|
+
startFailure = e;
|
|
61
|
+
throw e;
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
await use(lifecycle);
|
|
65
|
+
}
|
|
66
|
+
finally {
|
|
67
|
+
await lifecycle.afterAll();
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
{ scope: 'worker' },
|
|
71
|
+
],
|
|
72
|
+
session: async ({ quiesco, task, skip }, use) => {
|
|
73
|
+
const t = task;
|
|
74
|
+
if ((await quiesco.before(tagLevelsOf(t), fullName(t))) === 'skipped')
|
|
75
|
+
skip('tagged for another platform');
|
|
76
|
+
try {
|
|
77
|
+
await use(quiesco.current);
|
|
78
|
+
}
|
|
79
|
+
finally {
|
|
80
|
+
const failed = t.result?.state === 'fail';
|
|
81
|
+
const { files } = await quiesco.after({ tags: tagLevelsOf(t).flat(), failed });
|
|
82
|
+
if (failed)
|
|
83
|
+
addEvidence(t, files);
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
app: async ({ session }, use) => {
|
|
87
|
+
await use(session.driver);
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
export const it = test;
|
|
91
|
+
export { describe, expect } from 'vitest';
|
|
92
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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;;;;GA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AC,CAAC,MAAM,EAAE,KAAK,KAAK,MAAM,CAAC;YAC1C,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;YAC/E,IAAI,MAAM;gBAAE,WAAW,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;QACpC,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"}
|
package/dist/tags.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** The parts of a Vitest task used here (structural: no vitest import, unit-testable). */
|
|
2
|
+
export interface TaskLike {
|
|
3
|
+
name: string;
|
|
4
|
+
tags?: readonly string[] | undefined;
|
|
5
|
+
suite?: TaskLike | undefined;
|
|
6
|
+
}
|
|
7
|
+
export declare function tagLevelsOf(task: TaskLike): string[][];
|
|
8
|
+
/** "suite > nested > test": the name of the test's artifacts directory. */
|
|
9
|
+
export declare function fullName(task: TaskLike): string;
|
|
10
|
+
//# sourceMappingURL=tags.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tags.d.ts","sourceRoot":"","sources":["../src/tags.ts"],"names":[],"mappings":"AAOA,0FAA0F;AAC1F,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,CAAC;IACrC,KAAK,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAC;CAC9B;AAQD,wBAAgB,WAAW,CAAC,IAAI,EAAE,QAAQ,GAAG,MAAM,EAAE,EAAE,CAItD;AAED,2EAA2E;AAC3E,wBAAgB,QAAQ,CAAC,IAAI,EAAE,QAAQ,GAAG,MAAM,CAI/C"}
|
package/dist/tags.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tags of a Vitest test grouped by level, outermost suite first (Phase 6.10): each level is the tags in
|
|
3
|
+
* that suite's or test's title plus its own `{ tags }` (Vitest reports inherited tags merged, so a
|
|
4
|
+
* level's own tags are its tags minus its parent's). The innermost level with a platform tag decides.
|
|
5
|
+
*/
|
|
6
|
+
import { titleTags } from '@quiesco/core';
|
|
7
|
+
function own(node, parent) {
|
|
8
|
+
const inherited = new Set(parent?.tags ?? []);
|
|
9
|
+
const native = (node.tags ?? []).filter((t) => !inherited.has(t));
|
|
10
|
+
return [...new Set([...titleTags(node.name), ...native])];
|
|
11
|
+
}
|
|
12
|
+
export function tagLevelsOf(task) {
|
|
13
|
+
const chain = [];
|
|
14
|
+
for (let n = task; n !== undefined; n = n.suite)
|
|
15
|
+
chain.unshift(n);
|
|
16
|
+
return chain.map((n, i) => own(n, chain[i - 1]));
|
|
17
|
+
}
|
|
18
|
+
/** "suite > nested > test": the name of the test's artifacts directory. */
|
|
19
|
+
export function fullName(task) {
|
|
20
|
+
const names = [];
|
|
21
|
+
for (let n = task; n !== undefined; n = n.suite)
|
|
22
|
+
names.unshift(n.name);
|
|
23
|
+
return names.join(' > ');
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=tags.js.map
|
package/dist/tags.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tags.js","sourceRoot":"","sources":["../src/tags.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAS1C,SAAS,GAAG,CAAC,IAAc,EAAE,MAA4B;IACvD,MAAM,SAAS,GAAG,I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1.0",
|
|
4
|
+
"description": "Quiesco for Vitest: one session for the run, `app` as a test fixture, a reset before every test",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "h2nology",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"quiesco",
|
|
9
|
+
"e2e",
|
|
10
|
+
"testing",
|
|
11
|
+
"expo",
|
|
12
|
+
"react-native",
|
|
13
|
+
"vitest"
|
|
14
|
+
],
|
|
15
|
+
"homepage": "https://github.com/h2nology/quiesco/tree/main/packages/vitest#readme",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/h2nology/quiesco.git",
|
|
19
|
+
"directory": "packages/vitest"
|
|
20
|
+
},
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/h2nology/quiesco/issues"
|
|
23
|
+
},
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=24"
|
|
26
|
+
},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
30
|
+
"type": "module",
|
|
31
|
+
"main": "./dist/index.js",
|
|
32
|
+
"exports": {
|
|
33
|
+
".": {
|
|
34
|
+
"types": "./dist/index.d.ts",
|
|
35
|
+
"import": "./dist/index.js"
|
|
36
|
+
},
|
|
37
|
+
"./config": {
|
|
38
|
+
"types": "./dist/config.d.ts",
|
|
39
|
+
"import": "./dist/config.js"
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"files": [
|
|
43
|
+
"dist",
|
|
44
|
+
"src"
|
|
45
|
+
],
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@quiesco/core": "0.1.0"
|
|
48
|
+
},
|
|
49
|
+
"peerDependencies": {
|
|
50
|
+
"vitest": ">=5.1"
|
|
51
|
+
},
|
|
52
|
+
"scripts": {
|
|
53
|
+
"build": "tsc -b",
|
|
54
|
+
"test": "vitest run"
|
|
55
|
+
}
|
|
6
56
|
}
|
package/src/config.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `test` options for Vitest (Phase 6.10):
|
|
3
|
+
*
|
|
4
|
+
* // vitest.config.ts
|
|
5
|
+
* import { defineConfig } from 'vitest/config';
|
|
6
|
+
* import { quiesco } from '@quiesco/vitest/config';
|
|
7
|
+
* export default defineConfig({ test: { ...quiesco(), include: ['e2e/**\/*.test.ts'] } });
|
|
8
|
+
*
|
|
9
|
+
* - `isolate: false`: a worker keeps its session (the device and the app) across test files (findings
|
|
10
|
+
* 6.10 batch B). `workers` (default 1) worker processes run files in parallel, each on its own device
|
|
11
|
+
* (Phase 6.12): `quiesco({ workers: 2 })`, or `--fileParallelism --maxWorkers 2` on the command line.
|
|
12
|
+
* - The platform tags are declared, so `test(name, { tags: ['@ios'] }, …)` is accepted.
|
|
13
|
+
* - `testTimeout`: the first test also waits for the session (booting a device can take minutes).
|
|
14
|
+
*/
|
|
15
|
+
import { DEFAULT_TAGS } from '@quiesco/core';
|
|
16
|
+
import type { TagNames } from '@quiesco/core';
|
|
17
|
+
|
|
18
|
+
export interface QuiescoVitestOptions {
|
|
19
|
+
/** Tag names when quiesco.config renames them (`tags` there). */
|
|
20
|
+
tags?: Partial<TagNames>;
|
|
21
|
+
/** Default 300 s (the first test includes starting the session). */
|
|
22
|
+
testTimeout?: number;
|
|
23
|
+
/** Extra tags of your own to declare, e.g. `['@smoke']`. */
|
|
24
|
+
extraTags?: readonly string[];
|
|
25
|
+
/** Parallel workers, each with its own device (Phase 6.12). Default 1 (serial). */
|
|
26
|
+
workers?: number;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function quiesco(options: QuiescoVitestOptions = {}) {
|
|
30
|
+
const names = { ...DEFAULT_TAGS, ...options.tags };
|
|
31
|
+
const declared = [...new Set([names.ios, names.android, names.web, names.native, names.hardReset, ...(options.extraTags ?? [])])];
|
|
32
|
+
return {
|
|
33
|
+
pool: 'forks' as const,
|
|
34
|
+
isolate: false,
|
|
35
|
+
// Serial unless asked for; `vitest --fileParallelism --maxWorkers N` overrides both.
|
|
36
|
+
fileParallelism: (options.workers ?? 1) > 1,
|
|
37
|
+
maxWorkers: Math.max(1, options.workers ?? 1),
|
|
38
|
+
testTimeout: options.testTimeout ?? 300_000,
|
|
39
|
+
hookTimeout: options.testTimeout ?? 300_000,
|
|
40
|
+
teardownTimeout: 120_000,
|
|
41
|
+
tags: declared.map((name) => ({ name })),
|
|
42
|
+
};
|
|
43
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @quiesco/vitest (Phase 6.10): Quiesco for Vitest.
|
|
3
|
+
*
|
|
4
|
+
* import { test } from '@quiesco/vitest';
|
|
5
|
+
*
|
|
6
|
+
* test('a new todo appears at the top @ios', async ({ app }) => {
|
|
7
|
+
* await app.tap('add-todo');
|
|
8
|
+
* });
|
|
9
|
+
* test('Android only', { tags: ['@android'] }, async ({ app }) => { … });
|
|
10
|
+
*
|
|
11
|
+
* - One session (device + app) per worker, as a worker fixture: with `quiesco()` from
|
|
12
|
+
* `@quiesco/vitest/config` every file runs in one worker; `quiesco({ workers: N })` runs files on N
|
|
13
|
+
* devices in parallel (Phase 6.12). Closed when the worker ends.
|
|
14
|
+
* - Before each test that uses `app` (or `session`): skipped when tagged for another platform (in its
|
|
15
|
+
* title or `{ tags }`, the innermost level decides), else the app is reset.
|
|
16
|
+
* - After a failed test: the evidence (screenshot, element tree, idle state, logs) is written to the
|
|
17
|
+
* artifacts directory and its path is added to the failure message.
|
|
18
|
+
*/
|
|
19
|
+
import { Lifecycle } from '@quiesco/core';
|
|
20
|
+
import type { Driver, Session, WorkerInfo } from '@quiesco/core';
|
|
21
|
+
import { test as base } from 'vitest';
|
|
22
|
+
|
|
23
|
+
import { fullName, tagLevelsOf } from './tags.js';
|
|
24
|
+
import type { TaskLike } from './tags.js';
|
|
25
|
+
|
|
26
|
+
export { quiesco } from './config.js';
|
|
27
|
+
export type { QuiescoVitestOptions } from './config.js';
|
|
28
|
+
export { fullName, tagLevelsOf } from './tags.js';
|
|
29
|
+
export type { TaskLike } from './tags.js';
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The worker this process is (Phase 6.12): VITEST_POOL_ID (1…maxWorkers) is fixed for a worker process,
|
|
33
|
+
* unlike VITEST_WORKER_ID, which changes with every file (findings 6.12). The count comes from the
|
|
34
|
+
* worker's resolved config (internal, best effort): one worker when files do not run in parallel.
|
|
35
|
+
*/
|
|
36
|
+
export function vitestWorker(
|
|
37
|
+
env: NodeJS.ProcessEnv = process.env,
|
|
38
|
+
config: { maxWorkers?: number; fileParallelism?: boolean } | undefined = (globalThis as { __vitest_worker__?: { config?: { maxWorkers?: number; fileParallelism?: boolean } } }).__vitest_worker__?.config,
|
|
39
|
+
): WorkerInfo {
|
|
40
|
+
const count = config?.fileParallelism === false || config?.maxWorkers === undefined ? 1 : Math.max(1, config.maxWorkers);
|
|
41
|
+
const id = Number.parseInt(env['VITEST_POOL_ID'] ?? '', 10);
|
|
42
|
+
if (count === 1 || !(id >= 1)) return { index: 0, count };
|
|
43
|
+
return { index: Math.min(id, count) - 1, count };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
interface FailedTask extends TaskLike {
|
|
47
|
+
result?: { state?: string; errors?: { message?: string; stack?: string }[] } | undefined;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Adds where the evidence is to the first error of a failed test (Vitest has no attachments after a test ends). */
|
|
51
|
+
export function addEvidence(task: FailedTask, files: readonly string[]): void {
|
|
52
|
+
const err = task.result?.errors?.[0];
|
|
53
|
+
if (err === undefined || files.length === 0) return;
|
|
54
|
+
const note = `\n\nQuiesco evidence:\n${files.map((f) => ` ${f}`).join('\n')}`;
|
|
55
|
+
err.message = `${err.message ?? ''}${note}`;
|
|
56
|
+
if (typeof err.stack === 'string') err.stack = err.stack.replace(/\n|$/, `${note}\n`);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** A session that failed to start fails the remaining tests at once instead of starting again for each. */
|
|
60
|
+
let startFailure: unknown = null;
|
|
61
|
+
|
|
62
|
+
export const test = base.extend<{
|
|
63
|
+
$worker: { quiesco: Lifecycle };
|
|
64
|
+
$test: { app: Driver; session: Session };
|
|
65
|
+
}>({
|
|
66
|
+
quiesco: [
|
|
67
|
+
// Vitest reads a fixture's dependencies from the destructuring pattern: it must be `{}` here.
|
|
68
|
+
// eslint-disable-next-line no-empty-pattern
|
|
69
|
+
async ({}, use) => {
|
|
70
|
+
if (startFailure !== null) throw startFailure;
|
|
71
|
+
const lifecycle = new Lifecycle({ worker: vitestWorker() });
|
|
72
|
+
try {
|
|
73
|
+
await lifecycle.beforeAll();
|
|
74
|
+
} catch (e) {
|
|
75
|
+
startFailure = e;
|
|
76
|
+
throw e;
|
|
77
|
+
}
|
|
78
|
+
try {
|
|
79
|
+
await use(lifecycle);
|
|
80
|
+
} finally {
|
|
81
|
+
await lifecycle.afterAll();
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
{ scope: 'worker' },
|
|
85
|
+
],
|
|
86
|
+
session: async ({ quiesco, task, skip }, use) => {
|
|
87
|
+
const t = task as unknown as FailedTask;
|
|
88
|
+
if ((await quiesco.before(tagLevelsOf(t), fullName(t))) === 'skipped') skip('tagged for another platform');
|
|
89
|
+
try {
|
|
90
|
+
await use(quiesco.current);
|
|
91
|
+
} finally {
|
|
92
|
+
const failed = t.result?.state === 'fail';
|
|
93
|
+
const { files } = await quiesco.after({ tags: tagLevelsOf(t).flat(), failed });
|
|
94
|
+
if (failed) addEvidence(t, files);
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
app: async ({ session }, use) => {
|
|
98
|
+
await use(session.driver);
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
export const it = test;
|
|
103
|
+
export { describe, expect } from 'vitest';
|
package/src/tags.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tags of a Vitest test grouped by level, outermost suite first (Phase 6.10): each level is the tags in
|
|
3
|
+
* that suite's or test's title plus its own `{ tags }` (Vitest reports inherited tags merged, so a
|
|
4
|
+
* level's own tags are its tags minus its parent's). The innermost level with a platform tag decides.
|
|
5
|
+
*/
|
|
6
|
+
import { titleTags } from '@quiesco/core';
|
|
7
|
+
|
|
8
|
+
/** The parts of a Vitest task used here (structural: no vitest import, unit-testable). */
|
|
9
|
+
export interface TaskLike {
|
|
10
|
+
name: string;
|
|
11
|
+
tags?: readonly string[] | undefined;
|
|
12
|
+
suite?: TaskLike | undefined;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function own(node: TaskLike, parent: TaskLike | undefined): string[] {
|
|
16
|
+
const inherited = new Set(parent?.tags ?? []);
|
|
17
|
+
const native = (node.tags ?? []).filter((t) => !inherited.has(t));
|
|
18
|
+
return [...new Set([...titleTags(node.name), ...native])];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function tagLevelsOf(task: TaskLike): string[][] {
|
|
22
|
+
const chain: TaskLike[] = [];
|
|
23
|
+
for (let n: TaskLike | undefined = task; n !== undefined; n = n.suite) chain.unshift(n);
|
|
24
|
+
return chain.map((n, i) => own(n, chain[i - 1]));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** "suite > nested > test": the name of the test's artifacts directory. */
|
|
28
|
+
export function fullName(task: TaskLike): string {
|
|
29
|
+
const names: string[] = [];
|
|
30
|
+
for (let n: TaskLike | undefined = task; n !== undefined; n = n.suite) names.unshift(n.name);
|
|
31
|
+
return names.join(' > ');
|
|
32
|
+
}
|