@jsenv/test 1.1.2 → 1.1.4

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.
Files changed (50) hide show
  1. package/dist/jsenv_test.js +4 -2
  2. package/package.json +3 -3
  3. package/src/coverage/babel_plugin_instrument.js +15 -15
  4. package/src/coverage/coverage_reporter_html_directory.js +10 -10
  5. package/src/coverage/coverage_reporter_json_file.js +7 -7
  6. package/src/coverage/coverage_reporter_text_log.js +8 -8
  7. package/src/coverage/empty_coverage_factory.js +24 -24
  8. package/src/coverage/file_by_file_coverage.js +10 -10
  9. package/src/coverage/istanbul_coverage_composition.js +16 -16
  10. package/src/coverage/istanbul_coverage_map_from_coverage.js +8 -8
  11. package/src/coverage/list_files_not_covered.js +4 -4
  12. package/src/coverage/missing_coverage.js +17 -17
  13. package/src/coverage/report_to_coverage.js +52 -52
  14. package/src/coverage/v8_and_istanbul.js +17 -16
  15. package/src/coverage/v8_coverage.js +8 -8
  16. package/src/coverage/v8_coverage_composition.js +12 -12
  17. package/src/coverage/v8_coverage_node_directory.js +42 -42
  18. package/src/coverage/v8_coverage_to_istanbul.js +45 -45
  19. package/src/execution/execute.js +21 -21
  20. package/src/execution/execute_steps.js +129 -129
  21. package/src/execution/execute_test_plan.js +72 -68
  22. package/src/execution/execution_colors.js +2 -2
  23. package/src/execution/execution_steps.js +20 -20
  24. package/src/execution/gc.js +5 -5
  25. package/src/execution/logs_file_execution.js +126 -126
  26. package/src/execution/logs_file_execution.test.mjs +11 -11
  27. package/src/execution/run.js +51 -51
  28. package/src/execution/web_server_param.js +24 -24
  29. package/src/main.js +7 -7
  30. package/src/runtime_browsers/chromium.js +7 -7
  31. package/src/runtime_browsers/firefox.js +10 -10
  32. package/src/runtime_browsers/middleware_istanbul.js +23 -23
  33. package/src/runtime_browsers/middleware_js_supervisor.js +32 -32
  34. package/src/runtime_browsers/using_playwright.js +186 -186
  35. package/src/runtime_browsers/webkit.js +11 -11
  36. package/src/runtime_node/child_exec_options.js +43 -43
  37. package/src/runtime_node/controllable_child_process.mjs +47 -47
  38. package/src/runtime_node/controllable_worker_thread.mjs +37 -37
  39. package/src/runtime_node/exec_options.js +26 -26
  40. package/src/runtime_node/execute_using_dynamic_import.js +26 -26
  41. package/src/runtime_node/exit_codes.js +4 -4
  42. package/src/runtime_node/importmap_node_loader.mjs +24 -24
  43. package/src/runtime_node/importmap_node_loader_file_url.js +1 -1
  44. package/src/runtime_node/kill_process_tree.js +30 -30
  45. package/src/runtime_node/no_experimental_warnings.cjs +4 -4
  46. package/src/runtime_node/no_experimental_warnings_file_url.js +1 -1
  47. package/src/runtime_node/node_child_process.js +128 -128
  48. package/src/runtime_node/node_execution_performance.js +28 -28
  49. package/src/runtime_node/node_worker_thread.js +108 -108
  50. package/src/runtime_node/profiler_v8_coverage.js +21 -21
@@ -1,13 +1,13 @@
1
- import wrapAnsi from "wrap-ansi"
1
+ import wrapAnsi from "wrap-ansi";
2
2
  import {
3
3
  ANSI,
4
4
  UNICODE,
5
5
  msAsEllapsedTime,
6
6
  msAsDuration,
7
7
  byteAsMemoryUsage,
8
- } from "@jsenv/log"
8
+ } from "@jsenv/log";
9
9
 
10
- import { EXECUTION_COLORS } from "./execution_colors.js"
10
+ import { EXECUTION_COLORS } from "./execution_colors.js";
11
11
 
12
12
  export const createExecutionLog = (
13
13
  {
@@ -29,26 +29,26 @@ export const createExecutionLog = (
29
29
  memoryHeap,
30
30
  },
31
31
  ) => {
32
- const { status } = executionResult
33
- const descriptionFormatter = descriptionFormatters[status]
32
+ const { status } = executionResult;
33
+ const descriptionFormatter = descriptionFormatters[status];
34
34
  const description = descriptionFormatter({
35
35
  index: executionIndex,
36
36
  total: counters.total,
37
37
  executionParams,
38
- })
38
+ });
39
39
  const summary = createIntermediateSummary({
40
40
  executionIndex,
41
41
  counters,
42
42
  timeEllapsed,
43
43
  memoryHeap,
44
- })
45
- let log
44
+ });
45
+ let log;
46
46
  if (logShortForCompletedExecutions && status === "completed") {
47
- log = `${description}${summary}`
47
+ log = `${description}${summary}`;
48
48
  } else {
49
- const { consoleCalls = [], errors = [] } = executionResult
50
- const consoleOutput = formatConsoleCalls(consoleCalls)
51
- const errorsOutput = formatErrors(errors)
49
+ const { consoleCalls = [], errors = [] } = executionResult;
50
+ const consoleOutput = formatConsoleCalls(consoleCalls);
51
+ const errorsOutput = formatErrors(errors);
52
52
  log = formatExecution({
53
53
  label: `${description}${summary}`,
54
54
  details: {
@@ -65,40 +65,40 @@ export const createExecutionLog = (
65
65
  },
66
66
  consoleOutput,
67
67
  errorsOutput,
68
- })
68
+ });
69
69
  }
70
70
 
71
- const { columns = 80 } = process.stdout
71
+ const { columns = 80 } = process.stdout;
72
72
  log = wrapAnsi(log, columns, {
73
73
  trim: false,
74
74
  hard: true,
75
75
  wordWrap: false,
76
- })
76
+ });
77
77
  if (endMs) {
78
78
  if (logShortForCompletedExecutions) {
79
- return `${log}\n`
79
+ return `${log}\n`;
80
80
  }
81
81
  if (executionIndex === counters.total - 1) {
82
- return `${log}\n`
82
+ return `${log}\n`;
83
83
  }
84
- return `${log}\n\n`
84
+ return `${log}\n\n`;
85
85
  }
86
- return log
87
- }
86
+ return log;
87
+ };
88
88
 
89
89
  const formatErrors = (errors) => {
90
90
  if (errors.length === 0) {
91
- return ""
91
+ return "";
92
92
  }
93
- const formatError = (error) => error.stack || error.message || error
93
+ const formatError = (error) => error.stack || error.message || error;
94
94
 
95
95
  if (errors.length === 1) {
96
96
  return `${ANSI.color(`-------- error --------`, ANSI.RED)}
97
97
  ${formatError(errors[0])}
98
- ${ANSI.color(`-------------------------`, ANSI.RED)}`
98
+ ${ANSI.color(`-------------------------`, ANSI.RED)}`;
99
99
  }
100
100
 
101
- let output = []
101
+ let output = [];
102
102
  errors.forEach((error) => {
103
103
  output.push(
104
104
  prefixFirstAndIndentRemainingLines({
@@ -106,30 +106,30 @@ ${ANSI.color(`-------------------------`, ANSI.RED)}`
106
106
  indentation: " ",
107
107
  text: formatError(error),
108
108
  }),
109
- )
110
- })
109
+ );
110
+ });
111
111
  return `${ANSI.color(`-------- errors (${errors.length}) --------`, ANSI.RED)}
112
112
  ${output.join(`\n`)}
113
- ${ANSI.color(`-------------------------`, ANSI.RED)}`
114
- }
113
+ ${ANSI.color(`-------------------------`, ANSI.RED)}`;
114
+ };
115
115
 
116
116
  export const createSummaryLog = (
117
117
  summary,
118
118
  ) => `-------------- summary -----------------
119
119
  ${createAllExecutionsSummary(summary)}
120
120
  total duration: ${msAsDuration(summary.duration)}
121
- ----------------------------------------`
121
+ ----------------------------------------`;
122
122
 
123
123
  const createAllExecutionsSummary = ({ counters }) => {
124
124
  if (counters.total === 0) {
125
- return `no execution`
125
+ return `no execution`;
126
126
  }
127
127
  const executionLabel =
128
- counters.total === 1 ? `1 execution` : `${counters.total} executions`
128
+ counters.total === 1 ? `1 execution` : `${counters.total} executions`;
129
129
  return `${executionLabel}: ${createStatusSummary({
130
130
  counters,
131
- })}`
132
- }
131
+ })}`;
132
+ };
133
133
 
134
134
  const createIntermediateSummary = ({
135
135
  executionIndex,
@@ -137,7 +137,7 @@ const createIntermediateSummary = ({
137
137
  memoryHeap,
138
138
  timeEllapsed,
139
139
  }) => {
140
- const parts = []
140
+ const parts = [];
141
141
  if (executionIndex > 0 || counters.done > 0) {
142
142
  parts.push(
143
143
  createStatusSummary({
@@ -146,55 +146,55 @@ const createIntermediateSummary = ({
146
146
  total: executionIndex + 1,
147
147
  },
148
148
  }),
149
- )
149
+ );
150
150
  }
151
151
  if (timeEllapsed) {
152
- parts.push(`duration: ${msAsEllapsedTime(timeEllapsed)}`)
152
+ parts.push(`duration: ${msAsEllapsedTime(timeEllapsed)}`);
153
153
  }
154
154
  if (memoryHeap) {
155
- parts.push(`memory heap: ${byteAsMemoryUsage(memoryHeap)}`)
155
+ parts.push(`memory heap: ${byteAsMemoryUsage(memoryHeap)}`);
156
156
  }
157
157
  if (parts.length === 0) {
158
- return ""
158
+ return "";
159
159
  }
160
- return ` (${parts.join(` / `)})`
161
- }
160
+ return ` (${parts.join(` / `)})`;
161
+ };
162
162
 
163
163
  const createStatusSummary = ({ counters }) => {
164
164
  if (counters.aborted === counters.total) {
165
- return `all ${ANSI.color(`aborted`, EXECUTION_COLORS.aborted)}`
165
+ return `all ${ANSI.color(`aborted`, EXECUTION_COLORS.aborted)}`;
166
166
  }
167
167
  if (counters.timedout === counters.total) {
168
- return `all ${ANSI.color(`timed out`, EXECUTION_COLORS.timedout)}`
168
+ return `all ${ANSI.color(`timed out`, EXECUTION_COLORS.timedout)}`;
169
169
  }
170
170
  if (counters.failed === counters.total) {
171
- return `all ${ANSI.color(`failed`, EXECUTION_COLORS.failed)}`
171
+ return `all ${ANSI.color(`failed`, EXECUTION_COLORS.failed)}`;
172
172
  }
173
173
  if (counters.completed === counters.total) {
174
- return `all ${ANSI.color(`completed`, EXECUTION_COLORS.completed)}`
174
+ return `all ${ANSI.color(`completed`, EXECUTION_COLORS.completed)}`;
175
175
  }
176
176
  if (counters.cancelled === counters.total) {
177
- return `all ${ANSI.color(`cancelled`, EXECUTION_COLORS.cancelled)}`
177
+ return `all ${ANSI.color(`cancelled`, EXECUTION_COLORS.cancelled)}`;
178
178
  }
179
179
  return createMixedDetails({
180
180
  counters,
181
- })
182
- }
181
+ });
182
+ };
183
183
 
184
184
  const createMixedDetails = ({ counters }) => {
185
- const parts = []
185
+ const parts = [];
186
186
  if (counters.timedout) {
187
187
  parts.push(
188
188
  `${counters.timedout} ${ANSI.color(
189
189
  `timed out`,
190
190
  EXECUTION_COLORS.timedout,
191
191
  )}`,
192
- )
192
+ );
193
193
  }
194
194
  if (counters.failed) {
195
195
  parts.push(
196
196
  `${counters.failed} ${ANSI.color(`failed`, EXECUTION_COLORS.failed)}`,
197
- )
197
+ );
198
198
  }
199
199
  if (counters.completed) {
200
200
  parts.push(
@@ -202,12 +202,12 @@ const createMixedDetails = ({ counters }) => {
202
202
  `completed`,
203
203
  EXECUTION_COLORS.completed,
204
204
  )}`,
205
- )
205
+ );
206
206
  }
207
207
  if (counters.aborted) {
208
208
  parts.push(
209
209
  `${counters.aborted} ${ANSI.color(`aborted`, EXECUTION_COLORS.aborted)}`,
210
- )
210
+ );
211
211
  }
212
212
  if (counters.cancelled) {
213
213
  parts.push(
@@ -215,17 +215,17 @@ const createMixedDetails = ({ counters }) => {
215
215
  `cancelled`,
216
216
  EXECUTION_COLORS.cancelled,
217
217
  )}`,
218
- )
218
+ );
219
219
  }
220
- return `${parts.join(", ")}`
221
- }
220
+ return `${parts.join(", ")}`;
221
+ };
222
222
 
223
223
  const descriptionFormatters = {
224
224
  executing: ({ index, total }) => {
225
225
  return ANSI.color(
226
226
  `executing ${padNumber(index, total)} of ${total}`,
227
227
  EXECUTION_COLORS.executing,
228
- )
228
+ );
229
229
  },
230
230
  aborted: ({ index, total }) => {
231
231
  return ANSI.color(
@@ -234,7 +234,7 @@ const descriptionFormatters = {
234
234
  total,
235
235
  )} of ${total} aborted`,
236
236
  EXECUTION_COLORS.aborted,
237
- )
237
+ );
238
238
  },
239
239
  timedout: ({ index, total, executionParams }) => {
240
240
  return ANSI.color(
@@ -243,7 +243,7 @@ const descriptionFormatters = {
243
243
  total,
244
244
  )} of ${total} timeout after ${executionParams.allocatedMs}ms`,
245
245
  EXECUTION_COLORS.timedout,
246
- )
246
+ );
247
247
  },
248
248
  failed: ({ index, total }) => {
249
249
  return ANSI.color(
@@ -252,7 +252,7 @@ const descriptionFormatters = {
252
252
  total,
253
253
  )} of ${total} failed`,
254
254
  EXECUTION_COLORS.failed,
255
- )
255
+ );
256
256
  },
257
257
  completed: ({ index, total }) => {
258
258
  return ANSI.color(
@@ -261,7 +261,7 @@ const descriptionFormatters = {
261
261
  total,
262
262
  )} of ${total} completed`,
263
263
  EXECUTION_COLORS.completed,
264
- )
264
+ );
265
265
  },
266
266
  cancelled: ({ index, total }) => {
267
267
  return ANSI.color(
@@ -270,26 +270,26 @@ const descriptionFormatters = {
270
270
  total,
271
271
  )} of ${total} cancelled`,
272
272
  EXECUTION_COLORS.cancelled,
273
- )
273
+ );
274
274
  },
275
- }
275
+ };
276
276
 
277
277
  const padNumber = (index, total) => {
278
- const number = index + 1
279
- const numberWidth = String(number).length
280
- const totalWith = String(total).length
281
- let missingWidth = totalWith - numberWidth
282
- let padded = ""
278
+ const number = index + 1;
279
+ const numberWidth = String(number).length;
280
+ const totalWith = String(total).length;
281
+ let missingWidth = totalWith - numberWidth;
282
+ let padded = "";
283
283
  while (missingWidth--) {
284
- padded += "0"
284
+ padded += "0";
285
285
  }
286
- padded += number
287
- return padded
288
- }
286
+ padded += number;
287
+ return padded;
288
+ };
289
289
 
290
290
  const formatConsoleCalls = (consoleCalls) => {
291
291
  if (consoleCalls.length === 0) {
292
- return ""
292
+ return "";
293
293
  }
294
294
  const repartition = {
295
295
  debug: 0,
@@ -297,61 +297,61 @@ const formatConsoleCalls = (consoleCalls) => {
297
297
  warning: 0,
298
298
  error: 0,
299
299
  log: 0,
300
- }
300
+ };
301
301
  consoleCalls.forEach((consoleCall) => {
302
- repartition[consoleCall.type]++
303
- })
304
- const consoleOutput = formatConsoleOutput(consoleCalls)
302
+ repartition[consoleCall.type]++;
303
+ });
304
+ const consoleOutput = formatConsoleOutput(consoleCalls);
305
305
 
306
306
  return `${ANSI.color(
307
307
  `-------- ${formatConsoleSummary(repartition)} --------`,
308
308
  ANSI.GREY,
309
309
  )}
310
310
  ${consoleOutput}
311
- ${ANSI.color(`-------------------------`, ANSI.GREY)}`
312
- }
311
+ ${ANSI.color(`-------------------------`, ANSI.GREY)}`;
312
+ };
313
313
 
314
314
  export const formatConsoleOutput = (consoleCalls) => {
315
315
  // inside Node.js you can do process.stdout.write()
316
316
  // and in that case the consoleCall is not suffixed with "\n"
317
317
  // we want to keep these calls together in the output
318
- const regroupedCalls = []
318
+ const regroupedCalls = [];
319
319
  consoleCalls.forEach((consoleCall, index) => {
320
320
  if (index === 0) {
321
- regroupedCalls.push(consoleCall)
322
- return
321
+ regroupedCalls.push(consoleCall);
322
+ return;
323
323
  }
324
- const previousCall = consoleCalls[index - 1]
324
+ const previousCall = consoleCalls[index - 1];
325
325
  if (previousCall.type !== consoleCall.type) {
326
- regroupedCalls.push(consoleCall)
327
- return
326
+ regroupedCalls.push(consoleCall);
327
+ return;
328
328
  }
329
329
  if (previousCall.text.endsWith("\n")) {
330
- regroupedCalls.push(consoleCall)
331
- return
330
+ regroupedCalls.push(consoleCall);
331
+ return;
332
332
  }
333
333
  if (previousCall.text.endsWith("\r")) {
334
- regroupedCalls.push(consoleCall)
335
- return
334
+ regroupedCalls.push(consoleCall);
335
+ return;
336
336
  }
337
- const previousRegroupedCallIndex = regroupedCalls.length - 1
338
- const previousRegroupedCall = regroupedCalls[previousRegroupedCallIndex]
339
- previousRegroupedCall.text = `${previousRegroupedCall.text}${consoleCall.text}`
340
- })
337
+ const previousRegroupedCallIndex = regroupedCalls.length - 1;
338
+ const previousRegroupedCall = regroupedCalls[previousRegroupedCallIndex];
339
+ previousRegroupedCall.text = `${previousRegroupedCall.text}${consoleCall.text}`;
340
+ });
341
341
 
342
- let consoleOutput = ``
342
+ let consoleOutput = ``;
343
343
  regroupedCalls.forEach((regroupedCall, index) => {
344
- const text = regroupedCall.text
344
+ const text = regroupedCall.text;
345
345
  const textFormatted = prefixFirstAndIndentRemainingLines({
346
346
  prefix: CONSOLE_ICONS[regroupedCall.type],
347
347
  text,
348
348
  trimLines: true,
349
349
  trimLastLine: index === regroupedCalls.length - 1,
350
- })
351
- consoleOutput += textFormatted
352
- })
353
- return consoleOutput
354
- }
350
+ });
351
+ consoleOutput += textFormatted;
352
+ });
353
+ return consoleOutput;
354
+ };
355
355
 
356
356
  const prefixFirstAndIndentRemainingLines = ({
357
357
  prefix,
@@ -360,21 +360,21 @@ const prefixFirstAndIndentRemainingLines = ({
360
360
  trimLines,
361
361
  trimLastLine,
362
362
  }) => {
363
- const lines = text.split(/\r?\n/)
364
- const firstLine = lines.shift()
365
- let result = `${prefix} ${firstLine}`
366
- let i = 0
363
+ const lines = text.split(/\r?\n/);
364
+ const firstLine = lines.shift();
365
+ let result = `${prefix} ${firstLine}`;
366
+ let i = 0;
367
367
  while (i < lines.length) {
368
- const line = trimLines ? lines[i].trim() : lines[i]
369
- i++
368
+ const line = trimLines ? lines[i].trim() : lines[i];
369
+ i++;
370
370
  result += line.length
371
371
  ? `\n${indentation}${line}`
372
372
  : trimLastLine && i === lines.length
373
373
  ? ""
374
- : `\n`
374
+ : `\n`;
375
375
  }
376
- return result
377
- }
376
+ return result;
377
+ };
378
378
 
379
379
  const CONSOLE_ICONS = {
380
380
  debug: UNICODE.DEBUG,
@@ -382,28 +382,28 @@ const CONSOLE_ICONS = {
382
382
  warning: UNICODE.WARNING,
383
383
  error: UNICODE.FAILURE,
384
384
  log: " ",
385
- }
385
+ };
386
386
 
387
387
  const formatConsoleSummary = (repartition) => {
388
- const { debug, info, warning, error } = repartition
389
- const parts = []
388
+ const { debug, info, warning, error } = repartition;
389
+ const parts = [];
390
390
  if (error) {
391
- parts.push(`${CONSOLE_ICONS.error} ${error}`)
391
+ parts.push(`${CONSOLE_ICONS.error} ${error}`);
392
392
  }
393
393
  if (warning) {
394
- parts.push(`${CONSOLE_ICONS.warning} ${warning}`)
394
+ parts.push(`${CONSOLE_ICONS.warning} ${warning}`);
395
395
  }
396
396
  if (info) {
397
- parts.push(`${CONSOLE_ICONS.info} ${info}`)
397
+ parts.push(`${CONSOLE_ICONS.info} ${info}`);
398
398
  }
399
399
  if (debug) {
400
- parts.push(`${CONSOLE_ICONS.debug} ${debug}`)
400
+ parts.push(`${CONSOLE_ICONS.debug} ${debug}`);
401
401
  }
402
402
  if (parts.length === 0) {
403
- return `console`
403
+ return `console`;
404
404
  }
405
- return `console (${parts.join(" ")})`
406
- }
405
+ return `console (${parts.join(" ")})`;
406
+ };
407
407
 
408
408
  const formatExecution = ({
409
409
  label,
@@ -411,17 +411,17 @@ const formatExecution = ({
411
411
  consoleOutput,
412
412
  errorsOutput,
413
413
  }) => {
414
- let message = ``
415
- message += label
414
+ let message = ``;
415
+ message += label;
416
416
  Object.keys(details).forEach((key) => {
417
417
  message += `
418
- ${key}: ${details[key]}`
419
- })
418
+ ${key}: ${details[key]}`;
419
+ });
420
420
  if (consoleOutput) {
421
- message += `\n${consoleOutput}`
421
+ message += `\n${consoleOutput}`;
422
422
  }
423
423
  if (errorsOutput) {
424
- message += `\n${errorsOutput}`
424
+ message += `\n${errorsOutput}`;
425
425
  }
426
- return message
427
- }
426
+ return message;
427
+ };
@@ -1,24 +1,24 @@
1
- import { assert } from "@jsenv/assert"
1
+ import { assert } from "@jsenv/assert";
2
2
 
3
- import { formatConsoleOutput } from "./logs_file_execution.js"
3
+ import { formatConsoleOutput } from "./logs_file_execution.js";
4
4
 
5
5
  {
6
6
  const actual = formatConsoleOutput([
7
7
  { type: "log", text: "a\n" },
8
8
  { type: "log", text: "b\n" },
9
- ])
9
+ ]);
10
10
  const expected = ` a
11
- b`
12
- assert({ actual, expected })
11
+ b`;
12
+ assert({ actual, expected });
13
13
  }
14
14
 
15
15
  {
16
16
  const actual = formatConsoleOutput([
17
17
  { type: "log", text: "a" },
18
18
  { type: "log", text: "b" },
19
- ])
20
- const expected = ` ab`
21
- assert({ actual, expected })
19
+ ]);
20
+ const expected = ` ab`;
21
+ assert({ actual, expected });
22
22
  }
23
23
 
24
24
  {
@@ -33,9 +33,9 @@ import { formatConsoleOutput } from "./logs_file_execution.js"
33
33
  text: `alpha
34
34
  beta`,
35
35
  },
36
- ])
36
+ ]);
37
37
  const expected = ` 1
38
38
  2alpha
39
- beta`
40
- assert({ actual, expected })
39
+ beta`;
40
+ assert({ actual, expected });
41
41
  }