@itmetsam/samurai-framework 0.22.0 → 0.22.2
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/dist/api.d.ts +3 -3
- package/dist/browser/page-content.d.ts +4 -0
- package/dist/browser/page-content.js +12 -0
- package/dist/browser/page-events.d.ts +11 -0
- package/dist/browser/page-events.js +23 -0
- package/dist/browser/page-logging.d.ts +24 -0
- package/dist/browser/page-logging.js +43 -0
- package/dist/browser/page-settings.d.ts +1 -1
- package/dist/browser/page-viewport.d.ts +21 -0
- package/dist/browser/page-viewport.js +33 -0
- package/dist/browser/page.d.ts +6 -9
- package/dist/browser/page.js +31 -63
- package/dist/browser/screenshot.d.ts +6 -0
- package/dist/browser/screenshot.js +14 -0
- package/dist/capabilities.d.ts +16 -2
- package/dist/capabilities.js +16 -2
- package/dist/config/config.js +2 -1
- package/dist/config/fixture-use.d.ts +19 -0
- package/dist/config/fixture-use.js +44 -0
- package/dist/config/group-use.d.ts +4 -2
- package/dist/config/group-use.js +30 -20
- package/dist/config/use-options.js +5 -1
- package/dist/recorder/capture.d.ts +3 -0
- package/dist/recorder/capture.js +18 -1
- package/dist/recorder/normalise.d.ts +12 -1
- package/dist/recorder/normalise.js +29 -1
- package/dist/recorder/page-messages.d.ts +6 -2
- package/dist/recorder/page-messages.js +29 -21
- package/dist/recorder/toolbar/inspect.js +10 -3
- package/dist/runner/fixture-defs.d.ts +2 -1
- package/dist/runner/fixture-defs.js +51 -18
- package/dist/runner/fixture-meta.d.ts +20 -0
- package/dist/runner/fixture-meta.js +109 -0
- package/dist/runner/fixture-options.d.ts +8 -0
- package/dist/runner/fixture-options.js +35 -0
- package/dist/runner/fixture-outputs.d.ts +11 -0
- package/dist/runner/fixture-outputs.js +28 -0
- package/dist/runner/fixture-registry.d.ts +35 -0
- package/dist/runner/fixture-registry.js +73 -0
- package/dist/runner/fixture-scope.d.ts +39 -9
- package/dist/runner/fixture-scope.js +139 -70
- package/dist/runner/fixture-start.d.ts +27 -0
- package/dist/runner/fixture-start.js +76 -0
- package/dist/runner/fixture-use.d.ts +23 -0
- package/dist/runner/fixture-use.js +64 -0
- package/dist/runner/fixture-worker.d.ts +26 -0
- package/dist/runner/fixture-worker.js +46 -0
- package/dist/runner/prepare-run.js +5 -0
- package/dist/runner/registry.js +15 -5
- package/dist/runner/reporter.d.ts +3 -1
- package/dist/runner/reporter.js +1 -0
- package/dist/runner/run-test.d.ts +3 -0
- package/dist/runner/run-test.js +16 -1
- package/dist/runner/run.d.ts +7 -0
- package/dist/runner/run.js +9 -0
- package/dist/runner/test-function.d.ts +2 -2
- package/dist/runner/test-runner.js +6 -1
- package/dist/runner/use-options.d.ts +16 -2
- package/dist/runner/use-options.js +28 -8
- package/dist/runner/worker-session.js +6 -0
- package/dist/steps/build.js +49 -25
- package/dist/steps/emit.js +64 -7
- package/dist/steps/index.d.ts +1 -1
- package/dist/steps/model.d.ts +60 -10
- package/dist/steps/parse/call.js +125 -39
- package/dist/steps/parse/expectation.d.ts +2 -1
- package/dist/steps/parse/expectation.js +30 -8
- package/dist/steps/parse/literals.d.ts +9 -0
- package/dist/steps/parse/literals.js +42 -0
- package/dist/steps/parse/step.js +28 -1
- package/dist/types/config.d.ts +35 -22
- package/dist/types/extend.d.ts +54 -2
- package/dist/types/test.d.ts +24 -0
- package/dist/types/use.d.ts +14 -0
- package/package.json +1 -1
package/dist/types/config.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { StepDefinition } from "../flows/steps/define.js";
|
|
2
2
|
import type { SupportedBrowser } from "./browser.js";
|
|
3
|
-
import type { UseOptions } from "./use.js";
|
|
3
|
+
import type { FixtureUse, UseOptions } from "./use.js";
|
|
4
4
|
import type { ResolvedConfig } from "../config/resolved-config.js";
|
|
5
5
|
|
|
6
6
|
interface SamuraiTest {
|
|
@@ -39,7 +39,7 @@ export interface SamuraiGroup {
|
|
|
39
39
|
* as config `use` that make sense per group (`locale`, `isMobile`, `viewport`, ...). They apply when the group is
|
|
40
40
|
* selected (`--group`); a run without `--group` ignores them. The way to port a Playwright project.
|
|
41
41
|
*/
|
|
42
|
-
use?: GroupUse;
|
|
42
|
+
use?: GroupUse & FixtureUse;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
/** The options of a group's `use`: those of `test.use()`, and the page's `viewport` */
|
|
@@ -105,6 +105,12 @@ export interface SamuraiEnvironment {
|
|
|
105
105
|
headless?: boolean;
|
|
106
106
|
/** Test data, used in steps as ${name}. Never put secrets here. */
|
|
107
107
|
variables?: Record<string, string | number | boolean>;
|
|
108
|
+
/**
|
|
109
|
+
* `use` options for every test run in this environment, over config `use` and under a group's `use` and
|
|
110
|
+
* `test.use()`. `fixtures: { order: false }` turns a fixture off here for good: a test that needs it is skipped,
|
|
111
|
+
* whatever a group or test says.
|
|
112
|
+
*/
|
|
113
|
+
use?: GroupUse & FixtureUse;
|
|
108
114
|
}
|
|
109
115
|
|
|
110
116
|
export interface SamuraiTestConfig {
|
|
@@ -199,26 +205,27 @@ export interface SamuraiTestConfig {
|
|
|
199
205
|
*/
|
|
200
206
|
filesDir?: string;
|
|
201
207
|
/** How pages are opened, and what the browser pretends: the options of `test.use()` apply to every test */
|
|
202
|
-
use?: UseOptions &
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
208
|
+
use?: UseOptions &
|
|
209
|
+
FixtureUse & {
|
|
210
|
+
/**
|
|
211
|
+
* Size of the page's viewport, so screenshots and layout are the same on every machine.
|
|
212
|
+
* `null` keeps the browser's own size
|
|
213
|
+
* @default { width: 1280, height: 720 }
|
|
214
|
+
*/
|
|
215
|
+
viewport?: { width: number; height: number } | null;
|
|
216
|
+
/**
|
|
217
|
+
* Run the browser without a window. Needed on machines without a display, such as CI runners.
|
|
218
|
+
* Left out, a run is headless when the `CI` environment variable is set and shows a window otherwise
|
|
219
|
+
*/
|
|
220
|
+
headless?: boolean;
|
|
221
|
+
/**
|
|
222
|
+
* Make an action or read on a locator that matches several elements throw
|
|
223
|
+
* `name(): strict mode violation, N elements match ...` instead of using the first one. Narrow the locator
|
|
224
|
+
* (`first()`, `nth()`, `filter()`) or turn it off for one locator with `locator.strict(false)`
|
|
225
|
+
* @default false
|
|
226
|
+
*/
|
|
227
|
+
strictSelectors?: boolean;
|
|
228
|
+
};
|
|
222
229
|
/** What to do with the browser's console output and uncaught page exceptions */
|
|
223
230
|
logs?: {
|
|
224
231
|
/**
|
|
@@ -293,6 +300,12 @@ export interface SamuraiTestConfig {
|
|
|
293
300
|
globalSetup?: string | GlobalSetupFunction;
|
|
294
301
|
/** Module (path relative to the project folder) whose default export runs once after the tests; or the function itself */
|
|
295
302
|
globalTeardown?: string | GlobalTeardownFunction;
|
|
303
|
+
/**
|
|
304
|
+
* The tests made with `test.extend()` whose fixtures the app, the groups and `use.fixtures` can name. The
|
|
305
|
+
* fixtures are read from the list without running a test; a name defined twice, or not matching
|
|
306
|
+
* `/^[a-z][A-Za-z0-9]*$/`, refuses the run.
|
|
307
|
+
*/
|
|
308
|
+
fixtures?: { extend: (...args: never[]) => unknown }[];
|
|
296
309
|
/** Keyed by name: 'dev', 'staging', 'production' */
|
|
297
310
|
environments?: Record<string, SamuraiEnvironment>;
|
|
298
311
|
/** Used when no environment is chosen with --env or SAMURAI_ENV */
|
package/dist/types/extend.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Field } from "../flows/core/index.js";
|
|
1
2
|
import type { TestFixtures } from "./test.js";
|
|
2
3
|
|
|
3
4
|
/** What a test sees when it is built with `test.extend()`: the built-in fixtures, a custom one of the same name replacing it */
|
|
@@ -6,12 +7,63 @@ export type FixturesOf<X> = Omit<TestFixtures, keyof X> & X;
|
|
|
6
7
|
/** `B` on top of `A`: a key in both takes the type from `B` */
|
|
7
8
|
export type MergeFixtures<A, B> = Omit<A, keyof B> & B;
|
|
8
9
|
|
|
10
|
+
/** One key of the value a fixture sets up, listed for the app and the report */
|
|
11
|
+
export interface FixtureOutput {
|
|
12
|
+
name: string;
|
|
13
|
+
label?: string;
|
|
14
|
+
/** The test gets the key, but the report and the app never do */
|
|
15
|
+
secret?: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* One setting of an option fixture, as data for a form: the flows field types, with paths relative to the option
|
|
20
|
+
* object. `secret` stores the name of a secret and `variable` the name of a variable; the fixture receives the
|
|
21
|
+
* resolved value.
|
|
22
|
+
*/
|
|
23
|
+
export type FixtureField =
|
|
24
|
+
| Extract<
|
|
25
|
+
Field,
|
|
26
|
+
{
|
|
27
|
+
type:
|
|
28
|
+
| "text"
|
|
29
|
+
| "code"
|
|
30
|
+
| "expression"
|
|
31
|
+
| "number"
|
|
32
|
+
| "select"
|
|
33
|
+
| "segmented"
|
|
34
|
+
| "switch";
|
|
35
|
+
}
|
|
36
|
+
>
|
|
37
|
+
| {
|
|
38
|
+
path: string;
|
|
39
|
+
label?: string;
|
|
40
|
+
type: "secret" | "variable";
|
|
41
|
+
default?: string;
|
|
42
|
+
};
|
|
43
|
+
|
|
9
44
|
/** The options of a fixture written as `[fixture, options]` */
|
|
10
45
|
export interface FixtureOptions {
|
|
11
46
|
/** Set the fixture up for every test, whether or not the test asks for it */
|
|
12
47
|
auto?: boolean;
|
|
13
|
-
/**
|
|
14
|
-
|
|
48
|
+
/**
|
|
49
|
+
* `"test"`: set up for each test (the default). `"worker"`: set up once per worker for the tests that use it with
|
|
50
|
+
* the same options and environment, and torn down when the worker is done. A worker fixture gets no `page`.
|
|
51
|
+
*/
|
|
52
|
+
scope?: "test" | "worker";
|
|
53
|
+
/** The name in the app's catalog */
|
|
54
|
+
label?: string;
|
|
55
|
+
/** A design-system icon name */
|
|
56
|
+
icon?: string;
|
|
57
|
+
/** One sentence for the catalog */
|
|
58
|
+
description?: string;
|
|
59
|
+
/** The keys of the value the fixture sets up, when it is a flat record of strings, numbers and booleans */
|
|
60
|
+
outputs?: FixtureOutput[];
|
|
61
|
+
/** Milliseconds a setup or a teardown may take. @default the test timeout */
|
|
62
|
+
timeout?: number;
|
|
63
|
+
/** The fixture is the options of the fixture `<name without "Options">`: a value that `use` overrides key by key */
|
|
64
|
+
option?: boolean;
|
|
65
|
+
/** The form of an option fixture */
|
|
66
|
+
fields?: FixtureField[];
|
|
15
67
|
}
|
|
16
68
|
|
|
17
69
|
/** A value, or a function that sets the value up, calls `use(value)` and cleans up once `use` returns */
|
package/dist/types/test.d.ts
CHANGED
|
@@ -74,6 +74,26 @@ export interface TestStepEntry {
|
|
|
74
74
|
steps?: TestStepEntry[];
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
/** How a fixture's setup or teardown went in one test */
|
|
78
|
+
export interface TestFixturePhase {
|
|
79
|
+
/** `"skipped"`: a worker fixture another test of this worker already set up */
|
|
80
|
+
status: "passed" | "failed" | "skipped";
|
|
81
|
+
/** Milliseconds */
|
|
82
|
+
durationMs: number;
|
|
83
|
+
error?: TestError;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** A fixture that set up for a test (hand-written `test.extend` ones too), as the report lists it */
|
|
87
|
+
export interface TestFixtureEntry {
|
|
88
|
+
name: string;
|
|
89
|
+
scope: "test" | "worker";
|
|
90
|
+
setup: TestFixturePhase;
|
|
91
|
+
/** Absent for a worker fixture: it is torn down when the worker is done, after the test's result is written */
|
|
92
|
+
teardown?: Omit<TestFixturePhase, "status"> & { status: "passed" | "failed" };
|
|
93
|
+
/** The declared outputs that are not secret */
|
|
94
|
+
outputs?: Record<string, string | number | boolean>;
|
|
95
|
+
}
|
|
96
|
+
|
|
77
97
|
/** What `testInfo` and `test.info()` tell about the running test (hooks included) */
|
|
78
98
|
export interface TestInfo {
|
|
79
99
|
/** The test's own title */
|
|
@@ -245,6 +265,8 @@ interface TestResultSuccess extends TestResultIdentity, TestRetries {
|
|
|
245
265
|
annotations?: TestAnnotation[];
|
|
246
266
|
/** The steps the test ran with `test.step`; absent when it ran none */
|
|
247
267
|
steps?: TestStepEntry[];
|
|
268
|
+
/** The fixtures the test set up and how each went; absent when it used none */
|
|
269
|
+
fixtures?: TestFixtureEntry[];
|
|
248
270
|
}
|
|
249
271
|
|
|
250
272
|
/** The error sits flat on the entry, as in the report: `message`, `type`, `stack`, and for assertions `expected` and `actual` */
|
|
@@ -265,6 +287,8 @@ interface TestResultFailed extends TestResultIdentity, TestError, TestRetries {
|
|
|
265
287
|
annotations?: TestAnnotation[];
|
|
266
288
|
/** The steps the test ran with `test.step`; absent when it ran none */
|
|
267
289
|
steps?: TestStepEntry[];
|
|
290
|
+
/** The fixtures the test set up and how each went; absent when it used none */
|
|
291
|
+
fixtures?: TestFixtureEntry[];
|
|
268
292
|
}
|
|
269
293
|
|
|
270
294
|
/** What a result says about the retries of its test; absent when it passed or failed on the first attempt */
|
package/dist/types/use.d.ts
CHANGED
|
@@ -38,6 +38,20 @@ export interface UseOptions {
|
|
|
38
38
|
colorScheme?: ColorScheme;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
/**
|
|
42
|
+
* What a `use` that is layered over config, environment, group and `test.use()` can also say about fixtures. Not
|
|
43
|
+
* part of `UseOptions`: `page.use()` and the browser know nothing of fixtures.
|
|
44
|
+
*/
|
|
45
|
+
export interface FixtureUse {
|
|
46
|
+
/**
|
|
47
|
+
* Fixtures to attach by name (`true`: set up before `beforeEach`, like an `auto` fixture) or to remove (`false`).
|
|
48
|
+
* An environment's `false` wins over a group's or test's `true`.
|
|
49
|
+
*/
|
|
50
|
+
fixtures?: Record<string, boolean>;
|
|
51
|
+
/** The values of an option fixture (`orderOptions: { items: 2 }`), merged key by key with the other layers */
|
|
52
|
+
[option: `${string}Options`]: Record<string, unknown> | undefined;
|
|
53
|
+
}
|
|
54
|
+
|
|
41
55
|
/** The options `page.use()` and `context.use()` take: those that can change while the browser runs */
|
|
42
56
|
export type RuntimeUseOptions = Pick<
|
|
43
57
|
UseOptions,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itmetsam/samurai-framework",
|
|
3
|
-
"version": "0.22.
|
|
3
|
+
"version": "0.22.2",
|
|
4
4
|
"description": "Browser test framework over WebDriver BiDi: auto-waiting locators, environments and secrets, a recorder, and a command line.",
|
|
5
5
|
"main": "dist/api.js",
|
|
6
6
|
"exports": {
|