@jsenv/test 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -3,19 +3,45 @@
|
|
|
3
3
|
Executing test files in web browsers and/or Node.js.
|
|
4
4
|
This tool enforce test files to be written as **standard** files, without any sort of complexity.
|
|
5
5
|
|
|
6
|
-
# 1.
|
|
6
|
+
# 1. Writing tests on web browsers
|
|
7
7
|
|
|
8
|
-
|
|
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:
|
|
9
11
|
|
|
10
12
|
```js
|
|
11
|
-
// add.js
|
|
12
13
|
export const add = (a, b) => a + b
|
|
13
14
|
```
|
|
14
15
|
|
|
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_
|
|
16
43
|
|
|
17
44
|
```html
|
|
18
|
-
<!-- add.test.html -->
|
|
19
45
|
<!DOCTYPE html>
|
|
20
46
|
<html>
|
|
21
47
|
<head>
|
|
@@ -38,51 +64,75 @@ export const add = (a, b) => a + b
|
|
|
38
64
|
</html>
|
|
39
65
|
```
|
|
40
66
|
|
|
41
|
-
## 1.2
|
|
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.
|
|
42
70
|
|
|
43
71
|
```js
|
|
44
|
-
|
|
45
|
-
import { add } from "./add.js"
|
|
72
|
+
import { startDevServer } from "@jsenv/core"
|
|
46
73
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
74
|
+
await startDevServer({
|
|
75
|
+
sourceDirectoryUrl: new URL("../src/", import.meta.url),
|
|
76
|
+
port: 3456,
|
|
77
|
+
})
|
|
52
78
|
```
|
|
53
79
|
|
|
54
|
-
|
|
80
|
+
_scripts/test.mjs_: will start a web browser and use it to execute all test files.
|
|
55
81
|
|
|
56
|
-
|
|
57
|
-
|
|
82
|
+
```js
|
|
83
|
+
import { executeTestPlan, chromium } from "@jsenv/test"
|
|
58
84
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
+
```
|
|
62
101
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
-
|
|
68
|
-
|
|
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
|
|
69
108
|
```
|
|
70
109
|
|
|
71
|
-
|
|
110
|
+
☝️ Playwright is used by `@jsenv/test` to start a web browser, see [playwright website](https://github.com/microsoft/playwright)<sup>↗</sup>.
|
|
72
111
|
|
|
73
|
-
|
|
112
|
+
Command to execute tests:
|
|
113
|
+
|
|
114
|
+
```console
|
|
115
|
+
node ./scripts/test.mjs
|
|
116
|
+
```
|
|
74
117
|
|
|
75
|
-
|
|
76
|
-
[playwright](https://github.com/microsoft/playwright)<sup>↗</sup> is used to start a headless chromium.
|
|
118
|
+
### 1.3 Executing on more browsers
|
|
77
119
|
|
|
78
120
|
```js
|
|
79
|
-
import { executeTestPlan, chromium } from "@jsenv/test"
|
|
121
|
+
import { executeTestPlan, chromium, firefox, webkit } from "@jsenv/test"
|
|
80
122
|
|
|
81
123
|
await executeTestPlan({
|
|
82
124
|
rootDirectoryUrl: new URL("../", import.meta.url),
|
|
83
125
|
testPlan: {
|
|
84
|
-
"
|
|
85
|
-
chromium: {
|
|
126
|
+
"./src/**/*.test.html": {
|
|
127
|
+
chromium: {
|
|
128
|
+
runtime: chromium(),
|
|
129
|
+
},
|
|
130
|
+
firefox: {
|
|
131
|
+
runtime: firefox(),
|
|
132
|
+
},
|
|
133
|
+
webkit: {
|
|
134
|
+
runtime: webkit(),
|
|
135
|
+
},
|
|
86
136
|
},
|
|
87
137
|
},
|
|
88
138
|
webServer: {
|
|
@@ -93,89 +143,201 @@ await executeTestPlan({
|
|
|
93
143
|
})
|
|
94
144
|
```
|
|
95
145
|
|
|
96
|
-
|
|
146
|
+
# 2. Writing tests on Node.js
|
|
97
147
|
|
|
98
|
-
|
|
148
|
+
This section demonstrates how to write a test that will be executed in Node.js.
|
|
99
149
|
|
|
100
|
-
|
|
150
|
+
The function that will be tested is inside "add.js" file:
|
|
101
151
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
| webServer.rootDirectoryUrl | url of directory served by the web server | `new URL("../src/", import.meta.url)` |
|
|
106
|
-
| webServer.moduleUrl | url of the file responsible to start a web server | `new URL("./dev.mjs", import.meta.url)` |
|
|
152
|
+
```js
|
|
153
|
+
export const add = (a, b) => a + b
|
|
154
|
+
```
|
|
107
155
|
|
|
108
|
-
|
|
156
|
+
The demonstration uses the following file structure:
|
|
109
157
|
|
|
110
158
|
<pre>
|
|
111
159
|
project/
|
|
112
160
|
src/
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
foo.js
|
|
116
|
-
<strong>foo.test.html</strong>
|
|
117
|
-
index.html
|
|
161
|
+
<strong>add.js</strong>
|
|
162
|
+
package.json
|
|
118
163
|
</pre>
|
|
119
164
|
|
|
120
|
-
|
|
165
|
+
At the end of the demo, the file structure will be like this:
|
|
121
166
|
|
|
122
167
|
<pre>
|
|
123
168
|
project/
|
|
169
|
+
scripts/
|
|
170
|
+
<strong>test.mjs</strong>
|
|
124
171
|
src/
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
foo.js
|
|
130
|
-
index.html
|
|
172
|
+
add.js
|
|
173
|
+
tests/
|
|
174
|
+
<strong>add.test.mjs</strong>
|
|
175
|
+
package.json
|
|
131
176
|
</pre>
|
|
132
177
|
|
|
133
|
-
|
|
134
|
-
It's best to configure `webServer` to lead to jsenv dev server but it does not have to; Any server serving files from a directory can be used.
|
|
178
|
+
## 2.1 Writing the test file
|
|
135
179
|
|
|
136
|
-
|
|
180
|
+
_add.test.mjs_
|
|
137
181
|
|
|
138
182
|
```js
|
|
139
|
-
import {
|
|
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"
|
|
140
198
|
|
|
141
199
|
await executeTestPlan({
|
|
142
200
|
rootDirectoryUrl: new URL("../", import.meta.url),
|
|
143
201
|
testPlan: {
|
|
144
|
-
"./
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
202
|
+
"./tests/**/*.test.mjs": {
|
|
203
|
+
node: {
|
|
204
|
+
runtime: nodeWorkerThread(),
|
|
205
|
+
},
|
|
148
206
|
},
|
|
149
207
|
},
|
|
150
|
-
webServer: {
|
|
151
|
-
origin: "http://localhost:3456",
|
|
152
|
-
rootDirectoryUrl: new URL("../src/", import.meta.url),
|
|
153
|
-
moduleUrl: new URL("./dev.mjs", import.meta.url),
|
|
154
|
-
},
|
|
155
208
|
})
|
|
156
209
|
```
|
|
157
210
|
|
|
158
|
-
|
|
211
|
+
Command to install dependencies:
|
|
159
212
|
|
|
160
|
-
|
|
213
|
+
```console
|
|
214
|
+
npm i --save-dev @jsenv/test
|
|
215
|
+
```
|
|
161
216
|
|
|
162
|
-
|
|
163
|
-
import { executeTestPlan, nodeWorkerThread } from "@jsenv/test"
|
|
217
|
+
Command to execute tests:
|
|
164
218
|
|
|
165
|
-
|
|
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({
|
|
166
253
|
rootDirectoryUrl: new URL("../", import.meta.url),
|
|
167
254
|
testPlan: {
|
|
168
|
-
"./
|
|
169
|
-
|
|
255
|
+
"./src/**/*.test.html": {
|
|
256
|
+
chromium: {
|
|
257
|
+
runtime: chromium(),
|
|
258
|
+
},
|
|
259
|
+
firefox: {
|
|
260
|
+
runtime: firefox(),
|
|
261
|
+
},
|
|
262
|
+
webkit: {
|
|
263
|
+
runtime: webkit(),
|
|
264
|
+
},
|
|
170
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,
|
|
171
293
|
},
|
|
172
294
|
})
|
|
295
|
+
report // contains many information about test executions
|
|
173
296
|
```
|
|
174
297
|
|
|
175
|
-
|
|
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
|
|
176
338
|
|
|
177
339
|
Each file is given 30s to execute.
|
|
178
|
-
If this duration is exceeded the browser tab (or node process/worker thread) is closed and
|
|
340
|
+
If this duration is exceeded the browser tab (or node process/worker thread) is closed and execution is considered as failed.
|
|
179
341
|
This duration can be configured as shown below:
|
|
180
342
|
|
|
181
343
|
```js
|
|
@@ -185,16 +347,13 @@ await executeTestPlan({
|
|
|
185
347
|
rootDirectoryUrl: new URL("../", import.meta.url),
|
|
186
348
|
testPlan: {
|
|
187
349
|
"./tests/**/*.test.mjs": {
|
|
188
|
-
node: {
|
|
350
|
+
node: {
|
|
351
|
+
runtime: nodeWorkerThread(),
|
|
352
|
+
allocatedMs: 60_000,
|
|
353
|
+
},
|
|
189
354
|
},
|
|
190
355
|
},
|
|
191
356
|
})
|
|
192
357
|
```
|
|
193
358
|
|
|
194
359
|
☝️ Code above changes the default allocated time to 60s.
|
|
195
|
-
|
|
196
|
-
# 3. Installation
|
|
197
|
-
|
|
198
|
-
```console
|
|
199
|
-
npm install --save-dev @jsenv/test
|
|
200
|
-
```
|
package/dist/jsenv_test.js
CHANGED
|
@@ -3244,7 +3244,7 @@ const createExecutionLog = ({
|
|
|
3244
3244
|
startMs,
|
|
3245
3245
|
endMs
|
|
3246
3246
|
}, {
|
|
3247
|
-
|
|
3247
|
+
logShortForCompletedExecutions,
|
|
3248
3248
|
counters,
|
|
3249
3249
|
logRuntime,
|
|
3250
3250
|
logEachDuration,
|
|
@@ -3267,7 +3267,7 @@ const createExecutionLog = ({
|
|
|
3267
3267
|
memoryHeap
|
|
3268
3268
|
});
|
|
3269
3269
|
let log;
|
|
3270
|
-
if (
|
|
3270
|
+
if (logShortForCompletedExecutions && status === "completed") {
|
|
3271
3271
|
log = `${description}${summary}`;
|
|
3272
3272
|
} else {
|
|
3273
3273
|
const {
|
|
@@ -3300,7 +3300,7 @@ const createExecutionLog = ({
|
|
|
3300
3300
|
wordWrap: false
|
|
3301
3301
|
});
|
|
3302
3302
|
if (endMs) {
|
|
3303
|
-
if (
|
|
3303
|
+
if (logShortForCompletedExecutions) {
|
|
3304
3304
|
return `${log}\n`;
|
|
3305
3305
|
}
|
|
3306
3306
|
if (executionIndex === counters.total - 1) {
|
|
@@ -3608,8 +3608,8 @@ const executeSteps = async (executionSteps, {
|
|
|
3608
3608
|
logTimeUsage,
|
|
3609
3609
|
logMemoryHeapUsage,
|
|
3610
3610
|
logFileRelativeUrl,
|
|
3611
|
-
|
|
3612
|
-
|
|
3611
|
+
logMergeForCompletedExecutions,
|
|
3612
|
+
logShortForCompletedExecutions,
|
|
3613
3613
|
rootDirectoryUrl,
|
|
3614
3614
|
webServer,
|
|
3615
3615
|
keepRunning,
|
|
@@ -3697,9 +3697,9 @@ const executeSteps = async (executionSteps, {
|
|
|
3697
3697
|
coverageMethodForNodeJs,
|
|
3698
3698
|
stopAfterAllSignal
|
|
3699
3699
|
};
|
|
3700
|
-
if (
|
|
3701
|
-
|
|
3702
|
-
logger.debug(`Force
|
|
3700
|
+
if (logMergeForCompletedExecutions && !process.stdout.isTTY) {
|
|
3701
|
+
logMergeForCompletedExecutions = false;
|
|
3702
|
+
logger.debug(`Force logMergeForCompletedExecutions to false because process.stdout.isTTY is false`);
|
|
3703
3703
|
}
|
|
3704
3704
|
const debugLogsEnabled = logger.levels.debug;
|
|
3705
3705
|
const executionLogsEnabled = logger.levels.info;
|
|
@@ -3834,7 +3834,7 @@ const executeSteps = async (executionSteps, {
|
|
|
3834
3834
|
}
|
|
3835
3835
|
if (executionLogsEnabled) {
|
|
3836
3836
|
const log = createExecutionLog(afterExecutionInfo, {
|
|
3837
|
-
|
|
3837
|
+
logShortForCompletedExecutions,
|
|
3838
3838
|
counters,
|
|
3839
3839
|
logRuntime,
|
|
3840
3840
|
logEachDuration,
|
|
@@ -3850,7 +3850,7 @@ const executeSteps = async (executionSteps, {
|
|
|
3850
3850
|
executionLog.write(log);
|
|
3851
3851
|
rawOutput += stripAnsi(log);
|
|
3852
3852
|
const canOverwriteLog = canOverwriteLogGetter({
|
|
3853
|
-
|
|
3853
|
+
logMergeForCompletedExecutions,
|
|
3854
3854
|
executionResult
|
|
3855
3855
|
});
|
|
3856
3856
|
if (canOverwriteLog) {
|
|
@@ -3906,10 +3906,10 @@ const executeSteps = async (executionSteps, {
|
|
|
3906
3906
|
}
|
|
3907
3907
|
};
|
|
3908
3908
|
const canOverwriteLogGetter = ({
|
|
3909
|
-
|
|
3909
|
+
logMergeForCompletedExecutions,
|
|
3910
3910
|
executionResult
|
|
3911
3911
|
}) => {
|
|
3912
|
-
if (!
|
|
3912
|
+
if (!logMergeForCompletedExecutions) {
|
|
3913
3913
|
return false;
|
|
3914
3914
|
}
|
|
3915
3915
|
if (executionResult.status === "aborted") {
|
|
@@ -3974,8 +3974,8 @@ const executeInParallel = async ({
|
|
|
3974
3974
|
* @param {string|url} testPlanParameters.rootDirectoryUrl Directory containing test files;
|
|
3975
3975
|
* @param {Object} [testPlanParameters.webServer] Web server info; required when executing test on browsers
|
|
3976
3976
|
* @param {Object} testPlanParameters.testPlan Object associating files with runtimes where they will be executed
|
|
3977
|
-
* @param {boolean} [testPlanParameters.
|
|
3978
|
-
* @param {boolean} [testPlanParameters.
|
|
3977
|
+
* @param {boolean} [testPlanParameters.logShortForCompletedExecutions=false] Abbreviate completed execution information to shorten terminal output
|
|
3978
|
+
* @param {boolean} [testPlanParameters.logMergeForCompletedExecutions=false] Merge completed execution logs to shorten terminal output
|
|
3979
3979
|
* @param {number} [testPlanParameters.maxExecutionsInParallel=1] Maximum amount of execution in parallel
|
|
3980
3980
|
* @param {number} [testPlanParameters.defaultMsAllocatedPerExecution=30000] Milliseconds after which execution is aborted and considered as failed by timeout
|
|
3981
3981
|
* @param {boolean} [testPlanParameters.failFast=false] Fails immediatly when a test execution fails
|
|
@@ -3996,8 +3996,8 @@ const executeTestPlan = async ({
|
|
|
3996
3996
|
logTimeUsage = false,
|
|
3997
3997
|
logMemoryHeapUsage = false,
|
|
3998
3998
|
logFileRelativeUrl = ".jsenv/test_plan_debug.txt",
|
|
3999
|
-
|
|
4000
|
-
|
|
3999
|
+
logShortForCompletedExecutions = false,
|
|
4000
|
+
logMergeForCompletedExecutions = true,
|
|
4001
4001
|
rootDirectoryUrl,
|
|
4002
4002
|
webServer,
|
|
4003
4003
|
testPlan,
|
|
@@ -4196,8 +4196,8 @@ const executeTestPlan = async ({
|
|
|
4196
4196
|
logTimeUsage,
|
|
4197
4197
|
logMemoryHeapUsage,
|
|
4198
4198
|
logFileRelativeUrl,
|
|
4199
|
-
|
|
4200
|
-
|
|
4199
|
+
logShortForCompletedExecutions,
|
|
4200
|
+
logMergeForCompletedExecutions,
|
|
4201
4201
|
rootDirectoryUrl,
|
|
4202
4202
|
webServer,
|
|
4203
4203
|
maxExecutionsInParallel,
|
|
@@ -4505,7 +4505,7 @@ const createRuntimeUsingPlaywright = ({
|
|
|
4505
4505
|
stopOnExit: true,
|
|
4506
4506
|
playwrightLaunchOptions: {
|
|
4507
4507
|
...playwrightLaunchOptions,
|
|
4508
|
-
headless: !headful
|
|
4508
|
+
headless: headful === undefined ? !keepRunning : !headful
|
|
4509
4509
|
}
|
|
4510
4510
|
});
|
|
4511
4511
|
if (browser._initializer.version) {
|
package/package.json
CHANGED
|
@@ -25,8 +25,8 @@ export const executeSteps = async (
|
|
|
25
25
|
logTimeUsage,
|
|
26
26
|
logMemoryHeapUsage,
|
|
27
27
|
logFileRelativeUrl,
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
logMergeForCompletedExecutions,
|
|
29
|
+
logShortForCompletedExecutions,
|
|
30
30
|
rootDirectoryUrl,
|
|
31
31
|
webServer,
|
|
32
32
|
|
|
@@ -124,10 +124,10 @@ export const executeSteps = async (
|
|
|
124
124
|
stopAfterAllSignal,
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
-
if (
|
|
128
|
-
|
|
127
|
+
if (logMergeForCompletedExecutions && !process.stdout.isTTY) {
|
|
128
|
+
logMergeForCompletedExecutions = false
|
|
129
129
|
logger.debug(
|
|
130
|
-
`Force
|
|
130
|
+
`Force logMergeForCompletedExecutions to false because process.stdout.isTTY is false`,
|
|
131
131
|
)
|
|
132
132
|
}
|
|
133
133
|
const debugLogsEnabled = logger.levels.debug
|
|
@@ -273,7 +273,7 @@ export const executeSteps = async (
|
|
|
273
273
|
}
|
|
274
274
|
if (executionLogsEnabled) {
|
|
275
275
|
const log = createExecutionLog(afterExecutionInfo, {
|
|
276
|
-
|
|
276
|
+
logShortForCompletedExecutions,
|
|
277
277
|
counters,
|
|
278
278
|
logRuntime,
|
|
279
279
|
logEachDuration,
|
|
@@ -292,7 +292,7 @@ export const executeSteps = async (
|
|
|
292
292
|
rawOutput += stripAnsi(log)
|
|
293
293
|
|
|
294
294
|
const canOverwriteLog = canOverwriteLogGetter({
|
|
295
|
-
|
|
295
|
+
logMergeForCompletedExecutions,
|
|
296
296
|
executionResult,
|
|
297
297
|
})
|
|
298
298
|
if (canOverwriteLog) {
|
|
@@ -352,10 +352,10 @@ export const executeSteps = async (
|
|
|
352
352
|
}
|
|
353
353
|
|
|
354
354
|
const canOverwriteLogGetter = ({
|
|
355
|
-
|
|
355
|
+
logMergeForCompletedExecutions,
|
|
356
356
|
executionResult,
|
|
357
357
|
}) => {
|
|
358
|
-
if (!
|
|
358
|
+
if (!logMergeForCompletedExecutions) {
|
|
359
359
|
return false
|
|
360
360
|
}
|
|
361
361
|
if (executionResult.status === "aborted") {
|
|
@@ -21,8 +21,8 @@ import { executeSteps } from "./execute_steps.js"
|
|
|
21
21
|
* @param {string|url} testPlanParameters.rootDirectoryUrl Directory containing test files;
|
|
22
22
|
* @param {Object} [testPlanParameters.webServer] Web server info; required when executing test on browsers
|
|
23
23
|
* @param {Object} testPlanParameters.testPlan Object associating files with runtimes where they will be executed
|
|
24
|
-
* @param {boolean} [testPlanParameters.
|
|
25
|
-
* @param {boolean} [testPlanParameters.
|
|
24
|
+
* @param {boolean} [testPlanParameters.logShortForCompletedExecutions=false] Abbreviate completed execution information to shorten terminal output
|
|
25
|
+
* @param {boolean} [testPlanParameters.logMergeForCompletedExecutions=false] Merge completed execution logs to shorten terminal output
|
|
26
26
|
* @param {number} [testPlanParameters.maxExecutionsInParallel=1] Maximum amount of execution in parallel
|
|
27
27
|
* @param {number} [testPlanParameters.defaultMsAllocatedPerExecution=30000] Milliseconds after which execution is aborted and considered as failed by timeout
|
|
28
28
|
* @param {boolean} [testPlanParameters.failFast=false] Fails immediatly when a test execution fails
|
|
@@ -43,8 +43,8 @@ export const executeTestPlan = async ({
|
|
|
43
43
|
logTimeUsage = false,
|
|
44
44
|
logMemoryHeapUsage = false,
|
|
45
45
|
logFileRelativeUrl = ".jsenv/test_plan_debug.txt",
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
logShortForCompletedExecutions = false,
|
|
47
|
+
logMergeForCompletedExecutions = true,
|
|
48
48
|
|
|
49
49
|
rootDirectoryUrl,
|
|
50
50
|
webServer,
|
|
@@ -293,8 +293,8 @@ export const executeTestPlan = async ({
|
|
|
293
293
|
logTimeUsage,
|
|
294
294
|
logMemoryHeapUsage,
|
|
295
295
|
logFileRelativeUrl,
|
|
296
|
-
|
|
297
|
-
|
|
296
|
+
logShortForCompletedExecutions,
|
|
297
|
+
logMergeForCompletedExecutions,
|
|
298
298
|
rootDirectoryUrl,
|
|
299
299
|
webServer,
|
|
300
300
|
|
|
@@ -21,7 +21,7 @@ export const createExecutionLog = (
|
|
|
21
21
|
endMs,
|
|
22
22
|
},
|
|
23
23
|
{
|
|
24
|
-
|
|
24
|
+
logShortForCompletedExecutions,
|
|
25
25
|
counters,
|
|
26
26
|
logRuntime,
|
|
27
27
|
logEachDuration,
|
|
@@ -43,7 +43,7 @@ export const createExecutionLog = (
|
|
|
43
43
|
memoryHeap,
|
|
44
44
|
})
|
|
45
45
|
let log
|
|
46
|
-
if (
|
|
46
|
+
if (logShortForCompletedExecutions && status === "completed") {
|
|
47
47
|
log = `${description}${summary}`
|
|
48
48
|
} else {
|
|
49
49
|
const { consoleCalls = [], errors = [] } = executionResult
|
|
@@ -75,7 +75,7 @@ export const createExecutionLog = (
|
|
|
75
75
|
wordWrap: false,
|
|
76
76
|
})
|
|
77
77
|
if (endMs) {
|
|
78
|
-
if (
|
|
78
|
+
if (logShortForCompletedExecutions) {
|
|
79
79
|
return `${log}\n`
|
|
80
80
|
}
|
|
81
81
|
if (executionIndex === counters.total - 1) {
|
|
@@ -83,7 +83,7 @@ export const createRuntimeUsingPlaywright = ({
|
|
|
83
83
|
stopOnExit: true,
|
|
84
84
|
playwrightLaunchOptions: {
|
|
85
85
|
...playwrightLaunchOptions,
|
|
86
|
-
headless: !headful,
|
|
86
|
+
headless: headful === undefined ? !keepRunning : !headful,
|
|
87
87
|
},
|
|
88
88
|
})
|
|
89
89
|
if (browser._initializer.version) {
|