@brillout/test-e2e 0.5.24 → 0.5.26

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.
@@ -8,7 +8,7 @@ const getConfig_1 = require("../getConfig");
8
8
  const strip_ansi_1 = __importDefault(require("strip-ansi"));
9
9
  function isTolerateError({ logSource, logText }) {
10
10
  logText = (0, strip_ansi_1.default)(logText);
11
- if (tolerateError({ logSource, logText })) {
11
+ if (tolerateErrorBuiltIn({ logSource, logText })) {
12
12
  return true;
13
13
  }
14
14
  const config = (0, getConfig_1.getConfig)();
@@ -18,20 +18,38 @@ function isTolerateError({ logSource, logText }) {
18
18
  return false;
19
19
  }
20
20
  exports.isTolerateError = isTolerateError;
21
- function tolerateError({ logSource, logText }) {
22
- return isFetchExperimentalWarning() || isTerminationEPIPE();
23
- function isFetchExperimentalWarning() {
24
- return (logSource === 'stderr' &&
25
- logText.includes('ExperimentalWarning: The Fetch API is an experimental feature. This feature could change at any time'));
26
- }
27
- /* Suppress:
28
- ```
29
- [16:00:26.335][/examples/i18n-v1][npm run dev][run()] Terminate server.
30
- [16:00:26.342][/examples/i18n-v1][npm run dev][stderr] The service was stopped: write EPIPE
31
- [16:00:26.342][/examples/i18n-v1][npm run dev][run()] Process termination. (Nominal, exit code: null.)
32
- ```
33
- */
34
- function isTerminationEPIPE() {
35
- return logSource === 'stderr' && logText.includes('The service was stopped: write EPIPE');
36
- }
21
+ function tolerateErrorBuiltIn({ logSource, logText }) {
22
+ return [
23
+ {
24
+ logText: 'ExperimentalWarning: The Fetch API is an experimental feature. This feature could change at any time',
25
+ logSource: 'stderr',
26
+ },
27
+ /* Ignore:
28
+ ```
29
+ [16:00:26.335][/examples/i18n-v1][npm run dev][run()] Terminate server.
30
+ [16:00:26.342][/examples/i18n-v1][npm run dev][stderr] The service was stopped: write EPIPE
31
+ [16:00:26.342][/examples/i18n-v1][npm run dev][run()] Process termination. (Nominal, exit code: null.)
32
+ ``` */
33
+ {
34
+ logText: 'The service was stopped: write EPIPE',
35
+ logSource: 'stderr',
36
+ },
37
+ /* Ignore Chrome logging warning when it cannot do its creepy tracking: https://stackoverflow.com/questions/69619035/error-with-permissions-policy-header-unrecognized-feature-interest-cohort/75119417#75119417
38
+ ```
39
+ [15:57:20.273][/test/abort/test-dev-server.test.ts][npm run dev:server][Browser Warning] {
40
+ "type": "warning",
41
+ "text": "Error with Permissions-Policy header: Origin trial controlled feature not enabled: 'interest-cohort'.",
42
+ "location": {
43
+ "url": "",
44
+ "lineNumber": 0,
45
+ "columnNumber": 0
46
+ },
47
+ "args": []
48
+ }
49
+ ``` */
50
+ {
51
+ logText: 'Error with Permissions-Policy header: Origin trial controlled feature not enabled',
52
+ logSource: 'Browser Warning',
53
+ },
54
+ ].some((l) => l.logSource === logSource && logText.includes(l.logText));
37
55
  }
package/dist/Logs.js CHANGED
@@ -82,21 +82,21 @@ function add({ logSource, logText, loggedAfterExit = false, }) {
82
82
  }
83
83
  }
84
84
  function expectLog(logText, logFilter) {
85
- const logsFound = logEntries.filter((logEntry) => {
85
+ let logsFound = logEntries.filter((logEntry) => {
86
86
  if (removeAnsi(logEntry).logText.includes(logText)) {
87
87
  logEntry.isNotFailure = true;
88
88
  return true;
89
89
  }
90
90
  return false;
91
91
  });
92
- const logsFoundWithFilter = logsFound.filter((logEntry) => logFilter?.(removeAnsi(logEntry)));
93
- if (logsFoundWithFilter.length === 0) {
94
- if (logsFound.length === 0) {
95
- throw new Error(`The following log was expected but it wasn't logged: "${logText}"`);
96
- }
97
- else {
98
- throw new Error(`The following log was logged as expected, but it didn't match the logFilter() you provided`);
99
- }
92
+ if (logsFound.length === 0) {
93
+ throw new Error(`The following log was expected but it wasn't logged: "${logText}"`);
94
+ }
95
+ if (!logFilter)
96
+ return;
97
+ logsFound = logsFound.filter((logEntry) => logFilter(removeAnsi(logEntry)));
98
+ if (logsFound.length === 0) {
99
+ throw new Error(`The following log was logged as expected, but it didn't match the logFilter() you provided: "${logText}"`);
100
100
  }
101
101
  }
102
102
  exports.expectLog = expectLog;
package/dist/buildTs.d.ts CHANGED
@@ -1,2 +1,4 @@
1
1
  export { buildTs };
2
+ export { sourceMaps };
3
+ declare const sourceMaps: Record<string, string>;
2
4
  declare function buildTs(entry: string, outfile: string): Promise<() => void>;
package/dist/buildTs.js CHANGED
@@ -3,15 +3,17 @@ 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.buildTs = void 0;
6
+ exports.sourceMaps = 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;
10
12
  async function buildTs(entry, outfile) {
11
13
  await esbuild_1.default.build({
12
14
  platform: 'node',
13
15
  entryPoints: [entry],
14
- sourcemap: 'inline',
16
+ sourcemap: true,
15
17
  outfile,
16
18
  logLevel: 'warning',
17
19
  format: 'esm',
@@ -20,12 +22,17 @@ async function buildTs(entry, outfile) {
20
22
  packages: 'external',
21
23
  minify: false,
22
24
  });
23
- const removeBuildFile = () => {
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 = () => {
24
31
  if (utils_1.cliOptions.debugEsbuild) {
25
32
  return;
26
33
  }
27
34
  fs_1.default.unlinkSync(`${outfile}`);
28
35
  };
29
- return removeBuildFile;
36
+ return clean;
30
37
  }
31
38
  exports.buildTs = buildTs;
package/dist/cli.js CHANGED
@@ -2,10 +2,16 @@
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
+ };
5
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
+ const source_map_support_1 = __importDefault(require("source-map-support"));
6
10
  const utils_1 = require("./utils");
7
11
  const runAll_1 = require("./runAll");
12
+ const buildTs_1 = require("./buildTs");
8
13
  const Logs_1 = require("./Logs");
14
+ initSourceMap();
9
15
  initPromiseRejectionHandler();
10
16
  initUserExitHandler();
11
17
  cli();
@@ -24,3 +30,29 @@ function initUserExitHandler() {
24
30
  Logs_1.Logs.flushLogs();
25
31
  });
26
32
  }
33
+ // This mechanism seems necessary for the source map to apply for errors that happen a long time after the build file, which contains the inline source map, is removed.
34
+ // - The much simpler alternative used by Vike doesn't seem to work: https://github.com/brillout/vite-plugin-ssr/blob/77b1b0e8b6c1ed4efe3e3039f7c0b23a00651663/vite-plugin-ssr/node/plugin/plugins/importUserCode/v1-design/transpileAndLoadFile.ts#L200-L208
35
+ // - Failed attempt to make the simpler alternative work: https://github.com/brillout/test-e2e/commit/681abd19459b8c7d3ade9363ba32be86e3fdcb53
36
+ function initSourceMap() {
37
+ source_map_support_1.default.install({
38
+ retrieveSourceMap: function (source) {
39
+ const prefix = utils_1.fsWindowsBugWorkaroundPrefix;
40
+ if (source.startsWith(prefix)) {
41
+ source = source.slice(prefix.length);
42
+ if (process.platform == 'win32') {
43
+ (0, utils_1.assert)(source.startsWith('/'));
44
+ source = source.slice(1);
45
+ source = source.split('/').join('\\');
46
+ }
47
+ }
48
+ let sourceMap = buildTs_1.sourceMaps[source];
49
+ if (sourceMap) {
50
+ return {
51
+ map: sourceMap,
52
+ };
53
+ }
54
+ (0, utils_1.assert)(!source.endsWith('.test.mjs'), { source, sourceMapsKeys: Object.keys(buildTs_1.sourceMaps) });
55
+ return null;
56
+ },
57
+ });
58
+ }
package/dist/getConfig.js CHANGED
@@ -16,7 +16,10 @@ function getConfig() {
16
16
  exports.getConfig = getConfig;
17
17
  async function loadConfig() {
18
18
  const configFilePath = find();
19
- (0, utils_1.assertUsage)(configFilePath, `${configFileName} not found`);
19
+ if (!configFilePath) {
20
+ config = {};
21
+ return;
22
+ }
20
23
  const configFileExports = (await import((0, utils_1.fsWindowsBugWorkaround)(configFilePath)));
21
24
  (0, utils_1.assertUsage)('default' in configFileExports, `${configFileName} should have a default export`);
22
25
  assertConfig(configFileExports.default);
package/dist/runAll.d.ts CHANGED
@@ -1,4 +1,3 @@
1
1
  export { runAll };
2
2
  import { type FindFilter } from './utils';
3
- import 'source-map-support/register.js';
4
3
  declare function runAll(filter: null | FindFilter): Promise<void>;
package/dist/runAll.js CHANGED
@@ -16,7 +16,6 @@ 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");
20
19
  async function runAll(filter) {
21
20
  await (0, getConfig_1.loadConfig)();
22
21
  const testFiles = await (0, findTestFiles_1.findTestFiles)(filter);
@@ -78,7 +77,7 @@ async function buildAndTest(testFile, browser, isThirdAttempt) {
78
77
  const cacheBuster = Date.now();
79
78
  const testFileJs = testFile.replace('.ts', `.${cacheBuster}.mjs`);
80
79
  (0, utils_1.assert)(testFileJs.endsWith('.mjs'));
81
- const removeBuildFile = await (0, buildTs_1.buildTs)(testFile, testFileJs);
80
+ const cleanBuild = await (0, buildTs_1.buildTs)(testFile, testFileJs);
82
81
  (0, getCurrentTest_2.setCurrentTest)(testFile);
83
82
  (0, logTestStatus_1.logBoot)();
84
83
  let execErr;
@@ -86,13 +85,11 @@ async function buildAndTest(testFile, browser, isThirdAttempt) {
86
85
  await import((0, utils_2.fsWindowsBugWorkaround)(testFileJs));
87
86
  }
88
87
  catch (err) {
89
- // Ensure the source map is loaded before we remove testFileJs contains the inline source map
90
- installSourceMap(err);
91
88
  (0, utils_1.assert)(err);
92
89
  execErr = err;
93
90
  }
94
91
  finally {
95
- removeBuildFile();
92
+ cleanBuild();
96
93
  }
97
94
  if (execErr) {
98
95
  (0, logTestStatus_1.logFail)(`an error was thrown while executing the file ${testFile}`, true);
@@ -256,13 +253,3 @@ function assertSkipUsage(testInfo) {
256
253
  (0, utils_1.assertUsage)(testInfo.tests === undefined, err);
257
254
  }
258
255
  }
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(`\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)`);
20
+ console.log(`\n${picocolors_1.default.blue('INFO')} screenshot test skipped (because running test locally, i.e. not in a CI environment): ${pngFixturPath}`);
21
21
  return;
22
22
  }
23
23
  if (!fs_1.default.existsSync(pngFixturPath)) {
@@ -1,2 +1,4 @@
1
1
  export { fsWindowsBugWorkaround };
2
+ export { fsWindowsBugWorkaroundPrefix };
3
+ declare const fsWindowsBugWorkaroundPrefix = "file://";
2
4
  declare function fsWindowsBugWorkaround(testFileJs: string): string;
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fsWindowsBugWorkaround = void 0;
3
+ exports.fsWindowsBugWorkaroundPrefix = exports.fsWindowsBugWorkaround = void 0;
4
4
  const fsWindowsBugWorkaroundPrefix = 'file://';
5
+ exports.fsWindowsBugWorkaroundPrefix = fsWindowsBugWorkaroundPrefix;
5
6
  // https://stackoverflow.com/questions/69665780/error-err-unsupported-esm-url-scheme-only-file-and-data-urls-are-supported-by/70057245#70057245
6
7
  function fsWindowsBugWorkaround(testFileJs) {
7
8
  return `${fsWindowsBugWorkaroundPrefix}${testFileJs}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brillout/test-e2e",
3
- "version": "0.5.24",
3
+ "version": "0.5.26",
4
4
  "bin": "./bin.js",
5
5
  "main": "./dist/index.js",
6
6
  "scripts": {