@jsenv/test 3.0.3 → 3.0.5

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.
@@ -138,6 +138,7 @@ const executeUsingDynamicImport = async ({
138
138
  }) => {
139
139
  const result = {
140
140
  timings: {
141
+ origin: Date.now(),
141
142
  start: null,
142
143
  end: null,
143
144
  },
@@ -187,7 +188,7 @@ const executeUsingDynamicImport = async ({
187
188
  };
188
189
  }
189
190
 
190
- result.timings.start = Date.now();
191
+ result.timings.start = Date.now() - result.timings.origin;
191
192
  try {
192
193
  const namespace = await import(fileUrl);
193
194
  const namespaceResolved = {};
@@ -203,7 +204,7 @@ const executeUsingDynamicImport = async ({
203
204
  result.status = "failed";
204
205
  result.errors.push(createException(e, { rootDirectoryUrl }));
205
206
  } finally {
206
- result.timings.end = Date.now();
207
+ result.timings.end = Date.now() - result.timings.origin;
207
208
  if (finalizeCoverage) {
208
209
  await finalizeCoverage();
209
210
  finalizeCoverage = null;
@@ -4552,14 +4552,17 @@ const run = async ({
4552
4552
  allocatedMs = 0;
4553
4553
  }
4554
4554
 
4555
- const timingOrigin = Date.now();
4555
+ const timingsOrigin = Date.now();
4556
+ const takeTiming = () => {
4557
+ return Date.now() - timingsOrigin;
4558
+ };
4556
4559
  const result = {
4557
4560
  status: "pending",
4558
4561
  errors: [],
4559
4562
  namespace: null,
4560
4563
  consoleCalls: null,
4561
4564
  timings: {
4562
- origin: timingOrigin,
4565
+ origin: timingsOrigin,
4563
4566
  start: 0,
4564
4567
  runtimeStart: null,
4565
4568
  executionStart: null,
@@ -4571,9 +4574,6 @@ const run = async ({
4571
4574
  performance: null,
4572
4575
  coverageFileUrl: null,
4573
4576
  };
4574
- const takeTiming = (ms = Date.now()) => {
4575
- return ms - timingOrigin;
4576
- };
4577
4577
  const onConsoleRef = { current: () => {} };
4578
4578
  const stopSignal = { notify: () => {} };
4579
4579
  const runtimeLabel = `${runtime.name}/${runtime.version}`;
@@ -4684,12 +4684,15 @@ const run = async ({
4684
4684
  result.errors.push(errorProxy);
4685
4685
  }
4686
4686
  result.namespace = namespace;
4687
- if (timings) {
4688
- if (timings.start) {
4689
- result.timings.executionStart = Math.max(takeTiming(timings.start), 0);
4690
- }
4691
- if (timings.end) {
4692
- result.timings.executionEnd = Math.max(takeTiming(timings.end), 0);
4687
+ if (timings && typeof timings.start === "number") {
4688
+ const diff = timings.origin - result.timings.origin;
4689
+ result.timings.executionStart = timings.start + diff;
4690
+ result.timings.executionEnd = timings.end + diff;
4691
+
4692
+ if (result.timings.executionStart < result.timings.runtimeStart) {
4693
+ // can happen for browsers where navigationStart can be earlier
4694
+ // than when node.js calls runtimeStarted()
4695
+ result.timings.runtimeStart = result.timings.executionStart;
4693
4696
  }
4694
4697
  }
4695
4698
  result.memoryUsage =
@@ -6434,7 +6437,6 @@ To fix this warning:
6434
6437
  promises.push(promise);
6435
6438
  }
6436
6439
 
6437
- console.log(cpuUsage.overall.active, parallel.maxCpu);
6438
6440
  if (cpuUsage.overall.active > parallel.maxCpu) {
6439
6441
  // retry after Xms in case cpu usage decreases
6440
6442
  const promise = (async () => {
@@ -7042,7 +7044,7 @@ ${webServer.rootDirectoryUrl}`);
7042
7044
  if (memoryUsageAPIAvailable) {
7043
7045
  const getMemoryUsage = async () => {
7044
7046
  const memoryUsage = await page.evaluate(
7045
- /* eslint-disable no-undef */
7047
+ /* eslint-env browser */
7046
7048
  /* istanbul ignore next */
7047
7049
  async () => {
7048
7050
  const { performance } = window;
@@ -7057,7 +7059,7 @@ ${webServer.rootDirectoryUrl}`);
7057
7059
  // https://developer.mozilla.org/en-US/docs/Web/API/Performance/measureUserAgentSpecificMemory
7058
7060
  if (
7059
7061
  performance.measureUserAgentSpecificMemory &&
7060
- crossOriginIsolated
7062
+ window.crossOriginIsolated
7061
7063
  ) {
7062
7064
  const memorySample =
7063
7065
  await performance.measureUserAgentSpecificMemory();
@@ -7065,7 +7067,7 @@ ${webServer.rootDirectoryUrl}`);
7065
7067
  }
7066
7068
  return null;
7067
7069
  },
7068
- /* eslint-enable no-undef */
7070
+ /* eslint-env node */
7069
7071
  );
7070
7072
  return memoryUsage;
7071
7073
  };
@@ -7084,7 +7086,7 @@ ${webServer.rootDirectoryUrl}`);
7084
7086
  if (collectPerformance) {
7085
7087
  callbackSet.add(async () => {
7086
7088
  const performance = await page.evaluate(
7087
- /* eslint-disable no-undef */
7089
+ /* eslint-env browser */
7088
7090
  /* istanbul ignore next */
7089
7091
  () => {
7090
7092
  const { performance } = window;
@@ -7103,7 +7105,7 @@ ${webServer.rootDirectoryUrl}`);
7103
7105
  measures,
7104
7106
  };
7105
7107
  },
7106
- /* eslint-enable no-undef */
7108
+ /* eslint-env node */
7107
7109
  );
7108
7110
  result.performance = performance;
7109
7111
  });
@@ -7176,15 +7178,9 @@ ${webServer.rootDirectoryUrl}`);
7176
7178
  try {
7177
7179
  await page.goto(fileServerUrl, { timeout: 0 });
7178
7180
  const returnValue = await page.evaluate(
7179
- /* eslint-disable no-undef */
7181
+ /* eslint-env browser */
7180
7182
  /* istanbul ignore next */
7181
7183
  async () => {
7182
- let startTime;
7183
- try {
7184
- startTime = window.performance.timing.navigationStart;
7185
- } catch (e) {
7186
- startTime = Date.now();
7187
- }
7188
7184
  if (!window.__supervisor__) {
7189
7185
  throw new Error("window.__supervisor__ is undefined");
7190
7186
  }
@@ -7192,15 +7188,12 @@ ${webServer.rootDirectoryUrl}`);
7192
7188
  await window.__supervisor__.getDocumentExecutionResult();
7193
7189
  return {
7194
7190
  type: "window_supervisor",
7195
- timings: {
7196
- start: startTime,
7197
- end: Date.now(),
7198
- },
7191
+ timings: executionResultFromJsenvSupervisor.timings,
7199
7192
  executionResults:
7200
7193
  executionResultFromJsenvSupervisor.executionResults,
7201
7194
  };
7202
7195
  },
7203
- /* eslint-enable no-undef */
7196
+ /* eslint-env node */
7204
7197
  );
7205
7198
  cb(returnValue);
7206
7199
  } catch (e) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/test",
3
- "version": "3.0.3",
3
+ "version": "3.0.5",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -43,7 +43,7 @@
43
43
  "@jsenv/github-check-run": "0.1.8",
44
44
  "@jsenv/inspect": "2.0.0",
45
45
  "@jsenv/log": "3.5.2",
46
- "@jsenv/plugin-supervisor": "1.4.1",
46
+ "@jsenv/plugin-supervisor": "1.4.2",
47
47
  "@jsenv/url-meta": "8.4.0",
48
48
  "@jsenv/urls": "2.2.2",
49
49
  "@jsenv/utils": "2.1.1",
@@ -853,7 +853,6 @@ To fix this warning:
853
853
  promises.push(promise);
854
854
  }
855
855
 
856
- console.log(cpuUsage.overall.active, parallel.maxCpu);
857
856
  if (cpuUsage.overall.active > parallel.maxCpu) {
858
857
  // retry after Xms in case cpu usage decreases
859
858
  const promise = (async () => {
@@ -38,14 +38,17 @@ export const run = async ({
38
38
  allocatedMs = 0;
39
39
  }
40
40
 
41
- const timingOrigin = Date.now();
41
+ const timingsOrigin = Date.now();
42
+ const takeTiming = () => {
43
+ return Date.now() - timingsOrigin;
44
+ };
42
45
  const result = {
43
46
  status: "pending",
44
47
  errors: [],
45
48
  namespace: null,
46
49
  consoleCalls: null,
47
50
  timings: {
48
- origin: timingOrigin,
51
+ origin: timingsOrigin,
49
52
  start: 0,
50
53
  runtimeStart: null,
51
54
  executionStart: null,
@@ -57,9 +60,6 @@ export const run = async ({
57
60
  performance: null,
58
61
  coverageFileUrl: null,
59
62
  };
60
- const takeTiming = (ms = Date.now()) => {
61
- return ms - timingOrigin;
62
- };
63
63
  const onConsoleRef = { current: () => {} };
64
64
  const stopSignal = { notify: () => {} };
65
65
  const runtimeLabel = `${runtime.name}/${runtime.version}`;
@@ -170,12 +170,15 @@ export const run = async ({
170
170
  result.errors.push(errorProxy);
171
171
  }
172
172
  result.namespace = namespace;
173
- if (timings) {
174
- if (timings.start) {
175
- result.timings.executionStart = Math.max(takeTiming(timings.start), 0);
176
- }
177
- if (timings.end) {
178
- result.timings.executionEnd = Math.max(takeTiming(timings.end), 0);
173
+ if (timings && typeof timings.start === "number") {
174
+ const diff = timings.origin - result.timings.origin;
175
+ result.timings.executionStart = timings.start + diff;
176
+ result.timings.executionEnd = timings.end + diff;
177
+
178
+ if (result.timings.executionStart < result.timings.runtimeStart) {
179
+ // can happen for browsers where navigationStart can be earlier
180
+ // than when node.js calls runtimeStarted()
181
+ result.timings.runtimeStart = result.timings.executionStart;
179
182
  }
180
183
  }
181
184
  result.memoryUsage =
@@ -275,7 +275,7 @@ ${webServer.rootDirectoryUrl}`);
275
275
  if (memoryUsageAPIAvailable) {
276
276
  const getMemoryUsage = async () => {
277
277
  const memoryUsage = await page.evaluate(
278
- /* eslint-disable no-undef */
278
+ /* eslint-env browser */
279
279
  /* istanbul ignore next */
280
280
  async () => {
281
281
  const { performance } = window;
@@ -290,7 +290,7 @@ ${webServer.rootDirectoryUrl}`);
290
290
  // https://developer.mozilla.org/en-US/docs/Web/API/Performance/measureUserAgentSpecificMemory
291
291
  if (
292
292
  performance.measureUserAgentSpecificMemory &&
293
- crossOriginIsolated
293
+ window.crossOriginIsolated
294
294
  ) {
295
295
  const memorySample =
296
296
  await performance.measureUserAgentSpecificMemory();
@@ -298,7 +298,7 @@ ${webServer.rootDirectoryUrl}`);
298
298
  }
299
299
  return null;
300
300
  },
301
- /* eslint-enable no-undef */
301
+ /* eslint-env node */
302
302
  );
303
303
  return memoryUsage;
304
304
  };
@@ -317,7 +317,7 @@ ${webServer.rootDirectoryUrl}`);
317
317
  if (collectPerformance) {
318
318
  callbackSet.add(async () => {
319
319
  const performance = await page.evaluate(
320
- /* eslint-disable no-undef */
320
+ /* eslint-env browser */
321
321
  /* istanbul ignore next */
322
322
  () => {
323
323
  const { performance } = window;
@@ -336,7 +336,7 @@ ${webServer.rootDirectoryUrl}`);
336
336
  measures,
337
337
  };
338
338
  },
339
- /* eslint-enable no-undef */
339
+ /* eslint-env node */
340
340
  );
341
341
  result.performance = performance;
342
342
  });
@@ -409,15 +409,9 @@ ${webServer.rootDirectoryUrl}`);
409
409
  try {
410
410
  await page.goto(fileServerUrl, { timeout: 0 });
411
411
  const returnValue = await page.evaluate(
412
- /* eslint-disable no-undef */
412
+ /* eslint-env browser */
413
413
  /* istanbul ignore next */
414
414
  async () => {
415
- let startTime;
416
- try {
417
- startTime = window.performance.timing.navigationStart;
418
- } catch (e) {
419
- startTime = Date.now();
420
- }
421
415
  if (!window.__supervisor__) {
422
416
  throw new Error("window.__supervisor__ is undefined");
423
417
  }
@@ -425,15 +419,12 @@ ${webServer.rootDirectoryUrl}`);
425
419
  await window.__supervisor__.getDocumentExecutionResult();
426
420
  return {
427
421
  type: "window_supervisor",
428
- timings: {
429
- start: startTime,
430
- end: Date.now(),
431
- },
422
+ timings: executionResultFromJsenvSupervisor.timings,
432
423
  executionResults:
433
424
  executionResultFromJsenvSupervisor.executionResults,
434
425
  };
435
426
  },
436
- /* eslint-enable no-undef */
427
+ /* eslint-env node */
437
428
  );
438
429
  cb(returnValue);
439
430
  } catch (e) {
@@ -17,6 +17,7 @@ export const executeUsingDynamicImport = async ({
17
17
  }) => {
18
18
  const result = {
19
19
  timings: {
20
+ origin: Date.now(),
20
21
  start: null,
21
22
  end: null,
22
23
  },
@@ -66,7 +67,7 @@ export const executeUsingDynamicImport = async ({
66
67
  };
67
68
  }
68
69
 
69
- result.timings.start = Date.now();
70
+ result.timings.start = Date.now() - result.timings.origin;
70
71
  try {
71
72
  const namespace = await import(fileUrl);
72
73
  const namespaceResolved = {};
@@ -82,7 +83,7 @@ export const executeUsingDynamicImport = async ({
82
83
  result.status = "failed";
83
84
  result.errors.push(createException(e, { rootDirectoryUrl }));
84
85
  } finally {
85
- result.timings.end = Date.now();
86
+ result.timings.end = Date.now() - result.timings.origin;
86
87
  if (finalizeCoverage) {
87
88
  await finalizeCoverage();
88
89
  finalizeCoverage = null;