@jsenv/test 1.0.4 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -355
- package/dist/jsenv_test.js +68 -52
- package/package.json +3 -3
- package/src/execution/execute_steps.js +4 -0
- package/src/runtime_browsers/chromium.js +11 -12
- package/src/runtime_browsers/firefox.js +29 -9
- package/src/runtime_browsers/webkit.js +27 -28
package/README.md
CHANGED
|
@@ -1,359 +1,6 @@
|
|
|
1
1
|
# @jsenv/test [](https://www.npmjs.com/package/@jsenv/test)
|
|
2
2
|
|
|
3
|
-
Executing test files in web browsers
|
|
3
|
+
Executing test files in web browsers or Node.js.
|
|
4
4
|
This tool enforce test files to be written as **standard** files, without any sort of complexity.
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
This section demonstrates how to write a test that will be executed in a web browser.
|
|
9
|
-
|
|
10
|
-
The function that will be tested is inside "add.js" file:
|
|
11
|
-
|
|
12
|
-
```js
|
|
13
|
-
export const add = (a, b) => a + b
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
The demonstration uses the following file structure:
|
|
17
|
-
|
|
18
|
-
<pre>
|
|
19
|
-
project/
|
|
20
|
-
src/
|
|
21
|
-
<strong>add.js</strong>
|
|
22
|
-
index.html
|
|
23
|
-
package.json
|
|
24
|
-
</pre>
|
|
25
|
-
|
|
26
|
-
At the end of the demo, the file structure will be like this:
|
|
27
|
-
|
|
28
|
-
<pre>
|
|
29
|
-
project/
|
|
30
|
-
scripts/
|
|
31
|
-
<strong>dev.mjs</strong>
|
|
32
|
-
<strong>test.mjs</strong>
|
|
33
|
-
src/
|
|
34
|
-
add.js
|
|
35
|
-
<strong>add.test.html</strong>
|
|
36
|
-
index.html
|
|
37
|
-
package.json
|
|
38
|
-
</pre>
|
|
39
|
-
|
|
40
|
-
## 1.1 Writing the test file
|
|
41
|
-
|
|
42
|
-
_src/add.test.html_
|
|
43
|
-
|
|
44
|
-
```html
|
|
45
|
-
<!DOCTYPE html>
|
|
46
|
-
<html>
|
|
47
|
-
<head>
|
|
48
|
-
<title>Title</title>
|
|
49
|
-
<meta charset="utf-8" />
|
|
50
|
-
<link rel="icon" href="data:," />
|
|
51
|
-
</head>
|
|
52
|
-
|
|
53
|
-
<body>
|
|
54
|
-
<script type="module">
|
|
55
|
-
import { add } from "./add.js"
|
|
56
|
-
|
|
57
|
-
const actual = add(1, 2)
|
|
58
|
-
const expected = 3
|
|
59
|
-
if (actual !== expected) {
|
|
60
|
-
throw new Error(`add(1,2) should return 3, got ${actual}`)
|
|
61
|
-
}
|
|
62
|
-
</script>
|
|
63
|
-
</body>
|
|
64
|
-
</html>
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
## 1.2 Executing the test file
|
|
68
|
-
|
|
69
|
-
_scripts/dev.mjs_: will start a web server that is needed to executed "add.test.html" in a browser.
|
|
70
|
-
|
|
71
|
-
```js
|
|
72
|
-
import { startDevServer } from "@jsenv/core"
|
|
73
|
-
|
|
74
|
-
await startDevServer({
|
|
75
|
-
sourceDirectoryUrl: new URL("../src/", import.meta.url),
|
|
76
|
-
port: 3456,
|
|
77
|
-
})
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
_scripts/test.mjs_: will start a web browser and use it to execute all test files.
|
|
81
|
-
|
|
82
|
-
```js
|
|
83
|
-
import { executeTestPlan, chromium } from "@jsenv/test"
|
|
84
|
-
|
|
85
|
-
await executeTestPlan({
|
|
86
|
-
rootDirectoryUrl: new URL("../", import.meta.url),
|
|
87
|
-
testPlan: {
|
|
88
|
-
"./src/**/*.test.html": {
|
|
89
|
-
chromium: {
|
|
90
|
-
runtime: chromium(),
|
|
91
|
-
},
|
|
92
|
-
},
|
|
93
|
-
},
|
|
94
|
-
webServer: {
|
|
95
|
-
origin: "http://localhost:3456",
|
|
96
|
-
rootDirectoryUrl: new URL("../src/", import.meta.url),
|
|
97
|
-
moduleUrl: new URL("./dev.mjs", import.meta.url),
|
|
98
|
-
},
|
|
99
|
-
})
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
Command to install dependencies:
|
|
103
|
-
|
|
104
|
-
```console
|
|
105
|
-
npm i --save-dev @jsenv/core
|
|
106
|
-
npm i --save-dev @jsenv/test
|
|
107
|
-
npm i --save-dev playwright
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
☝️ Playwright is used by `@jsenv/test` to start a web browser, see [playwright website](https://github.com/microsoft/playwright)<sup>↗</sup>.
|
|
111
|
-
|
|
112
|
-
Command to execute tests:
|
|
113
|
-
|
|
114
|
-
```console
|
|
115
|
-
node ./scripts/test.mjs
|
|
116
|
-
```
|
|
117
|
-
|
|
118
|
-
### 1.3 Executing on more browsers
|
|
119
|
-
|
|
120
|
-
```js
|
|
121
|
-
import { executeTestPlan, chromium, firefox, webkit } from "@jsenv/test"
|
|
122
|
-
|
|
123
|
-
await executeTestPlan({
|
|
124
|
-
rootDirectoryUrl: new URL("../", import.meta.url),
|
|
125
|
-
testPlan: {
|
|
126
|
-
"./src/**/*.test.html": {
|
|
127
|
-
chromium: {
|
|
128
|
-
runtime: chromium(),
|
|
129
|
-
},
|
|
130
|
-
firefox: {
|
|
131
|
-
runtime: firefox(),
|
|
132
|
-
},
|
|
133
|
-
webkit: {
|
|
134
|
-
runtime: webkit(),
|
|
135
|
-
},
|
|
136
|
-
},
|
|
137
|
-
},
|
|
138
|
-
webServer: {
|
|
139
|
-
origin: "http://localhost:3456",
|
|
140
|
-
rootDirectoryUrl: new URL("../src/", import.meta.url),
|
|
141
|
-
moduleUrl: new URL("./dev.mjs", import.meta.url),
|
|
142
|
-
},
|
|
143
|
-
})
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
# 2. Writing tests on Node.js
|
|
147
|
-
|
|
148
|
-
This section demonstrates how to write a test that will be executed in Node.js.
|
|
149
|
-
|
|
150
|
-
The function that will be tested is inside "add.js" file:
|
|
151
|
-
|
|
152
|
-
```js
|
|
153
|
-
export const add = (a, b) => a + b
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
The demonstration uses the following file structure:
|
|
157
|
-
|
|
158
|
-
<pre>
|
|
159
|
-
project/
|
|
160
|
-
src/
|
|
161
|
-
<strong>add.js</strong>
|
|
162
|
-
package.json
|
|
163
|
-
</pre>
|
|
164
|
-
|
|
165
|
-
At the end of the demo, the file structure will be like this:
|
|
166
|
-
|
|
167
|
-
<pre>
|
|
168
|
-
project/
|
|
169
|
-
scripts/
|
|
170
|
-
<strong>test.mjs</strong>
|
|
171
|
-
src/
|
|
172
|
-
add.js
|
|
173
|
-
tests/
|
|
174
|
-
<strong>add.test.mjs</strong>
|
|
175
|
-
package.json
|
|
176
|
-
</pre>
|
|
177
|
-
|
|
178
|
-
## 2.1 Writing the test file
|
|
179
|
-
|
|
180
|
-
_add.test.mjs_
|
|
181
|
-
|
|
182
|
-
```js
|
|
183
|
-
import { add } from "./add.js"
|
|
184
|
-
|
|
185
|
-
const actual = add(1, 2)
|
|
186
|
-
const expected = 3
|
|
187
|
-
if (actual !== expected) {
|
|
188
|
-
throw new Error(`add(1,2) should return 3, got ${actual}`)
|
|
189
|
-
}
|
|
190
|
-
```
|
|
191
|
-
|
|
192
|
-
## 2.2 Executing the test file
|
|
193
|
-
|
|
194
|
-
_scripts/test.mjs_
|
|
195
|
-
|
|
196
|
-
```js
|
|
197
|
-
import { executeTestPlan, nodeWorkerThread } from "@jsenv/test"
|
|
198
|
-
|
|
199
|
-
await executeTestPlan({
|
|
200
|
-
rootDirectoryUrl: new URL("../", import.meta.url),
|
|
201
|
-
testPlan: {
|
|
202
|
-
"./tests/**/*.test.mjs": {
|
|
203
|
-
node: {
|
|
204
|
-
runtime: nodeWorkerThread(),
|
|
205
|
-
},
|
|
206
|
-
},
|
|
207
|
-
},
|
|
208
|
-
})
|
|
209
|
-
```
|
|
210
|
-
|
|
211
|
-
Command to install dependencies:
|
|
212
|
-
|
|
213
|
-
```console
|
|
214
|
-
npm i --save-dev @jsenv/test
|
|
215
|
-
```
|
|
216
|
-
|
|
217
|
-
Command to execute tests:
|
|
218
|
-
|
|
219
|
-
```console
|
|
220
|
-
node ./scripts/test.mjs
|
|
221
|
-
```
|
|
222
|
-
|
|
223
|
-
# 3. Assertion library
|
|
224
|
-
|
|
225
|
-
To have a basic example, the part of the code comparing `actual` and `expected` was done without an assertion library.
|
|
226
|
-
In pratice a test would likely use one. The diff below shows how the assertion can be written using [@jsenv/assert](../assert). Note that any other assertion library would work.
|
|
227
|
-
|
|
228
|
-
```diff
|
|
229
|
-
+ import { assert } from "@jsenv/assert"
|
|
230
|
-
import { add } from "./add.js"
|
|
231
|
-
|
|
232
|
-
const actual = add(1, 2)
|
|
233
|
-
const expected = 3
|
|
234
|
-
- if (actual !== expected) {
|
|
235
|
-
- throw new Error(`add(1,2) should return 3, got ${actual}`)
|
|
236
|
-
- }
|
|
237
|
-
+ assert({ actual, expected })
|
|
238
|
-
```
|
|
239
|
-
|
|
240
|
-
# 4. API
|
|
241
|
-
|
|
242
|
-
```js
|
|
243
|
-
import {
|
|
244
|
-
executeTestPlan,
|
|
245
|
-
chromium,
|
|
246
|
-
firefox,
|
|
247
|
-
webkit,
|
|
248
|
-
nodeWorkerThread,
|
|
249
|
-
nodeChildProcess,
|
|
250
|
-
} from "@jsenv/test"
|
|
251
|
-
|
|
252
|
-
const report = await executeTestPlan({
|
|
253
|
-
rootDirectoryUrl: new URL("../", import.meta.url),
|
|
254
|
-
testPlan: {
|
|
255
|
-
"./src/**/*.test.html": {
|
|
256
|
-
chromium: {
|
|
257
|
-
runtime: chromium(),
|
|
258
|
-
},
|
|
259
|
-
firefox: {
|
|
260
|
-
runtime: firefox(),
|
|
261
|
-
},
|
|
262
|
-
webkit: {
|
|
263
|
-
runtime: webkit(),
|
|
264
|
-
},
|
|
265
|
-
},
|
|
266
|
-
"./src/**/*.test.mjs": {
|
|
267
|
-
node_worker: {
|
|
268
|
-
runtime: nodeWorkerThread(),
|
|
269
|
-
},
|
|
270
|
-
node_process: {
|
|
271
|
-
runtime: nodeChildProcess({
|
|
272
|
-
commandLineOptions: ["--no-warnings"],
|
|
273
|
-
env: { TEST: "1" },
|
|
274
|
-
importMap: {
|
|
275
|
-
imports: { foo: "./foo_mock.js" },
|
|
276
|
-
},
|
|
277
|
-
}),
|
|
278
|
-
},
|
|
279
|
-
},
|
|
280
|
-
},
|
|
281
|
-
webServer: {
|
|
282
|
-
origin: "http://localhost:3456",
|
|
283
|
-
rootDirectoryUrl: new URL("../src/", import.meta.url),
|
|
284
|
-
moduleUrl: new URL("./dev.mjs", import.meta.url),
|
|
285
|
-
},
|
|
286
|
-
keepRunning: true,
|
|
287
|
-
logShortForCompletedExecutions: true,
|
|
288
|
-
logMergeForCompletedExecutions: true,
|
|
289
|
-
coverageEnabled: true,
|
|
290
|
-
coverageConfig: {
|
|
291
|
-
"./src/**/*.js": true,
|
|
292
|
-
"./src/**/*.test.mjs": false,
|
|
293
|
-
},
|
|
294
|
-
})
|
|
295
|
-
report // contains many information about test executions
|
|
296
|
-
```
|
|
297
|
-
|
|
298
|
-
| Parameter | Description |
|
|
299
|
-
| ------------------------------ | ----------------------------------------------------------------------------------------------------- |
|
|
300
|
-
| rootDirectoryUrl | Url used to resolve relative urls in other parameters (like testPlan) |
|
|
301
|
-
| testPlan | Object listing the files to execute and configuring where they will be executed |
|
|
302
|
-
| keepRunning | Boolean that can be used to keep browser/node process alive after all executions are done |
|
|
303
|
-
| logShortForCompletedExecutions | Boolean, when enabled completed execution logs will be shorter |
|
|
304
|
-
| logMergeForCompletedExecutions | Boolean, when enabled, as long as executions are completed, logs are overridden to shorten the output |
|
|
305
|
-
| coverageEnabled | Boolean controlling if code coverage will be collected while executing test files |
|
|
306
|
-
| coverageConfig | Object describing the files that should be covered |
|
|
307
|
-
| coverageReportHtml | Boolean controlling if a code coverage report will be written as HTML files |
|
|
308
|
-
| coverageReportHtmlDirectoryUrl | String or url where html files composing the code coverage report will be written |
|
|
309
|
-
|
|
310
|
-
# 4.1 webServer
|
|
311
|
-
|
|
312
|
-
| Parameter | Description |
|
|
313
|
-
| -------------------------- | ----------------------------------------------------------------------------------------------------------------- |
|
|
314
|
-
| webServer.origin | Url listened by the web server |
|
|
315
|
-
| webServer.rootDirectoryUrl | Url leading to the root directory for the web server |
|
|
316
|
-
| webServer.moduleUrl | `executeTestPlan` does a dynamic import on `webServer.moduleUrl` if there is nothing listening `webServer.origin` |
|
|
317
|
-
|
|
318
|
-
## 4.2 chromium/firefox/webkit
|
|
319
|
-
|
|
320
|
-
chromium, firefox and webkit runtimes can be configured, they use the parameters listed in the table below:
|
|
321
|
-
|
|
322
|
-
| Parameter | Description |
|
|
323
|
-
| ----------------------- | ----------------------------------------------------------------------------------------------------------------- |
|
|
324
|
-
| headful | browser UI would be displayed while running tests |
|
|
325
|
-
| playwrightLaunchOptions | Will be forwarded to playwright launch, see https://playwright.dev/docs/api/class-browsertype#browser-type-launch |
|
|
326
|
-
|
|
327
|
-
## 4.3 nodeWorkerThread/nodeChildProcess
|
|
328
|
-
|
|
329
|
-
nodeWorkerThread and nodeChildProcess can be configured, they use the parameters listed in the table below:
|
|
330
|
-
|
|
331
|
-
| Parameter | Description |
|
|
332
|
-
| ------------------ | ----------------------------------------------------------------------------------------------------------------------- |
|
|
333
|
-
| commandLineOptions | Command line options for node, see https://nodejs.org/api/cli.html#options |
|
|
334
|
-
| env | Becomes `process.env`, see "env" in https://nodejs.org/api/child_process.html#child_processexeccommand-options-callback |
|
|
335
|
-
| importMap | Can be used to override import resolution (redirect to other files during test) |
|
|
336
|
-
|
|
337
|
-
## 4.4 Allocated time
|
|
338
|
-
|
|
339
|
-
Each file is given 30s to execute.
|
|
340
|
-
If this duration is exceeded the browser tab (or node process/worker thread) is closed and execution is considered as failed.
|
|
341
|
-
This duration can be configured as shown below:
|
|
342
|
-
|
|
343
|
-
```js
|
|
344
|
-
import { executeTestPlan, nodeWorkerThread } from "@jsenv/test"
|
|
345
|
-
|
|
346
|
-
await executeTestPlan({
|
|
347
|
-
rootDirectoryUrl: new URL("../", import.meta.url),
|
|
348
|
-
testPlan: {
|
|
349
|
-
"./tests/**/*.test.mjs": {
|
|
350
|
-
node: {
|
|
351
|
-
runtime: nodeWorkerThread(),
|
|
352
|
-
allocatedMs: 60_000,
|
|
353
|
-
},
|
|
354
|
-
},
|
|
355
|
-
},
|
|
356
|
-
})
|
|
357
|
-
```
|
|
358
|
-
|
|
359
|
-
☝️ Code above changes the default allocated time to 60s.
|
|
6
|
+
[Documentation](<https://github.com/jsenv/core/wiki/D)-Test>)
|
package/dist/jsenv_test.js
CHANGED
|
@@ -3628,6 +3628,7 @@ const executeSteps = async (executionSteps, {
|
|
|
3628
3628
|
beforeExecutionCallback = () => {},
|
|
3629
3629
|
afterExecutionCallback = () => {}
|
|
3630
3630
|
} = {}) => {
|
|
3631
|
+
executionSteps = executionSteps.filter(executionStep => !executionStep.runtime?.disabled);
|
|
3631
3632
|
const executePlanReturnValue = {};
|
|
3632
3633
|
const report = {};
|
|
3633
3634
|
const callbacks = [];
|
|
@@ -4962,80 +4963,95 @@ const registerEvent = ({
|
|
|
4962
4963
|
};
|
|
4963
4964
|
};
|
|
4964
4965
|
|
|
4965
|
-
const chromiumParams = {
|
|
4966
|
-
browserName: "chromium",
|
|
4967
|
-
// browserVersion will be set by "browser._initializer.version"
|
|
4968
|
-
// see also https://github.com/microsoft/playwright/releases
|
|
4969
|
-
browserVersion: "unset",
|
|
4970
|
-
coveragePlaywrightAPIAvailable: true
|
|
4971
|
-
};
|
|
4972
4966
|
const chromium = params => {
|
|
4973
|
-
return
|
|
4974
|
-
...chromiumParams,
|
|
4975
|
-
...params
|
|
4976
|
-
});
|
|
4967
|
+
return createChromiumRuntine(params);
|
|
4977
4968
|
};
|
|
4978
4969
|
const chromiumIsolatedTab = params => {
|
|
4970
|
+
return createChromiumRuntine({
|
|
4971
|
+
...params,
|
|
4972
|
+
isolatedTab: true
|
|
4973
|
+
});
|
|
4974
|
+
};
|
|
4975
|
+
const createChromiumRuntine = params => {
|
|
4979
4976
|
return createRuntimeUsingPlaywright({
|
|
4980
|
-
|
|
4981
|
-
|
|
4977
|
+
browserName: "chromium",
|
|
4978
|
+
// browserVersion will be set by "browser._initializer.version"
|
|
4979
|
+
// see also https://github.com/microsoft/playwright/releases
|
|
4980
|
+
browserVersion: "unset",
|
|
4981
|
+
coveragePlaywrightAPIAvailable: true,
|
|
4982
4982
|
...params
|
|
4983
4983
|
});
|
|
4984
4984
|
};
|
|
4985
4985
|
|
|
4986
|
-
const firefoxParams = {
|
|
4987
|
-
browserName: "firefox",
|
|
4988
|
-
// browserVersion will be set by "browser._initializer.version"
|
|
4989
|
-
// see also https://github.com/microsoft/playwright/releases
|
|
4990
|
-
browserVersion: "unset"
|
|
4991
|
-
};
|
|
4992
4986
|
const firefox = params => {
|
|
4993
|
-
return
|
|
4994
|
-
...firefoxParams,
|
|
4995
|
-
...params
|
|
4996
|
-
});
|
|
4987
|
+
return createFirefoxRuntime(params);
|
|
4997
4988
|
};
|
|
4998
4989
|
const firefoxIsolatedTab = params => {
|
|
4999
4990
|
return createRuntimeUsingPlaywright({
|
|
5000
|
-
...
|
|
5001
|
-
isolatedTab: true
|
|
5002
|
-
...params
|
|
4991
|
+
...params,
|
|
4992
|
+
isolatedTab: true
|
|
5003
4993
|
});
|
|
5004
4994
|
};
|
|
5005
|
-
|
|
5006
|
-
|
|
5007
|
-
|
|
5008
|
-
|
|
5009
|
-
|
|
5010
|
-
|
|
5011
|
-
|
|
5012
|
-
|
|
5013
|
-
|
|
5014
|
-
|
|
5015
|
-
|
|
5016
|
-
|
|
5017
|
-
|
|
4995
|
+
const createFirefoxRuntime = ({
|
|
4996
|
+
disableOnWindowsBecauseFlaky,
|
|
4997
|
+
...params
|
|
4998
|
+
} = {}) => {
|
|
4999
|
+
if (process.platform === "win32") {
|
|
5000
|
+
if (disableOnWindowsBecauseFlaky === undefined) {
|
|
5001
|
+
// https://github.com/microsoft/playwright/issues/1396
|
|
5002
|
+
console.warn(`Windows + firefox detected: executions on firefox will be ignored (firefox is flaky on windows).
|
|
5003
|
+
To disable this warning, use disableOnWindowsBecauseFlaky: true
|
|
5004
|
+
To ignore potential flakyness, use disableOnWindowsBecauseFlaky: false`);
|
|
5005
|
+
disableOnWindowsBecauseFlaky = true;
|
|
5006
|
+
}
|
|
5007
|
+
if (disableOnWindowsBecauseFlaky) {
|
|
5008
|
+
return {
|
|
5009
|
+
disabled: true
|
|
5010
|
+
};
|
|
5018
5011
|
}
|
|
5019
|
-
return false;
|
|
5020
|
-
},
|
|
5021
|
-
transformErrorHook: error => {
|
|
5022
|
-
// Force error stack to contain the error message
|
|
5023
|
-
// because it's not the case on webkit
|
|
5024
|
-
error.stack = `${error.message}
|
|
5025
|
-
at ${error.stack}`;
|
|
5026
|
-
return error;
|
|
5027
5012
|
}
|
|
5028
|
-
};
|
|
5029
|
-
const webkit = params => {
|
|
5030
5013
|
return createRuntimeUsingPlaywright({
|
|
5031
|
-
|
|
5014
|
+
browserName: "firefox",
|
|
5015
|
+
// browserVersion will be set by "browser._initializer.version"
|
|
5016
|
+
// see also https://github.com/microsoft/playwright/releases
|
|
5017
|
+
browserVersion: "unset",
|
|
5018
|
+
isolatedTab: true,
|
|
5032
5019
|
...params
|
|
5033
5020
|
});
|
|
5034
5021
|
};
|
|
5022
|
+
|
|
5023
|
+
const webkit = params => {
|
|
5024
|
+
return createWekbitRuntime(params);
|
|
5025
|
+
};
|
|
5035
5026
|
const webkitIsolatedTab = params => {
|
|
5027
|
+
return createWekbitRuntime({
|
|
5028
|
+
...params,
|
|
5029
|
+
isolatedTab: true
|
|
5030
|
+
});
|
|
5031
|
+
};
|
|
5032
|
+
const createWekbitRuntime = params => {
|
|
5036
5033
|
return createRuntimeUsingPlaywright({
|
|
5037
|
-
|
|
5038
|
-
|
|
5034
|
+
browserName: "webkit",
|
|
5035
|
+
// browserVersion will be set by "browser._initializer.version"
|
|
5036
|
+
// see also https://github.com/microsoft/playwright/releases
|
|
5037
|
+
browserVersion: "unset",
|
|
5038
|
+
shouldIgnoreError: error => {
|
|
5039
|
+
// we catch error during execution but safari throw unhandled rejection
|
|
5040
|
+
// in a non-deterministic way.
|
|
5041
|
+
// I suppose it's due to some race condition to decide if the promise is catched or not
|
|
5042
|
+
// for now we'll ignore unhandled rejection on wekbkit
|
|
5043
|
+
if (error.name === "Unhandled Promise Rejection") {
|
|
5044
|
+
return true;
|
|
5045
|
+
}
|
|
5046
|
+
return false;
|
|
5047
|
+
},
|
|
5048
|
+
transformErrorHook: error => {
|
|
5049
|
+
// Force error stack to contain the error message
|
|
5050
|
+
// because it's not the case on webkit
|
|
5051
|
+
error.stack = `${error.message}
|
|
5052
|
+
at ${error.stack}`;
|
|
5053
|
+
return error;
|
|
5054
|
+
},
|
|
5039
5055
|
...params
|
|
5040
5056
|
});
|
|
5041
5057
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/test",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -33,9 +33,9 @@
|
|
|
33
33
|
"playwright": "1.x"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@jsenv/core": "35.0.
|
|
36
|
+
"@jsenv/core": "35.0.2",
|
|
37
37
|
"@jsenv/abort": "4.2.4",
|
|
38
|
-
"@jsenv/ast": "3.0.
|
|
38
|
+
"@jsenv/ast": "3.0.7",
|
|
39
39
|
"@jsenv/filesystem": "4.2.3",
|
|
40
40
|
"@jsenv/log": "3.3.4",
|
|
41
41
|
"@jsenv/urls": "2.0.0",
|
|
@@ -49,6 +49,10 @@ export const executeSteps = async (
|
|
|
49
49
|
afterExecutionCallback = () => {},
|
|
50
50
|
} = {},
|
|
51
51
|
) => {
|
|
52
|
+
executionSteps = executionSteps.filter(
|
|
53
|
+
(executionStep) => !executionStep.runtime?.disabled,
|
|
54
|
+
)
|
|
55
|
+
|
|
52
56
|
const executePlanReturnValue = {}
|
|
53
57
|
const report = {}
|
|
54
58
|
const callbacks = []
|
|
@@ -1,24 +1,23 @@
|
|
|
1
1
|
import { createRuntimeUsingPlaywright } from "./using_playwright.js"
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
// browserVersion will be set by "browser._initializer.version"
|
|
6
|
-
// see also https://github.com/microsoft/playwright/releases
|
|
7
|
-
browserVersion: "unset",
|
|
8
|
-
coveragePlaywrightAPIAvailable: true,
|
|
3
|
+
export const chromium = (params) => {
|
|
4
|
+
return createChromiumRuntine(params)
|
|
9
5
|
}
|
|
10
6
|
|
|
11
|
-
export const
|
|
12
|
-
return
|
|
13
|
-
...chromiumParams,
|
|
7
|
+
export const chromiumIsolatedTab = (params) => {
|
|
8
|
+
return createChromiumRuntine({
|
|
14
9
|
...params,
|
|
10
|
+
isolatedTab: true,
|
|
15
11
|
})
|
|
16
12
|
}
|
|
17
13
|
|
|
18
|
-
|
|
14
|
+
const createChromiumRuntine = (params) => {
|
|
19
15
|
return createRuntimeUsingPlaywright({
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
browserName: "chromium",
|
|
17
|
+
// browserVersion will be set by "browser._initializer.version"
|
|
18
|
+
// see also https://github.com/microsoft/playwright/releases
|
|
19
|
+
browserVersion: "unset",
|
|
20
|
+
coveragePlaywrightAPIAvailable: true,
|
|
22
21
|
...params,
|
|
23
22
|
})
|
|
24
23
|
}
|
|
@@ -1,22 +1,42 @@
|
|
|
1
1
|
import { createRuntimeUsingPlaywright } from "./using_playwright.js"
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
// browserVersion will be set by "browser._initializer.version"
|
|
6
|
-
// see also https://github.com/microsoft/playwright/releases
|
|
7
|
-
browserVersion: "unset",
|
|
3
|
+
export const firefox = (params) => {
|
|
4
|
+
return createFirefoxRuntime(params)
|
|
8
5
|
}
|
|
9
6
|
|
|
10
|
-
export const
|
|
7
|
+
export const firefoxIsolatedTab = (params) => {
|
|
11
8
|
return createRuntimeUsingPlaywright({
|
|
12
|
-
...firefoxParams,
|
|
13
9
|
...params,
|
|
10
|
+
isolatedTab: true,
|
|
14
11
|
})
|
|
15
12
|
}
|
|
16
13
|
|
|
17
|
-
|
|
14
|
+
const createFirefoxRuntime = ({
|
|
15
|
+
disableOnWindowsBecauseFlaky,
|
|
16
|
+
...params
|
|
17
|
+
} = {}) => {
|
|
18
|
+
if (process.platform === "win32") {
|
|
19
|
+
if (disableOnWindowsBecauseFlaky === undefined) {
|
|
20
|
+
// https://github.com/microsoft/playwright/issues/1396
|
|
21
|
+
console.warn(
|
|
22
|
+
`Windows + firefox detected: executions on firefox will be ignored (firefox is flaky on windows).
|
|
23
|
+
To disable this warning, use disableOnWindowsBecauseFlaky: true
|
|
24
|
+
To ignore potential flakyness, use disableOnWindowsBecauseFlaky: false`,
|
|
25
|
+
)
|
|
26
|
+
disableOnWindowsBecauseFlaky = true
|
|
27
|
+
}
|
|
28
|
+
if (disableOnWindowsBecauseFlaky) {
|
|
29
|
+
return {
|
|
30
|
+
disabled: true,
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
18
35
|
return createRuntimeUsingPlaywright({
|
|
19
|
-
|
|
36
|
+
browserName: "firefox",
|
|
37
|
+
// browserVersion will be set by "browser._initializer.version"
|
|
38
|
+
// see also https://github.com/microsoft/playwright/releases
|
|
39
|
+
browserVersion: "unset",
|
|
20
40
|
isolatedTab: true,
|
|
21
41
|
...params,
|
|
22
42
|
})
|
|
@@ -1,40 +1,39 @@
|
|
|
1
1
|
import { createRuntimeUsingPlaywright } from "./using_playwright.js"
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
// browserVersion will be set by "browser._initializer.version"
|
|
6
|
-
// see also https://github.com/microsoft/playwright/releases
|
|
7
|
-
browserVersion: "unset",
|
|
8
|
-
shouldIgnoreError: (error) => {
|
|
9
|
-
// we catch error during execution but safari throw unhandled rejection
|
|
10
|
-
// in a non-deterministic way.
|
|
11
|
-
// I suppose it's due to some race condition to decide if the promise is catched or not
|
|
12
|
-
// for now we'll ignore unhandled rejection on wekbkit
|
|
13
|
-
if (error.name === "Unhandled Promise Rejection") {
|
|
14
|
-
return true
|
|
15
|
-
}
|
|
16
|
-
return false
|
|
17
|
-
},
|
|
18
|
-
transformErrorHook: (error) => {
|
|
19
|
-
// Force error stack to contain the error message
|
|
20
|
-
// because it's not the case on webkit
|
|
21
|
-
error.stack = `${error.message}
|
|
22
|
-
at ${error.stack}`
|
|
23
|
-
return error
|
|
24
|
-
},
|
|
3
|
+
export const webkit = (params) => {
|
|
4
|
+
return createWekbitRuntime(params)
|
|
25
5
|
}
|
|
26
6
|
|
|
27
|
-
export const
|
|
28
|
-
return
|
|
29
|
-
...webkitParams,
|
|
7
|
+
export const webkitIsolatedTab = (params) => {
|
|
8
|
+
return createWekbitRuntime({
|
|
30
9
|
...params,
|
|
10
|
+
isolatedTab: true,
|
|
31
11
|
})
|
|
32
12
|
}
|
|
33
13
|
|
|
34
|
-
|
|
14
|
+
const createWekbitRuntime = (params) => {
|
|
35
15
|
return createRuntimeUsingPlaywright({
|
|
36
|
-
|
|
37
|
-
|
|
16
|
+
browserName: "webkit",
|
|
17
|
+
// browserVersion will be set by "browser._initializer.version"
|
|
18
|
+
// see also https://github.com/microsoft/playwright/releases
|
|
19
|
+
browserVersion: "unset",
|
|
20
|
+
shouldIgnoreError: (error) => {
|
|
21
|
+
// we catch error during execution but safari throw unhandled rejection
|
|
22
|
+
// in a non-deterministic way.
|
|
23
|
+
// I suppose it's due to some race condition to decide if the promise is catched or not
|
|
24
|
+
// for now we'll ignore unhandled rejection on wekbkit
|
|
25
|
+
if (error.name === "Unhandled Promise Rejection") {
|
|
26
|
+
return true
|
|
27
|
+
}
|
|
28
|
+
return false
|
|
29
|
+
},
|
|
30
|
+
transformErrorHook: (error) => {
|
|
31
|
+
// Force error stack to contain the error message
|
|
32
|
+
// because it's not the case on webkit
|
|
33
|
+
error.stack = `${error.message}
|
|
34
|
+
at ${error.stack}`
|
|
35
|
+
return error
|
|
36
|
+
},
|
|
38
37
|
...params,
|
|
39
38
|
})
|
|
40
39
|
}
|