@quiesco/cucumber 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/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/lifecycle.d.ts +45 -0
- package/dist/lifecycle.d.ts.map +1 -0
- package/dist/lifecycle.js +50 -0
- package/dist/lifecycle.js.map +1 -0
- package/dist/register-hooks.d.ts +19 -0
- package/dist/register-hooks.d.ts.map +1 -0
- package/dist/register-hooks.js +25 -0
- package/dist/register-hooks.js.map +1 -0
- package/dist/register.d.ts +2 -0
- package/dist/register.d.ts.map +1 -0
- package/dist/register.js +4 -0
- package/dist/register.js.map +1 -0
- package/dist/world.d.ts +16 -0
- package/dist/world.d.ts.map +1 -0
- package/dist/world.js +24 -0
- package/dist/world.js.map +1 -0
- package/package.json +59 -3
- package/src/index.ts +5 -0
- package/src/lifecycle.ts +69 -0
- package/src/register-hooks.ts +40 -0
- package/src/register.ts +4 -0
- package/src/world.ts +31 -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/cucumber
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
cucumber-js World and hooks for Quiesco: one session for the run, a reset before every scenario,
|
|
4
|
+
`this.app` in step definitions, platform tags (`@ios`, `@android`, `@web`, `@native`) and evidence
|
|
5
|
+
(screenshot, element tree, idle state) attached to failed scenarios.
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm i -D @quiesco/cucumber @cucumber/cucumber
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
// features/support/quiesco.ts
|
|
13
|
+
import '@quiesco/cucumber/register';
|
|
14
|
+
|
|
15
|
+
// features/step_definitions/todo.steps.ts
|
|
16
|
+
import { When } from '@cucumber/cucumber';
|
|
17
|
+
import type { QuiescoWorld } from '@quiesco/cucumber';
|
|
18
|
+
|
|
19
|
+
When('they add a todo {string}', async function (this: QuiescoWorld, title: string) {
|
|
20
|
+
await this.app.tap('add-todo'); // waits until the app is idle, then taps
|
|
21
|
+
await this.app.type('todo-title', title);
|
|
22
|
+
});
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Run with `npx quiesco test --platform ios|android|web`. [API reference](https://shift-14cc7601.mintlify.site/api),
|
|
26
|
+
[driver pattern](https://shift-14cc7601.mintlify.site/driver-pattern), [parallel runs](https://shift-14cc7601.mintlify.site/parallel).
|
|
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/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { registerQuiesco } from './register-hooks.js';
|
|
2
|
+
export type { RegisterOptions } from './register-hooks.js';
|
|
3
|
+
export { QuiescoWorld } from './world.js';
|
|
4
|
+
export { Lifecycle, tagLevels } from './lifecycle.js';
|
|
5
|
+
export type { Attachment, LifecycleOptions, ScenarioResult } from './lifecycle.js';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,YAAY,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACtD,YAAY,EAAE,UAAU,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* cucumber-js on top of core's runner-independent Lifecycle (requirements.md §6.10): Gherkin tag levels
|
|
3
|
+
* and `--parallel` workers (Phase 6.12). Kept free of cucumber imports so it can be unit-tested.
|
|
4
|
+
*/
|
|
5
|
+
import { Lifecycle as CoreLifecycle } from '@quiesco/core';
|
|
6
|
+
import type { LifecycleOptions as CoreOptions, WorkerInfo } from '@quiesco/core';
|
|
7
|
+
export type { Attachment, ScenarioResult } from '@quiesco/core';
|
|
8
|
+
export type LifecycleOptions = CoreOptions;
|
|
9
|
+
interface TaggedNode {
|
|
10
|
+
tags: readonly {
|
|
11
|
+
id: string;
|
|
12
|
+
}[];
|
|
13
|
+
}
|
|
14
|
+
interface ScenarioNode extends TaggedNode {
|
|
15
|
+
examples: readonly TaggedNode[];
|
|
16
|
+
}
|
|
17
|
+
interface FeatureChild {
|
|
18
|
+
rule?: TaggedNode & {
|
|
19
|
+
children: readonly FeatureChild[];
|
|
20
|
+
};
|
|
21
|
+
scenario?: ScenarioNode;
|
|
22
|
+
}
|
|
23
|
+
/** The parts of a cucumber-js GherkinDocument needed to place tags (structural, no cucumber import). */
|
|
24
|
+
export interface TagSource {
|
|
25
|
+
feature?: (TaggedNode & {
|
|
26
|
+
children: readonly FeatureChild[];
|
|
27
|
+
}) | undefined;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* A pickle's tags grouped by Gherkin level: [feature, rule, scenario, examples]. Tags whose node is
|
|
31
|
+
* not found count as scenario tags.
|
|
32
|
+
*/
|
|
33
|
+
export declare function tagLevels(pickleTags: readonly {
|
|
34
|
+
name: string;
|
|
35
|
+
astNodeId: string;
|
|
36
|
+
}[], doc: TagSource): string[][];
|
|
37
|
+
/**
|
|
38
|
+
* The worker this thread is: cucumber-js `--parallel N` runs N worker threads and sets
|
|
39
|
+
* CUCUMBER_WORKER_ID ("0"…) and CUCUMBER_TOTAL_WORKERS in each one's environment (findings 4.6).
|
|
40
|
+
*/
|
|
41
|
+
export declare function cucumberWorker(env: NodeJS.ProcessEnv): WorkerInfo;
|
|
42
|
+
export declare class Lifecycle extends CoreLifecycle {
|
|
43
|
+
constructor(options?: LifecycleOptions);
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=lifecycle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifecycle.d.ts","sourceRoot":"","sources":["../src/lifecycle.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,SAAS,IAAI,aAAa,EAAE,MAAM,eAAe,CAAC;AAC3D,OAAO,KAAK,EAAE,gBAAgB,IAAI,WAAW,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEjF,YAAY,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAChE,MAAM,MAAM,gBAAgB,GAAG,WAAW,CAAC;AAE3C,UAAU,UAAU;IAClB,IAAI,EAAE,SAAS;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CACjC;AACD,UAAU,YAAa,SAAQ,UAAU;IACvC,QAAQ,EAAE,SAAS,UAAU,EAAE,CAAC;CACjC;AACD,UAAU,YAAY;IACpB,IAAI,CAAC,EAAE,UAAU,GAAG;QAAE,QAAQ,EAAE,SAAS,YAAY,EAAE,CAAA;KAAE,CAAC;IAC1D,QAAQ,CAAC,EAAE,YAAY,CAAC;CACzB;AACD,wGAAwG;AACxG,MAAM,WAAW,SAAS;IACxB,OAAO,CAAC,EAAE,CAAC,UAAU,GAAG;QAAE,QAAQ,EAAE,SAAS,YAAY,EAAE,CAAA;KAAE,CAAC,GAAG,SAAS,CAAC;CAC5E;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,UAAU,EAAE,SAAS;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,EAAE,EAAE,GAAG,EAAE,SAAS,GAAG,MAAM,EAAE,EAAE,CAsBhH;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,CAAC,UAAU,GAAG,UAAU,CAKjE;AAED,qBAAa,SAAU,SAAQ,aAAa;gBAC9B,OAAO,GAAE,gBAAqB;CAG3C"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* cucumber-js on top of core's runner-independent Lifecycle (requirements.md §6.10): Gherkin tag levels
|
|
3
|
+
* and `--parallel` workers (Phase 6.12). Kept free of cucumber imports so it can be unit-tested.
|
|
4
|
+
*/
|
|
5
|
+
import { Lifecycle as CoreLifecycle } from '@quiesco/core';
|
|
6
|
+
/**
|
|
7
|
+
* A pickle's tags grouped by Gherkin level: [feature, rule, scenario, examples]. Tags whose node is
|
|
8
|
+
* not found count as scenario tags.
|
|
9
|
+
*/
|
|
10
|
+
export function tagLevels(pickleTags, doc) {
|
|
11
|
+
const level = new Map();
|
|
12
|
+
const mark = (node, l) => node.tags.forEach((t) => level.set(t.id, l));
|
|
13
|
+
const walk = (children) => {
|
|
14
|
+
for (const c of children) {
|
|
15
|
+
if (c.rule !== undefined) {
|
|
16
|
+
mark(c.rule, 1);
|
|
17
|
+
walk(c.rule.children);
|
|
18
|
+
}
|
|
19
|
+
if (c.scenario !== undefined) {
|
|
20
|
+
mark(c.scenario, 2);
|
|
21
|
+
c.scenario.examples.forEach((e) => mark(e, 3));
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
if (doc.feature !== undefined) {
|
|
26
|
+
mark(doc.feature, 0);
|
|
27
|
+
walk(doc.feature.children);
|
|
28
|
+
}
|
|
29
|
+
const out = [[], [], [], []];
|
|
30
|
+
for (const t of pickleTags)
|
|
31
|
+
out[level.get(t.astNodeId) ?? 2]?.push(t.name);
|
|
32
|
+
return out;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The worker this thread is: cucumber-js `--parallel N` runs N worker threads and sets
|
|
36
|
+
* CUCUMBER_WORKER_ID ("0"…) and CUCUMBER_TOTAL_WORKERS in each one's environment (findings 4.6).
|
|
37
|
+
*/
|
|
38
|
+
export function cucumberWorker(env) {
|
|
39
|
+
const count = Number.parseInt(env['CUCUMBER_TOTAL_WORKERS'] ?? '', 10);
|
|
40
|
+
const index = Number.parseInt(env['CUCUMBER_WORKER_ID'] ?? '', 10);
|
|
41
|
+
if (!(count > 1) || !(index >= 0))
|
|
42
|
+
return { index: 0, count: 1 };
|
|
43
|
+
return { index, count };
|
|
44
|
+
}
|
|
45
|
+
export class Lifecycle extends CoreLifecycle {
|
|
46
|
+
constructor(options = {}) {
|
|
47
|
+
super({ worker: cucumberWorker(options.env ?? process.env), ...options });
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=lifecycle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifecycle.js","sourceRoot":"","sources":["../src/lifecycle.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,SAAS,IAAI,aAAa,EAAE,MAAM,eAAe,CAAC;AAqB3D;;;GAGG;AACH,MAAM,UAAU,SAAS,CAAC,UAA0D,EAAE,GAAc;IAClG,MAAM,KAAK,GAAG,IAAI,GAAG,EAAkB,CAAC;IACxC,MAAM,IAAI,GAAG,CAAC,IAAgB,EAAE,CAAS,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;IAC3F,MAAM,IAAI,GAAG,CAAC,QAAiC,EAAE,EAAE;QACjD,KAAK,MAAM,CAAC,IAAI,QAAQ,EAAE,CAAC;YACzB,IAAI,CAAC,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;gBACzB,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;gBAChB,IAAI,CAAC,CAAC,CAAC,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AAC,EAAE,CAAC;IACjE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;AAC1B,CAAC;AAED,MAAM,OAAO,SAAU,SAAQ,aAAa;IAC1C,YAAY,UAA4B,EAAE;QACxC,KAAK,CAAC,EAAE,MAAM,EAAE,cAAc,CAAC,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;IAC5E,CAAC;CACF"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Lifecycle } from './lifecycle.js';
|
|
2
|
+
import type { LifecycleOptions } from './lifecycle.js';
|
|
3
|
+
import { QuiescoWorld } from './world.js';
|
|
4
|
+
export interface RegisterOptions extends LifecycleOptions {
|
|
5
|
+
/** Use your own World (must extend QuiescoWorld). Default QuiescoWorld. */
|
|
6
|
+
world?: typeof QuiescoWorld;
|
|
7
|
+
/** Default step timeout. Each driver call has its own sync timeout; this caps a whole step. Default 60 s. */
|
|
8
|
+
stepTimeoutMs?: number;
|
|
9
|
+
/** BeforeAll timeout: booting an emulator can take minutes. Default 10 min. */
|
|
10
|
+
setupTimeoutMs?: number;
|
|
11
|
+
/**
|
|
12
|
+
* Timeout of the per-scenario reset (Before). It can start the app again when it is gone, which waits up to
|
|
13
|
+
* 3 × the connect timeout. Default 3 min.
|
|
14
|
+
*/
|
|
15
|
+
resetTimeoutMs?: number;
|
|
16
|
+
}
|
|
17
|
+
/** Register the World and the lifecycle hooks with cucumber-js. Call once, from a support file. */
|
|
18
|
+
export declare function registerQuiesco(options?: RegisterOptions): Lifecycle;
|
|
19
|
+
//# sourceMappingURL=register-hooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register-hooks.d.ts","sourceRoot":"","sources":["../src/register-hooks.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAa,MAAM,gBAAgB,CAAC;AACtD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAiB,MAAM,YAAY,CAAC;AAEzD,MAAM,WAAW,eAAgB,SAAQ,gBAAgB;IACvD,2EAA2E;IAC3E,KAAK,CAAC,EAAE,OAAO,YAAY,CAAC;IAC5B,6GAA6G;IAC7G,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,+EAA+E;IAC/E,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,mGAAmG;AACnG,wBAAgB,eAAe,CAAC,OAAO,GAAE,eAAoB,GAAG,SAAS,CAkBxE"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { After, AfterAll, Before, BeforeAll, Status, setDefaultTimeout, setWorldConstructor } from '@cucumber/cucumber';
|
|
2
|
+
import { Lifecycle, tagLevels } from './lifecycle.js';
|
|
3
|
+
import { QuiescoWorld, bindLifecycle } from './world.js';
|
|
4
|
+
/** Register the World and the lifecycle hooks with cucumber-js. Call once, from a support file. */
|
|
5
|
+
export function registerQuiesco(options = {}) {
|
|
6
|
+
const lifecycle = new Lifecycle(options);
|
|
7
|
+
bindLifecycle(lifecycle);
|
|
8
|
+
setWorldConstructor(options.world ?? QuiescoWorld);
|
|
9
|
+
setDefaultTimeout(options.stepTimeoutMs ?? 60_000);
|
|
10
|
+
BeforeAll({ name: 'quiesco: start session', timeout: options.setupTimeoutMs ?? 600_000 }, () => lifecycle.beforeAll());
|
|
11
|
+
Before({ name: 'quiesco: reset app', timeout: options.resetTimeoutMs ?? 180_000 }, ({ pickle, gherkinDocument }) => lifecycle.before(tagLevels(pickle.tags, gherkinDocument), pickle.name));
|
|
12
|
+
After({ name: 'quiesco: evidence' }, async function ({ pickle, result }) {
|
|
13
|
+
const failed = result !== undefined && result.status !== Status.PASSED && result.status !== Status.SKIPPED;
|
|
14
|
+
for (const a of (await lifecycle.after({ tags: pickle.tags.map((t) => t.name), failed })).attachments) {
|
|
15
|
+
const opts = a.fileName !== undefined ? { mediaType: a.mediaType, fileName: a.fileName } : { mediaType: a.mediaType };
|
|
16
|
+
if (typeof a.data === 'string')
|
|
17
|
+
this.attach(a.data, opts);
|
|
18
|
+
else
|
|
19
|
+
this.attach(a.data, opts);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
AfterAll({ name: 'quiesco: stop session', timeout: 120_000 }, () => lifecycle.afterAll());
|
|
23
|
+
return lifecycle;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=register-hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register-hooks.js","sourceRoot":"","sources":["../src/register-hooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAExH,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEtD,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAgBzD,mGAAmG;AACnG,MAAM,UAAU,eAAe,CAAC,UAA2B,EAAE;IAC3D,MAAM,SAAS,GAAG,IAAI,SAAS,CAAC,OAAO,CAAC,CAAC;IACzC,aAAa,CAAC,SAAS,CAAC,CAAC;IACzB,mBAAmB,CAAC,OAAO,CAAC,KAAK,IAAI,YAAY,CAAC,CAAC;IACnD,iBAAiB,CAAC,OAAO,CAAC,aAAa,IAAI,MAAM,CAAC,CAAC;IAEnD,SAAS,CAAC,EAAE,IAAI,EAAE,wBAAwB,EAAE,OAAO,EAAE,OAAO,CAAC,cAAc,IAAI,OAAO,EAAE,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,SAAS,EAAE,CAAC,CAAC;IACvH,MAAM,CAAC,EAAE,IAAI,EAAE,oBAAoB,EAAE,OAAO,EAAE,OAAO,CAAC,cAAc,IAAI,OAAO,EAA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C,CAAC;IAC1F,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../src/register.ts"],"names":[],"mappings":""}
|
package/dist/register.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register.js","sourceRoot":"","sources":["../src/register.ts"],"names":[],"mappings":"AAAA,wFAAwF;AACxF,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD,eAAe,EAAE,CAAC"}
|
package/dist/world.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { World } from '@cucumber/cucumber';
|
|
2
|
+
import type { IWorldOptions } from '@cucumber/cucumber';
|
|
3
|
+
import type { Driver, Session } from '@quiesco/core';
|
|
4
|
+
import type { Lifecycle } from './lifecycle.js';
|
|
5
|
+
/** @internal set by registerQuiesco(). */
|
|
6
|
+
export declare function bindLifecycle(l: Lifecycle): void;
|
|
7
|
+
/**
|
|
8
|
+
* Cucumber World with `this.app` (the Quiesco Driver). Extend it to add your own business driver
|
|
9
|
+
* (Ports & Adapters): `class MyWorld extends QuiescoWorld { todos = new TodoDriver(this.app) }`.
|
|
10
|
+
*/
|
|
11
|
+
export declare class QuiescoWorld<Parameters = unknown> extends World<Parameters> {
|
|
12
|
+
constructor(options: IWorldOptions<Parameters>);
|
|
13
|
+
get app(): Driver;
|
|
14
|
+
get session(): Session;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=world.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"world.d.ts","sourceRoot":"","sources":["../src/world.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAErD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAIhD,0CAA0C;AAC1C,wBAAgB,aAAa,CAAC,CAAC,EAAE,SAAS,GAAG,IAAI,CAEhD;AAED;;;GAGG;AACH,qBAAa,YAAY,CAAC,UAAU,GAAG,OAAO,CAAE,SAAQ,KAAK,CAAC,UAAU,CAAC;gBAC3D,OAAO,EAAE,aAAa,CAAC,UAAU,CAAC;IAI9C,IAAI,GAAG,IAAI,MAAM,CAEhB;IAED,IAAI,OAAO,IAAI,OAAO,CAGrB;CACF"}
|
package/dist/world.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { World } from '@cucumber/cucumber';
|
|
2
|
+
let lifecycle = null;
|
|
3
|
+
/** @internal set by registerQuiesco(). */
|
|
4
|
+
export function bindLifecycle(l) {
|
|
5
|
+
lifecycle = l;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Cucumber World with `this.app` (the Quiesco Driver). Extend it to add your own business driver
|
|
9
|
+
* (Ports & Adapters): `class MyWorld extends QuiescoWorld { todos = new TodoDriver(this.app) }`.
|
|
10
|
+
*/
|
|
11
|
+
export class QuiescoWorld extends World {
|
|
12
|
+
constructor(options) {
|
|
13
|
+
super(options);
|
|
14
|
+
}
|
|
15
|
+
get app() {
|
|
16
|
+
return this.session.driver;
|
|
17
|
+
}
|
|
18
|
+
get session() {
|
|
19
|
+
if (lifecycle === null)
|
|
20
|
+
throw new Error("Quiesco is not registered: import '@quiesco/cucumber/register' in a support file");
|
|
21
|
+
return lifecycle.current;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=world.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"world.js","sourceRoot":"","sources":["../src/world.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAM3C,IAAI,SAAS,GAAqB,IAAI,CAAC;AAEvC,0CAA0C;AAC1C,MAAM,UAAU,aAAa,CAAC,CAAY;IACxC,SAAS,GAAG,CAAC,CAAC;AAChB,CAAC;AAED;;;GAGG;AACH,MAAM,OAAO,YAAmC,SAAQ,KAAiB;IACvE,YAAY,OAAkC;QAC5C,KAAK,CAAC,OAAO,CAAC,CAAC;IACjB,CAAC;IAED,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;IAC7B,CAAC;IAED,IAAI,OAAO;QACT,IAAI,SAAS,KAAK,IAAI;YAAE,MAAM,IAAI,KAAK,CAAC,kFAAkF,CAAC,CAAC;QAC5H,OAAO,SAAS,CAAC,OAAO,CAAC;IAC3B,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,62 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quiesco/cucumber",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "cucumber-js World and hooks for Quiesco",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "h2nology",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"quiesco",
|
|
9
|
+
"e2e",
|
|
10
|
+
"testing",
|
|
11
|
+
"expo",
|
|
12
|
+
"react-native",
|
|
13
|
+
"cucumber",
|
|
14
|
+
"bdd",
|
|
15
|
+
"gherkin"
|
|
16
|
+
],
|
|
17
|
+
"homepage": "https://github.com/h2nology/quiesco/tree/main/packages/cucumber#readme",
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/h2nology/quiesco.git",
|
|
21
|
+
"directory": "packages/cucumber"
|
|
22
|
+
},
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/h2nology/quiesco/issues"
|
|
25
|
+
},
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=24"
|
|
28
|
+
},
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"type": "module",
|
|
33
|
+
"main": "./dist/index.js",
|
|
34
|
+
"types": "./dist/index.d.ts",
|
|
35
|
+
"exports": {
|
|
36
|
+
".": {
|
|
37
|
+
"types": "./dist/index.d.ts",
|
|
38
|
+
"import": "./dist/index.js"
|
|
39
|
+
},
|
|
40
|
+
"./register": {
|
|
41
|
+
"types": "./dist/register.d.ts",
|
|
42
|
+
"import": "./dist/register.js"
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
"files": [
|
|
46
|
+
"dist",
|
|
47
|
+
"src"
|
|
48
|
+
],
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"@quiesco/core": "0.1.0"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@cucumber/cucumber": "13.3.0"
|
|
54
|
+
},
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"@cucumber/cucumber": ">=12"
|
|
57
|
+
},
|
|
58
|
+
"scripts": {
|
|
59
|
+
"build": "tsc -b",
|
|
60
|
+
"test": "vitest run"
|
|
61
|
+
}
|
|
6
62
|
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { registerQuiesco } from './register-hooks.js';
|
|
2
|
+
export type { RegisterOptions } from './register-hooks.js';
|
|
3
|
+
export { QuiescoWorld } from './world.js';
|
|
4
|
+
export { Lifecycle, tagLevels } from './lifecycle.js';
|
|
5
|
+
export type { Attachment, LifecycleOptions, ScenarioResult } from './lifecycle.js';
|
package/src/lifecycle.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* cucumber-js on top of core's runner-independent Lifecycle (requirements.md §6.10): Gherkin tag levels
|
|
3
|
+
* and `--parallel` workers (Phase 6.12). Kept free of cucumber imports so it can be unit-tested.
|
|
4
|
+
*/
|
|
5
|
+
import { Lifecycle as CoreLifecycle } from '@quiesco/core';
|
|
6
|
+
import type { LifecycleOptions as CoreOptions, WorkerInfo } from '@quiesco/core';
|
|
7
|
+
|
|
8
|
+
export type { Attachment, ScenarioResult } from '@quiesco/core';
|
|
9
|
+
export type LifecycleOptions = CoreOptions;
|
|
10
|
+
|
|
11
|
+
interface TaggedNode {
|
|
12
|
+
tags: readonly { id: string }[];
|
|
13
|
+
}
|
|
14
|
+
interface ScenarioNode extends TaggedNode {
|
|
15
|
+
examples: readonly TaggedNode[];
|
|
16
|
+
}
|
|
17
|
+
interface FeatureChild {
|
|
18
|
+
rule?: TaggedNode & { children: readonly FeatureChild[] };
|
|
19
|
+
scenario?: ScenarioNode;
|
|
20
|
+
}
|
|
21
|
+
/** The parts of a cucumber-js GherkinDocument needed to place tags (structural, no cucumber import). */
|
|
22
|
+
export interface TagSource {
|
|
23
|
+
feature?: (TaggedNode & { children: readonly FeatureChild[] }) | undefined;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* A pickle's tags grouped by Gherkin level: [feature, rule, scenario, examples]. Tags whose node is
|
|
28
|
+
* not found count as scenario tags.
|
|
29
|
+
*/
|
|
30
|
+
export function tagLevels(pickleTags: readonly { name: string; astNodeId: string }[], doc: TagSource): string[][] {
|
|
31
|
+
const level = new Map<string, number>();
|
|
32
|
+
const mark = (node: TaggedNode, l: number) => node.tags.forEach((t) => level.set(t.id, l));
|
|
33
|
+
const walk = (children: readonly FeatureChild[]) => {
|
|
34
|
+
for (const c of children) {
|
|
35
|
+
if (c.rule !== undefined) {
|
|
36
|
+
mark(c.rule, 1);
|
|
37
|
+
walk(c.rule.children);
|
|
38
|
+
}
|
|
39
|
+
if (c.scenario !== undefined) {
|
|
40
|
+
mark(c.scenario, 2);
|
|
41
|
+
c.scenario.examples.forEach((e) => mark(e, 3));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
if (doc.feature !== undefined) {
|
|
46
|
+
mark(doc.feature, 0);
|
|
47
|
+
walk(doc.feature.children);
|
|
48
|
+
}
|
|
49
|
+
const out: string[][] = [[], [], [], []];
|
|
50
|
+
for (const t of pickleTags) out[level.get(t.astNodeId) ?? 2]?.push(t.name);
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The worker this thread is: cucumber-js `--parallel N` runs N worker threads and sets
|
|
56
|
+
* CUCUMBER_WORKER_ID ("0"…) and CUCUMBER_TOTAL_WORKERS in each one's environment (findings 4.6).
|
|
57
|
+
*/
|
|
58
|
+
export function cucumberWorker(env: NodeJS.ProcessEnv): WorkerInfo {
|
|
59
|
+
const count = Number.parseInt(env['CUCUMBER_TOTAL_WORKERS'] ?? '', 10);
|
|
60
|
+
const index = Number.parseInt(env['CUCUMBER_WORKER_ID'] ?? '', 10);
|
|
61
|
+
if (!(count > 1) || !(index >= 0)) return { index: 0, count: 1 };
|
|
62
|
+
return { index, count };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export class Lifecycle extends CoreLifecycle {
|
|
66
|
+
constructor(options: LifecycleOptions = {}) {
|
|
67
|
+
super({ worker: cucumberWorker(options.env ?? process.env), ...options });
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { After, AfterAll, Before, BeforeAll, Status, setDefaultTimeout, setWorldConstructor } from '@cucumber/cucumber';
|
|
2
|
+
|
|
3
|
+
import { Lifecycle, tagLevels } from './lifecycle.js';
|
|
4
|
+
import type { LifecycleOptions } from './lifecycle.js';
|
|
5
|
+
import { QuiescoWorld, bindLifecycle } from './world.js';
|
|
6
|
+
|
|
7
|
+
export interface RegisterOptions extends LifecycleOptions {
|
|
8
|
+
/** Use your own World (must extend QuiescoWorld). Default QuiescoWorld. */
|
|
9
|
+
world?: typeof QuiescoWorld;
|
|
10
|
+
/** Default step timeout. Each driver call has its own sync timeout; this caps a whole step. Default 60 s. */
|
|
11
|
+
stepTimeoutMs?: number;
|
|
12
|
+
/** BeforeAll timeout: booting an emulator can take minutes. Default 10 min. */
|
|
13
|
+
setupTimeoutMs?: number;
|
|
14
|
+
/**
|
|
15
|
+
* Timeout of the per-scenario reset (Before). It can start the app again when it is gone, which waits up to
|
|
16
|
+
* 3 × the connect timeout. Default 3 min.
|
|
17
|
+
*/
|
|
18
|
+
resetTimeoutMs?: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Register the World and the lifecycle hooks with cucumber-js. Call once, from a support file. */
|
|
22
|
+
export function registerQuiesco(options: RegisterOptions = {}): Lifecycle {
|
|
23
|
+
const lifecycle = new Lifecycle(options);
|
|
24
|
+
bindLifecycle(lifecycle);
|
|
25
|
+
setWorldConstructor(options.world ?? QuiescoWorld);
|
|
26
|
+
setDefaultTimeout(options.stepTimeoutMs ?? 60_000);
|
|
27
|
+
|
|
28
|
+
BeforeAll({ name: 'quiesco: start session', timeout: options.setupTimeoutMs ?? 600_000 }, () => lifecycle.beforeAll());
|
|
29
|
+
Before({ name: 'quiesco: reset app', timeout: options.resetTimeoutMs ?? 180_000 }, ({ pickle, gherkinDocument }) => lifecycle.before(tagLevels(pickle.tags, gherkinDocument), pickle.name));
|
|
30
|
+
After({ name: 'quiesco: evidence' }, async function (this: QuiescoWorld, { pickle, result }) {
|
|
31
|
+
const failed = result !== undefined && result.status !== Status.PASSED && result.status !== Status.SKIPPED;
|
|
32
|
+
for (const a of (await lifecycle.after({ tags: pickle.tags.map((t) => t.name), failed })).attachments) {
|
|
33
|
+
const opts = a.fileName !== undefined ? { mediaType: a.mediaType, fileName: a.fileName } : { mediaType: a.mediaType };
|
|
34
|
+
if (typeof a.data === 'string') this.attach(a.data, opts);
|
|
35
|
+
else this.attach(a.data, opts);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
AfterAll({ name: 'quiesco: stop session', timeout: 120_000 }, () => lifecycle.afterAll());
|
|
39
|
+
return lifecycle;
|
|
40
|
+
}
|
package/src/register.ts
ADDED
package/src/world.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { World } from '@cucumber/cucumber';
|
|
2
|
+
import type { IWorldOptions } from '@cucumber/cucumber';
|
|
3
|
+
import type { Driver, Session } from '@quiesco/core';
|
|
4
|
+
|
|
5
|
+
import type { Lifecycle } from './lifecycle.js';
|
|
6
|
+
|
|
7
|
+
let lifecycle: Lifecycle | null = null;
|
|
8
|
+
|
|
9
|
+
/** @internal set by registerQuiesco(). */
|
|
10
|
+
export function bindLifecycle(l: Lifecycle): void {
|
|
11
|
+
lifecycle = l;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Cucumber World with `this.app` (the Quiesco Driver). Extend it to add your own business driver
|
|
16
|
+
* (Ports & Adapters): `class MyWorld extends QuiescoWorld { todos = new TodoDriver(this.app) }`.
|
|
17
|
+
*/
|
|
18
|
+
export class QuiescoWorld<Parameters = unknown> extends World<Parameters> {
|
|
19
|
+
constructor(options: IWorldOptions<Parameters>) {
|
|
20
|
+
super(options);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
get app(): Driver {
|
|
24
|
+
return this.session.driver;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
get session(): Session {
|
|
28
|
+
if (lifecycle === null) throw new Error("Quiesco is not registered: import '@quiesco/cucumber/register' in a support file");
|
|
29
|
+
return lifecycle.current;
|
|
30
|
+
}
|
|
31
|
+
}
|