@brillout/test-e2e 0.5.23 → 0.5.24

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/Logs.js CHANGED
@@ -92,7 +92,7 @@ function expectLog(logText, logFilter) {
92
92
  const logsFoundWithFilter = logsFound.filter((logEntry) => logFilter?.(removeAnsi(logEntry)));
93
93
  if (logsFoundWithFilter.length === 0) {
94
94
  if (logsFound.length === 0) {
95
- throw new Error(`The following log was expected but wasn't logged: "${logText}"`);
95
+ throw new Error(`The following log was expected but it wasn't logged: "${logText}"`);
96
96
  }
97
97
  else {
98
98
  throw new Error(`The following log was logged as expected, but it didn't match the logFilter() you provided`);
package/dist/buildTs.d.ts CHANGED
@@ -1,4 +1,2 @@
1
1
  export { buildTs };
2
- export { sourceMaps };
3
- declare const sourceMaps: Record<string, string>;
4
2
  declare function buildTs(entry: string, outfile: string): Promise<() => void>;
package/dist/buildTs.js CHANGED
@@ -3,17 +3,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.sourceMaps = exports.buildTs = void 0;
6
+ exports.buildTs = void 0;
7
7
  const esbuild_1 = __importDefault(require("esbuild"));
8
8
  const fs_1 = __importDefault(require("fs"));
9
9
  const utils_1 = require("./utils");
10
- const sourceMaps = {};
11
- exports.sourceMaps = sourceMaps;
12
10
  async function buildTs(entry, outfile) {
13
11
  await esbuild_1.default.build({
14
12
  platform: 'node',
15
13
  entryPoints: [entry],
16
- sourcemap: true,
14
+ sourcemap: 'inline',
17
15
  outfile,
18
16
  logLevel: 'warning',
19
17
  format: 'esm',
@@ -22,17 +20,12 @@ async function buildTs(entry, outfile) {
22
20
  packages: 'external',
23
21
  minify: false,
24
22
  });
25
- {
26
- const sourceMapFile = `${outfile}.map`;
27
- sourceMaps[outfile] = fs_1.default.readFileSync(sourceMapFile, 'utf8');
28
- fs_1.default.unlinkSync(sourceMapFile);
29
- }
30
- const clean = () => {
23
+ const removeBuildFile = () => {
31
24
  if (utils_1.cliOptions.debugEsbuild) {
32
25
  return;
33
26
  }
34
27
  fs_1.default.unlinkSync(`${outfile}`);
35
28
  };
36
- return clean;
29
+ return removeBuildFile;
37
30
  }
38
31
  exports.buildTs = buildTs;
package/dist/cli.js CHANGED
@@ -2,16 +2,10 @@
2
2
  /* Track down log origins
3
3
  import './utils/trackLogs'
4
4
  //*/
5
- var __importDefault = (this && this.__importDefault) || function (mod) {
6
- return (mod && mod.__esModule) ? mod : { "default": mod };
7
- };
8
5
  Object.defineProperty(exports, "__esModule", { value: true });
9
- const source_map_support_1 = __importDefault(require("source-map-support"));
10
6
  const utils_1 = require("./utils");
11
7
  const runAll_1 = require("./runAll");
12
- const buildTs_1 = require("./buildTs");
13
8
  const Logs_1 = require("./Logs");
14
- initSourceMap();
15
9
  initPromiseRejectionHandler();
16
10
  initUserExitHandler();
17
11
  cli();
@@ -30,27 +24,3 @@ function initUserExitHandler() {
30
24
  Logs_1.Logs.flushLogs();
31
25
  });
32
26
  }
33
- // Much simpler alternative: https://github.com/brillout/vite-plugin-ssr/blob/77b1b0e8b6c1ed4efe3e3039f7c0b23a00651663/vite-plugin-ssr/node/plugin/plugins/importUserCode/v1-design/transpileAndLoadFile.ts#L200-L208
34
- function initSourceMap() {
35
- source_map_support_1.default.install({
36
- retrieveSourceMap: function (source) {
37
- const prefix = utils_1.fsWindowsBugWorkaroundPrefix;
38
- if (source.startsWith(prefix)) {
39
- source = source.slice(prefix.length);
40
- if (process.platform == 'win32') {
41
- (0, utils_1.assert)(source.startsWith('/'));
42
- source = source.slice(1);
43
- source = source.split('/').join('\\');
44
- }
45
- }
46
- let sourceMap = buildTs_1.sourceMaps[source];
47
- if (sourceMap) {
48
- return {
49
- map: sourceMap,
50
- };
51
- }
52
- (0, utils_1.assert)(!source.endsWith('.test.mjs'), { source, sourceMapsKeys: Object.keys(buildTs_1.sourceMaps) });
53
- return null;
54
- },
55
- });
56
- }
@@ -3,6 +3,7 @@ export { logWarn };
3
3
  export { logFail };
4
4
  export { logBoot };
5
5
  export { hasFail };
6
+ export declare const TEST_FAIL = "TEST_FAIL";
6
7
  declare function logPass(): void;
7
8
  declare function logWarn(warning: string): void;
8
9
  declare function logFail(reason: string, isFinalAttempt: boolean): void;
@@ -3,7 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.hasFail = exports.logBoot = exports.logFail = exports.logWarn = exports.logPass = void 0;
6
+ exports.TEST_FAIL = exports.hasFail = exports.logBoot = exports.logFail = exports.logWarn = exports.logPass = void 0;
7
+ exports.TEST_FAIL = 'TEST_FAIL';
7
8
  const getCurrentTest_1 = require("./getCurrentTest");
8
9
  const utils_1 = require("./utils");
9
10
  const picocolors_1 = __importDefault(require("@brillout/picocolors"));
@@ -24,7 +25,7 @@ function logFail(reason, isFinalAttempt) {
24
25
  }
25
26
  const { FAIL } = getStatusTags();
26
27
  const color = (s) => picocolors_1.default.red(picocolors_1.default.bold(s));
27
- const msg = `Test ${isFinalAttempt ? FAIL : 'failed'} because ${reason}, see below. [TEST_FAILURE]`;
28
+ const msg = `Test ${isFinalAttempt ? FAIL : 'failed'} because ${reason}, see below. [${exports.TEST_FAIL}]`;
28
29
  console.log(color(msg));
29
30
  }
30
31
  exports.logFail = logFail;
package/dist/runAll.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export { runAll };
2
2
  import { type FindFilter } from './utils';
3
+ import 'source-map-support/register.js';
3
4
  declare function runAll(filter: null | FindFilter): Promise<void>;
package/dist/runAll.js CHANGED
@@ -16,6 +16,7 @@ const getConfig_1 = require("./getConfig");
16
16
  const logError_1 = require("./logError");
17
17
  const logTestStatus_1 = require("./logTestStatus");
18
18
  const picocolors_1 = __importDefault(require("@brillout/picocolors"));
19
+ require("source-map-support/register.js");
19
20
  async function runAll(filter) {
20
21
  await (0, getConfig_1.loadConfig)();
21
22
  const testFiles = await (0, findTestFiles_1.findTestFiles)(filter);
@@ -30,8 +31,8 @@ async function runAll(filter) {
30
31
  (0, utils_1.assert)(hasFailedTestFile && hasFailLog);
31
32
  (0, utils_1.assert)(failedTestFiles.length > 0);
32
33
  throw new Error(picocolors_1.default.red(picocolors_1.default.bold([
33
- 'Following test files failed, see logs above for more information (search for [TEST_FAILURE]):',
34
- ...failedTestFiles.map((testFile) => ` ${testFile}`),
34
+ `Following test files failed, see logs above for more information (search for [${logTestStatus_1.TEST_FAIL}]):`,
35
+ ...failedTestFiles.map((testFile) => `❌ ${testFile}`),
35
36
  ].join('\n'))));
36
37
  }
37
38
  }
@@ -74,21 +75,24 @@ async function runTestFiles(testFiles, browser) {
74
75
  }
75
76
  async function buildAndTest(testFile, browser, isThirdAttempt) {
76
77
  (0, utils_1.assert)(testFile.endsWith('.ts'));
77
- const testFileJs = testFile.replace('.ts', '.mjs');
78
+ const cacheBuster = Date.now();
79
+ const testFileJs = testFile.replace('.ts', `.${cacheBuster}.mjs`);
78
80
  (0, utils_1.assert)(testFileJs.endsWith('.mjs'));
79
- const cleanBuild = await (0, buildTs_1.buildTs)(testFile, testFileJs);
81
+ const removeBuildFile = await (0, buildTs_1.buildTs)(testFile, testFileJs);
80
82
  (0, getCurrentTest_2.setCurrentTest)(testFile);
81
83
  (0, logTestStatus_1.logBoot)();
82
84
  let execErr;
83
85
  try {
84
- await import((0, utils_2.fsWindowsBugWorkaround)(testFileJs) + `?cacheBuster=${Date.now()}`);
86
+ await import((0, utils_2.fsWindowsBugWorkaround)(testFileJs));
85
87
  }
86
88
  catch (err) {
89
+ // Ensure the source map is loaded before we remove testFileJs contains the inline source map
90
+ installSourceMap(err);
87
91
  (0, utils_1.assert)(err);
88
92
  execErr = err;
89
93
  }
90
94
  finally {
91
- cleanBuild();
95
+ removeBuildFile();
92
96
  }
93
97
  if (execErr) {
94
98
  (0, logTestStatus_1.logFail)(`an error was thrown while executing the file ${testFile}`, true);
@@ -252,3 +256,13 @@ function assertSkipUsage(testInfo) {
252
256
  (0, utils_1.assertUsage)(testInfo.tests === undefined, err);
253
257
  }
254
258
  }
259
+ // This tiggers Error.prepareStackTrace() which is needed for the npm package 'source-map-support': the Error.prepareStackTrace() hook of 'source-map-support' needs to be called before the file containing the source map is removed.
260
+ function installSourceMap(err) {
261
+ if ((0, utils_1.isObject)(err)) {
262
+ // Accessing err.stack triggers prepareStackTrace()
263
+ const { stack } = err;
264
+ // Ensure no compiler removes the line above
265
+ if (1 + 1 === 3)
266
+ console.log('I_AM_NEVER_SHOWN' + stack);
267
+ }
268
+ }
@@ -17,7 +17,7 @@ async function testScreenshotFixture({ screenshotFixturePath, doNotTestLocally,
17
17
  const pngPaths = getPngPaths();
18
18
  const pngFixturPath = screenshotFixturePath || pngPaths.pngFixturPath;
19
19
  if (doNotTestLocally && !(0, utils_1.isCI)()) {
20
- console.log(`${picocolors_1.default.blue(picocolors_1.default.bold('INFO'))} screenshot test ${pngFixturPath} skipped because running test locally (i.e. not in a CI environment)`);
20
+ console.log(`\n${picocolors_1.default.blue(picocolors_1.default.bold('INFO'))} screenshot test ${pngFixturPath} skipped because running test locally (i.e. not in a CI environment)`);
21
21
  return;
22
22
  }
23
23
  if (!fs_1.default.existsSync(pngFixturPath)) {
@@ -1,4 +1,2 @@
1
1
  export { fsWindowsBugWorkaround };
2
- export { fsWindowsBugWorkaroundPrefix };
3
- declare const fsWindowsBugWorkaroundPrefix = "file://";
4
2
  declare function fsWindowsBugWorkaround(testFileJs: string): string;
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fsWindowsBugWorkaroundPrefix = exports.fsWindowsBugWorkaround = void 0;
3
+ exports.fsWindowsBugWorkaround = void 0;
4
4
  const fsWindowsBugWorkaroundPrefix = 'file://';
5
- exports.fsWindowsBugWorkaroundPrefix = fsWindowsBugWorkaroundPrefix;
6
5
  // https://stackoverflow.com/questions/69665780/error-err-unsupported-esm-url-scheme-only-file-and-data-urls-are-supported-by/70057245#70057245
7
6
  function fsWindowsBugWorkaround(testFileJs) {
8
7
  return `${fsWindowsBugWorkaroundPrefix}${testFileJs}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brillout/test-e2e",
3
- "version": "0.5.23",
3
+ "version": "0.5.24",
4
4
  "bin": "./bin.js",
5
5
  "main": "./dist/index.js",
6
6
  "scripts": {