@brillout/test-e2e 0.5.29 → 0.5.30

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 (73) hide show
  1. package/dist/Logs/isTolerateError.d.ts +2 -2
  2. package/dist/Logs/isTolerateError.js +5 -11
  3. package/dist/Logs.d.ts +2 -2
  4. package/dist/Logs.js +26 -32
  5. package/dist/TIMEOUTS.js +6 -9
  6. package/dist/autoRetry.js +5 -8
  7. package/dist/buildTs.js +10 -16
  8. package/dist/chai/JestChaiExpect.d.ts +1 -1
  9. package/dist/chai/JestChaiExpect.js +1 -5
  10. package/dist/chai/expect.d.ts +1 -1
  11. package/dist/chai/expect.js +4 -30
  12. package/dist/chai/types.d.ts +4 -4
  13. package/dist/chai/types.js +1 -2
  14. package/dist/cli.js +13 -18
  15. package/dist/editFile.js +15 -21
  16. package/dist/fetch.d.ts +2 -2
  17. package/dist/fetch.js +20 -16
  18. package/dist/findTestFiles.d.ts +1 -1
  19. package/dist/findTestFiles.js +6 -9
  20. package/dist/getBrowser.js +9 -12
  21. package/dist/getConfig.d.ts +1 -1
  22. package/dist/getConfig.js +14 -20
  23. package/dist/getCurrentTest.d.ts +1 -1
  24. package/dist/getCurrentTest.js +15 -21
  25. package/dist/index.d.ts +13 -13
  26. package/dist/index.js +14 -38
  27. package/dist/logError.js +3 -6
  28. package/dist/logSection.js +5 -11
  29. package/dist/logTestStatus.js +19 -25
  30. package/dist/page.js +3 -6
  31. package/dist/parallel-ci.js +8 -14
  32. package/dist/run.js +42 -45
  33. package/dist/runAll.d.ts +1 -1
  34. package/dist/runAll.js +61 -67
  35. package/dist/runCommandThatTerminates.js +6 -9
  36. package/dist/skip.js +3 -6
  37. package/dist/test.js +5 -8
  38. package/dist/testScreenshotFixture.js +42 -45
  39. package/dist/utils/assert.js +23 -26
  40. package/dist/utils/cliOptions.js +9 -12
  41. package/dist/utils/findFiles.d.ts +1 -1
  42. package/dist/utils/findFiles.js +13 -19
  43. package/dist/utils/fsWindowsBugWorkaround.js +2 -5
  44. package/dist/utils/genPromise.js +1 -5
  45. package/dist/utils/hasProp.d.ts +15 -0
  46. package/dist/utils/hasProp.js +50 -0
  47. package/dist/utils/humanizeTime.js +1 -4
  48. package/dist/utils/isArray.d.ts +1 -0
  49. package/dist/utils/isArray.js +4 -0
  50. package/dist/utils/isArrayOfStrings.d.ts +2 -0
  51. package/dist/utils/isArrayOfStrings.js +5 -0
  52. package/dist/utils/isCallable.js +1 -5
  53. package/dist/utils/isMinNodeVersion.js +4 -7
  54. package/dist/utils/isObject.d.ts +1 -1
  55. package/dist/utils/isObject.js +1 -5
  56. package/dist/utils/isObjectOfStrings.d.ts +2 -0
  57. package/dist/utils/isObjectOfStrings.js +5 -0
  58. package/dist/utils/isTTY.js +1 -4
  59. package/dist/utils/logProgress.js +4 -7
  60. package/dist/utils/parseCli.js +3 -6
  61. package/dist/utils/platform.js +6 -9
  62. package/dist/utils/projectInfo.js +1 -4
  63. package/dist/utils/runCommand.js +7 -10
  64. package/dist/utils/runCommandLongRunning.js +40 -32
  65. package/dist/utils/runCommandShortLived.js +7 -10
  66. package/dist/utils/sleep.js +1 -4
  67. package/dist/utils/trackLogs.d.ts +1 -1
  68. package/dist/utils/trackLogs.js +1 -1
  69. package/dist/utils.d.ts +16 -0
  70. package/dist/utils.js +16 -0
  71. package/package.json +3 -2
  72. package/dist/utils/index.d.ts +0 -15
  73. package/dist/utils/index.js +0 -31
package/dist/runAll.js CHANGED
@@ -1,41 +1,35 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.runAll = void 0;
7
- const getCurrentTest_1 = require("./getCurrentTest");
8
- const Logs_1 = require("./Logs");
9
- const utils_1 = require("./utils");
10
- const utils_2 = require("./utils");
11
- const getCurrentTest_2 = require("./getCurrentTest");
12
- const getBrowser_1 = require("./getBrowser");
13
- const buildTs_1 = require("./buildTs");
14
- const findTestFiles_1 = require("./findTestFiles");
15
- const getConfig_1 = require("./getConfig");
16
- const logError_1 = require("./logError");
17
- const logTestStatus_1 = require("./logTestStatus");
18
- const picocolors_1 = __importDefault(require("@brillout/picocolors"));
1
+ export { runAll };
2
+ import { getCurrentTest } from './getCurrentTest.js';
3
+ import { Logs } from './Logs.js';
4
+ import { assert, assertUsage, cliOptions, humanizeTime, isCI, isWindows, logProgress } from './utils.js';
5
+ import { fsWindowsBugWorkaround } from './utils.js';
6
+ import { setCurrentTest } from './getCurrentTest.js';
7
+ import { getBrowser } from './getBrowser.js';
8
+ import { buildTs } from './buildTs.js';
9
+ import { findTestFiles } from './findTestFiles.js';
10
+ import { loadConfig } from './getConfig.js';
11
+ import { logError } from './logError.js';
12
+ import { hasFail, logBoot, logFail, logPass, logWarn, TEST_FAIL } from './logTestStatus.js';
13
+ import pc from '@brillout/picocolors';
19
14
  async function runAll(filter) {
20
- await (0, getConfig_1.loadConfig)();
21
- const testFiles = await (0, findTestFiles_1.findTestFiles)(filter);
22
- const browser = await (0, getBrowser_1.getBrowser)();
15
+ await loadConfig();
16
+ const testFiles = await findTestFiles(filter);
17
+ const browser = await getBrowser();
23
18
  const failedTestFiles = await runTestFiles(testFiles, browser);
24
19
  await browser.close();
25
20
  const hasFailedTestFile = failedTestFiles.length > 0;
26
- const hasFailLog = (0, logTestStatus_1.hasFail)();
21
+ const hasFailLog = hasFail();
27
22
  if (hasFailedTestFile || hasFailLog) {
28
23
  // hasFailedTestFile and hasFailLog are redundant
29
24
  // - When assert.ts calls logFail() this code block isn't run
30
- (0, utils_1.assert)(hasFailedTestFile && hasFailLog);
31
- (0, utils_1.assert)(failedTestFiles.length > 0);
32
- throw new Error(picocolors_1.default.red(picocolors_1.default.bold([
33
- `Following test files failed, see logs above for more information (search for [${logTestStatus_1.TEST_FAIL}]):`,
25
+ assert(hasFailedTestFile && hasFailLog);
26
+ assert(failedTestFiles.length > 0);
27
+ throw new Error(pc.red(pc.bold([
28
+ `Following test files failed, see logs above for more information (search for [${TEST_FAIL}]):`,
34
29
  ...failedTestFiles.map((testFile) => `❌ ${testFile}`),
35
30
  ].join('\n'))));
36
31
  }
37
32
  }
38
- exports.runAll = runAll;
39
33
  async function runTestFiles(testFiles, browser) {
40
34
  // First attempt
41
35
  let failedTestFiles = [];
@@ -47,7 +41,7 @@ async function runTestFiles(testFiles, browser) {
47
41
  if (!isFlaky) {
48
42
  doNotRetry = true;
49
43
  }
50
- if (utils_1.cliOptions.bail) {
44
+ if (cliOptions.bail) {
51
45
  return failedTestFiles;
52
46
  }
53
47
  }
@@ -55,7 +49,7 @@ async function runTestFiles(testFiles, browser) {
55
49
  if (doNotRetry) {
56
50
  return failedTestFiles;
57
51
  }
58
- if (!(0, utils_1.isCI)()) {
52
+ if (!isCI()) {
59
53
  return failedTestFiles;
60
54
  }
61
55
  else {
@@ -73,37 +67,37 @@ async function runTestFiles(testFiles, browser) {
73
67
  }
74
68
  }
75
69
  async function buildAndTest(testFile, browser, isThirdAttempt) {
76
- (0, utils_1.assert)(testFile.endsWith('.ts'));
70
+ assert(testFile.endsWith('.ts'));
77
71
  const cacheBuster = Date.now();
78
72
  const testFileJs = testFile.replace('.ts', `.${cacheBuster}.mjs`);
79
- (0, utils_1.assert)(testFileJs.endsWith('.mjs'));
80
- const cleanBuild = await (0, buildTs_1.buildTs)(testFile, testFileJs);
81
- (0, getCurrentTest_2.setCurrentTest)(testFile);
82
- (0, logTestStatus_1.logBoot)();
73
+ assert(testFileJs.endsWith('.mjs'));
74
+ const cleanBuild = await buildTs(testFile, testFileJs);
75
+ setCurrentTest(testFile);
76
+ logBoot();
83
77
  let execErr;
84
78
  try {
85
- await import((0, utils_2.fsWindowsBugWorkaround)(testFileJs));
79
+ await import(fsWindowsBugWorkaround(testFileJs));
86
80
  }
87
81
  catch (err) {
88
- (0, utils_1.assert)(err);
82
+ assert(err);
89
83
  execErr = err;
90
84
  }
91
85
  finally {
92
86
  cleanBuild();
93
87
  }
94
88
  if (execErr) {
95
- (0, logTestStatus_1.logFail)(`an error was thrown while executing the file ${testFile}`, true);
96
- (0, logError_1.logError)(execErr);
89
+ logFail(`an error was thrown while executing the file ${testFile}`, true);
90
+ logError(execErr);
97
91
  return {
98
92
  success: false,
99
93
  isFlaky: false,
100
94
  };
101
95
  }
102
96
  // When user calls skip()
103
- const testInfo = (0, getCurrentTest_1.getCurrentTest)();
97
+ const testInfo = getCurrentTest();
104
98
  if (testInfo.skipped) {
105
99
  assertSkipUsage(testInfo);
106
- (0, logTestStatus_1.logWarn)(testInfo.skipped.reason);
100
+ logWarn(testInfo.skipped.reason);
107
101
  return {
108
102
  success: true,
109
103
  isFlaky: false,
@@ -111,27 +105,27 @@ async function buildAndTest(testFile, browser, isThirdAttempt) {
111
105
  }
112
106
  else {
113
107
  // Set when user calls run() or runCommandThatTerminates()
114
- (0, utils_1.assert)(testInfo.runInfo);
108
+ assert(testInfo.runInfo);
115
109
  }
116
110
  const { isFlaky } = testInfo.runInfo;
117
111
  // When user calls run runCommandThatTerminates()
118
112
  if (testInfo.runInfo.isRunCommandThatTerminates) {
119
- (0, utils_1.assertUsage)(!testInfo.tests, "Can't call test() when calling runCommandThatTerminates()");
120
- (0, utils_1.assertUsage)(!testInfo.startServer, "Can't call run() when calling runCommandThatTerminates()");
121
- (0, logTestStatus_1.logPass)();
113
+ assertUsage(!testInfo.tests, "Can't call test() when calling runCommandThatTerminates()");
114
+ assertUsage(!testInfo.startServer, "Can't call run() when calling runCommandThatTerminates()");
115
+ logPass();
122
116
  return {
123
117
  success: true,
124
118
  isFlaky,
125
119
  };
126
120
  }
127
121
  const success = await runServerAndTests(browser, isThirdAttempt, isFlaky);
128
- (0, getCurrentTest_2.setCurrentTest)(null);
122
+ setCurrentTest(null);
129
123
  return { success, isFlaky };
130
124
  }
131
125
  async function runServerAndTests(browser, isThirdAttempt, isFlaky) {
132
- const testInfo = (0, getCurrentTest_1.getCurrentTest)();
133
- (0, utils_1.assert)(testInfo.startServer);
134
- (0, utils_1.assert)(testInfo.terminateServer);
126
+ const testInfo = getCurrentTest();
127
+ assert(testInfo.startServer);
128
+ assert(testInfo.terminateServer);
135
129
  const isFinalAttempt = isThirdAttempt || !isFlaky;
136
130
  const page = await browser.newPage();
137
131
  testInfo.page = page;
@@ -148,34 +142,34 @@ async function runServerAndTests(browser, isThirdAttempt, isFlaky) {
148
142
  // Check whether stderr emitted during testInfo.terminateServer()
149
143
  if (success) {
150
144
  const failOnWarning = true;
151
- if (Logs_1.Logs.hasFailLogs(failOnWarning) &&
145
+ if (Logs.hasFailLogs(failOnWarning) &&
152
146
  // See comments about taskkill in src/utils/runCommandLongRunning.ts
153
- !(0, utils_1.isWindows)()) {
147
+ !isWindows()) {
154
148
  logFailure(null, `${getErrorType(failOnWarning)} occurred during server termination`, isFinalAttempt);
155
149
  success = false;
156
150
  }
157
151
  }
158
152
  if (success) {
159
- (0, logTestStatus_1.logPass)();
153
+ logPass();
160
154
  }
161
- Logs_1.Logs.clearLogs();
155
+ Logs.clearLogs();
162
156
  return success;
163
157
  }
164
158
  async function runTests(testInfo, isFinalAttempt) {
165
159
  // Set when user calls run()
166
- (0, utils_1.assert)(testInfo.runInfo);
167
- (0, utils_1.assert)(testInfo.afterEach);
160
+ assert(testInfo.runInfo);
161
+ assert(testInfo.afterEach);
168
162
  const tests =
169
163
  // Set when user calls test()
170
164
  testInfo.tests ??
171
165
  // When user hasn't any test() call
172
166
  [];
173
167
  for (const { testDesc, testFn } of tests) {
174
- Logs_1.Logs.add({
168
+ Logs.add({
175
169
  logSource: 'test()',
176
170
  logText: testDesc,
177
171
  });
178
- const done = (0, utils_1.logProgress)(`[test] ${testDesc}`);
172
+ const done = logProgress(`[test] ${testDesc}`);
179
173
  let err;
180
174
  try {
181
175
  await runTest(testFn, testInfo.runInfo.testFunctionTimeout);
@@ -187,7 +181,7 @@ async function runTests(testInfo, isFinalAttempt) {
187
181
  testInfo.afterEach(!!err);
188
182
  {
189
183
  const failOnWarning = !testInfo.runInfo.doNotFailOnWarning;
190
- const hasErrorLog = Logs_1.Logs.hasFailLogs(failOnWarning);
184
+ const hasErrorLog = Logs.hasFailLogs(failOnWarning);
191
185
  const isFailure = err || hasErrorLog;
192
186
  if (isFailure) {
193
187
  if (err) {
@@ -197,22 +191,22 @@ async function runTests(testInfo, isFinalAttempt) {
197
191
  logFailure(null, `${getErrorType(failOnWarning)} occurred while running the test "${testDesc}"`, isFinalAttempt);
198
192
  }
199
193
  else {
200
- (0, utils_1.assert)(false);
194
+ assert(false);
201
195
  }
202
196
  return false;
203
197
  }
204
198
  }
205
- Logs_1.Logs.clearLogs();
199
+ Logs.clearLogs();
206
200
  }
207
201
  return true;
208
202
  }
209
203
  function logFailure(err, reason, isFinalAttempt) {
210
- (0, logTestStatus_1.logFail)(reason, isFinalAttempt);
204
+ logFail(reason, isFinalAttempt);
211
205
  if (err) {
212
- (0, logError_1.logError)(err);
206
+ logError(err);
213
207
  }
214
- Logs_1.Logs.logErrorsAndWarnings();
215
- Logs_1.Logs.flushLogs();
208
+ Logs.logErrorsAndWarnings();
209
+ Logs.flushLogs();
216
210
  }
217
211
  function getErrorType(failOnWarning) {
218
212
  return !failOnWarning ? 'error(s)' : 'error(s)/warning(s)';
@@ -225,7 +219,7 @@ function runTest(testFn, testFunctionTimeout) {
225
219
  reject = reject_;
226
220
  });
227
221
  const timeout = setTimeout(() => {
228
- reject(new Error(`[test] Timeout after ${(0, utils_1.humanizeTime)(testFunctionTimeout)}`));
222
+ reject(new Error(`[test] Timeout after ${humanizeTime(testFunctionTimeout)}`));
229
223
  }, testFunctionTimeout);
230
224
  const ret = testFn();
231
225
  (async () => {
@@ -243,13 +237,13 @@ function runTest(testFn, testFunctionTimeout) {
243
237
  return promise;
244
238
  }
245
239
  function assertSkipUsage(testInfo) {
246
- (0, utils_1.assert)(testInfo.skipped);
240
+ assert(testInfo.skipped);
247
241
  {
248
242
  const err = 'You cannot call run() after calling skip()';
249
- (0, utils_1.assertUsage)(testInfo.runInfo === undefined, err);
243
+ assertUsage(testInfo.runInfo === undefined, err);
250
244
  }
251
245
  {
252
246
  const err = 'You cannot call test() after calling skip()';
253
- (0, utils_1.assertUsage)(testInfo.tests === undefined, err);
247
+ assertUsage(testInfo.tests === undefined, err);
254
248
  }
255
249
  }
@@ -1,11 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.runCommandThatTerminates = void 0;
4
- const getCurrentTest_1 = require("./getCurrentTest");
5
- const utils_1 = require("./utils");
1
+ export { runCommandThatTerminates };
2
+ import { getCwd, setRunInfo } from './getCurrentTest.js';
3
+ import { runCommand } from './utils.js';
6
4
  async function runCommandThatTerminates(cmd, { timeout = 2 * 60 * 1000 } = {}) {
7
- (0, getCurrentTest_1.setRunInfo)({ cmd, isRunCommandThatTerminates: true });
8
- const cwd = (0, getCurrentTest_1.getCwd)();
9
- await (0, utils_1.runCommand)(cmd, { timeout, cwd });
5
+ setRunInfo({ cmd, isRunCommandThatTerminates: true });
6
+ const cwd = getCwd();
7
+ await runCommand(cmd, { timeout, cwd });
10
8
  }
11
- exports.runCommandThatTerminates = runCommandThatTerminates;
package/dist/skip.js CHANGED
@@ -1,9 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.skip = void 0;
4
- const getCurrentTest_1 = require("./getCurrentTest");
1
+ export { skip };
2
+ import { getCurrentTest } from './getCurrentTest.js';
5
3
  function skip(reason) {
6
- const testInfo = (0, getCurrentTest_1.getCurrentTest)();
4
+ const testInfo = getCurrentTest();
7
5
  testInfo.skipped = { reason };
8
6
  }
9
- exports.skip = skip;
package/dist/test.js CHANGED
@@ -1,15 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.test = void 0;
4
- const utils_1 = require("./utils");
5
- const getCurrentTest_1 = require("./getCurrentTest");
1
+ export { test };
2
+ import { assert } from './utils.js';
3
+ import { getCurrentTest } from './getCurrentTest.js';
6
4
  function test(testDesc, testFn) {
7
- const testInfo = (0, getCurrentTest_1.getCurrentTest)();
8
- (0, utils_1.assert)(!testInfo.hasStartedRunning);
5
+ const testInfo = getCurrentTest();
6
+ assert(!testInfo.hasStartedRunning);
9
7
  testInfo.tests = testInfo.tests ?? [];
10
8
  testInfo.tests.push({
11
9
  testDesc,
12
10
  testFn,
13
11
  });
14
12
  }
15
- exports.test = test;
@@ -1,111 +1,108 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.testScreenshotFixture = void 0;
1
+ export { testScreenshotFixture };
7
2
  // Reference implementation: https://playwright.dev/docs/test-snapshots
8
- const pixelmatch_1 = __importDefault(require("pixelmatch"));
9
- const pngjs_1 = require("pngjs");
10
- const fs_1 = __importDefault(require("fs"));
11
- const path_1 = __importDefault(require("path"));
12
- const utils_1 = require("./utils");
13
- const getCurrentTest_1 = require("./getCurrentTest");
14
- const expect_1 = require("./chai/expect");
15
- const picocolors_1 = __importDefault(require("@brillout/picocolors"));
3
+ import pixelmatch from 'pixelmatch';
4
+ import { PNG } from 'pngjs';
5
+ import fs from 'fs';
6
+ import path from 'path';
7
+ import { assert, isCI, sleep } from './utils.js';
8
+ import { getCurrentTest, getCwd } from './getCurrentTest.js';
9
+ import { expect } from './chai/expect.js';
10
+ import pc from '@brillout/picocolors';
16
11
  async function testScreenshotFixture({ screenshotFixturePath, doNotTestLocally, } = {}) {
17
12
  const pngPaths = getPngPaths();
18
13
  const pngFixturPath = screenshotFixturePath || pngPaths.pngFixturPath;
19
- if (doNotTestLocally && !(0, utils_1.isCI)()) {
20
- console.log(`\n${picocolors_1.default.blue('INFO')} test screenshot fixture ${pngFixturPath} ${picocolors_1.default.bold('skipped')}. (Because ${picocolors_1.default.cyan('doNotTestLocally: true')} and test is being run locally, i.e. not in a CI environment.)`);
14
+ if (doNotTestLocally && !isCI()) {
15
+ console.log(`\n${pc.blue('INFO')} test screenshot fixture ${pngFixturPath} ${pc.bold('skipped')}. (Because ${pc.cyan('doNotTestLocally: true')} and test is being run locally, i.e. not in a CI environment.)`);
21
16
  return;
22
17
  }
23
- const fixtureMissing = !fs_1.default.existsSync(pngFixturPath);
18
+ const fixtureMissing = !fs.existsSync(pngFixturPath);
24
19
  if (fixtureMissing) {
25
20
  const pngActual = await takeScreenshot();
26
- const fileContent = pngjs_1.PNG.sync.write(pngActual);
21
+ const fileContent = PNG.sync.write(pngActual);
27
22
  const { pngExpectPath } = pngPaths;
28
- const filPath = (0, utils_1.isCI)() ? pngExpectPath : pngFixturPath;
29
- fs_1.default.writeFileSync(filPath, fileContent);
23
+ const filPath = isCI() ? pngExpectPath : pngFixturPath;
24
+ fs.writeFileSync(filPath, fileContent);
30
25
  console.log('Expect image written at', pngExpectPath);
31
26
  const errMsgs = [
32
27
  //
33
28
  'Screenshot fixture missing. Screenshot fixture created at:',
34
29
  ` ${filPath}`,
35
30
  ];
36
- if (!(0, utils_1.isCI)()) {
31
+ if (!isCI()) {
37
32
  errMsgs.push('You can now re-run the test and the screenshot fixture test will pass.');
38
33
  }
39
34
  else {
40
35
  errMsgs.push([
41
- 'The screnshot fixture was uploaded as GitHub Workflow Artifact.',
42
- `(See ${picocolors_1.default.bold('Summary')} > ${picocolors_1.default.bold('Artifacts')}, and make sure to use the ${picocolors_1.default.bold('actions/upload-artifact@v3')} action.)`,
36
+ 'The screenshot fixture was uploaded as GitHub Workflow Artifact.',
37
+ `(See ${pc.bold('Summary')} > ${pc.bold('Artifacts')},`,
38
+ `and make sure to use the ${pc.bold('actions/upload-artifact@v3')} action`,
39
+ `otherwise the screenshot won't be uploaded`,
40
+ `and the ${pc.bold('Artifacts')} section will be missing in the ${pc.bold('Summary')} page.)`,
43
41
  `Download the fixture, check it into the repository (so that it lives at ${pngFixturPath}), and try again: the test should now pass.`,
44
42
  ].join(' '));
45
43
  }
46
44
  throw new Error(errMsgs.join('\n'));
47
45
  }
48
- const pngExpect = pngjs_1.PNG.sync.read(fs_1.default.readFileSync(pngFixturPath));
46
+ const pngExpect = PNG.sync.read(fs.readFileSync(pngFixturPath));
49
47
  const pngActual = await takeScreenshot();
50
- (0, expect_1.expect)(pngExpect.width).toBe(pngActual.width);
51
- (0, expect_1.expect)(pngExpect.height).toBe(pngActual.height);
48
+ expect(pngExpect.width).toBe(pngActual.width);
49
+ expect(pngExpect.height).toBe(pngActual.height);
52
50
  const { width, height } = pngExpect;
53
- const pngDiffer = new pngjs_1.PNG({ width, height });
54
- const numDiffPixels = (0, pixelmatch_1.default)(pngExpect.data, pngActual.data, pngDiffer.data, width, height, { threshold: 0.1 });
51
+ const pngDiffer = new PNG({ width, height });
52
+ const numDiffPixels = pixelmatch(pngExpect.data, pngActual.data, pngDiffer.data, width, height, { threshold: 0.1 });
55
53
  try {
56
- (0, expect_1.expect)(numDiffPixels).toBe(0);
54
+ expect(numDiffPixels).toBe(0);
57
55
  }
58
56
  catch (err) {
59
57
  const { pngExpectPath, pngActualPath, pngDifferPath } = pngPaths;
60
58
  {
61
- fs_1.default.writeFileSync(pngActualPath, pngjs_1.PNG.sync.write(pngActual));
59
+ fs.writeFileSync(pngActualPath, PNG.sync.write(pngActual));
62
60
  console.log('Actual image written at', pngActualPath);
63
61
  }
64
62
  {
65
- fs_1.default.writeFileSync(pngExpectPath, pngjs_1.PNG.sync.write(pngExpect));
63
+ fs.writeFileSync(pngExpectPath, PNG.sync.write(pngExpect));
66
64
  console.log('Expect image written at', pngExpectPath);
67
65
  }
68
66
  {
69
- fs_1.default.writeFileSync(pngDifferPath, pngjs_1.PNG.sync.write(pngDiffer));
67
+ fs.writeFileSync(pngDifferPath, PNG.sync.write(pngDiffer));
70
68
  console.log('Differ image written at', pngDifferPath);
71
69
  }
72
70
  throw err;
73
71
  }
74
72
  }
75
- exports.testScreenshotFixture = testScreenshotFixture;
76
73
  async function takeScreenshot() {
77
- const { page } = (0, getCurrentTest_1.getCurrentTest)();
78
- (0, utils_1.assert)(page);
74
+ const { page } = getCurrentTest();
75
+ assert(page);
79
76
  let screenshotCurr;
80
77
  let screenshotPrev;
81
78
  let attemps = 15;
82
79
  while (attemps-- > 0) {
83
80
  screenshotPrev = screenshotCurr;
84
- screenshotCurr = pngjs_1.PNG.sync.read(await page.screenshot());
81
+ screenshotCurr = PNG.sync.read(await page.screenshot());
85
82
  if (screenshotPrev) {
86
83
  const { width, height } = screenshotCurr;
87
- const numDiffPixels = (0, pixelmatch_1.default)(screenshotPrev.data, screenshotCurr.data, null, width, height, {
84
+ const numDiffPixels = pixelmatch(screenshotPrev.data, screenshotCurr.data, null, width, height, {
88
85
  threshold: 0,
89
86
  });
90
87
  if (numDiffPixels === 0) {
91
88
  return screenshotCurr;
92
89
  }
93
90
  }
94
- await (0, utils_1.sleep)(1000);
91
+ await sleep(1000);
95
92
  }
96
93
  throw new Error("Couldn't take a stable screenshot. The UI seems to be continously changing.");
97
94
  }
98
95
  function getPngPaths() {
99
96
  const cwd = getTestFileDir();
100
- const pngFixturPath = path_1.default.join(cwd, './.test-screenshot-fixture.png');
101
- const pngExpectPath = path_1.default.join(cwd, './test-screenshot-expect.png');
102
- const pngActualPath = path_1.default.join(cwd, './test-screenshot-actual.png');
103
- const pngDifferPath = path_1.default.join(cwd, './test-screenshot-differ.png');
97
+ const pngFixturPath = path.join(cwd, './.test-screenshot-fixture.png');
98
+ const pngExpectPath = path.join(cwd, './test-screenshot-expect.png');
99
+ const pngActualPath = path.join(cwd, './test-screenshot-actual.png');
100
+ const pngDifferPath = path.join(cwd, './test-screenshot-differ.png');
104
101
  return { pngFixturPath, pngExpectPath, pngActualPath, pngDifferPath };
105
102
  }
106
103
  function getTestFileDir() {
107
- const { testFile, runInfo } = (0, getCurrentTest_1.getCurrentTest)();
108
- const cwd = path_1.default.dirname(testFile);
109
- (0, utils_1.assert)(cwd === (0, getCurrentTest_1.getCwd)());
104
+ const { testFile, runInfo } = getCurrentTest();
105
+ const cwd = path.dirname(testFile);
106
+ assert(cwd === getCwd());
110
107
  return cwd;
111
108
  }
@@ -1,14 +1,16 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.projectErrorPrefix = exports.getProjectError = exports.assertInfo = exports.assertWarning = exports.assertUsage = exports.assert = void 0;
4
- const projectInfo_1 = require("./projectInfo");
5
- const Logs_1 = require("../Logs");
6
- const getCurrentTest_1 = require("../getCurrentTest");
7
- const logSection_1 = require("../logSection");
8
- const logError_1 = require("../logError");
9
- const logTestStatus_1 = require("../logTestStatus");
10
- const errorPrefix = `[${projectInfo_1.projectInfo.npmPackageName}]`;
11
- exports.projectErrorPrefix = errorPrefix;
1
+ export { assert };
2
+ export { assertUsage };
3
+ export { assertWarning };
4
+ export { assertInfo };
5
+ export { getProjectError };
6
+ export { errorPrefix as projectErrorPrefix };
7
+ import { projectInfo } from './projectInfo.js';
8
+ import { Logs } from '../Logs.js';
9
+ import { getCurrentTest } from '../getCurrentTest.js';
10
+ import { logSection } from '../logSection.js';
11
+ import { logError } from '../logError.js';
12
+ import { logFail } from '../logTestStatus.js';
13
+ const errorPrefix = `[${projectInfo.npmPackageName}]`;
12
14
  const internalErrorPrefix = `${errorPrefix}[Bug]`;
13
15
  const usageErrorPrefix = `${errorPrefix}[Wrong Usage]`;
14
16
  const warningPrefix = `${errorPrefix}[Warning]`;
@@ -22,23 +24,22 @@ function assert(condition, debugInfo) {
22
24
  return '';
23
25
  }
24
26
  const debugInfoSerialized = typeof debugInfo === 'string' ? debugInfo : '`' + JSON.stringify(debugInfo) + '`';
25
- return `Debug info (this is for the ${projectInfo_1.projectInfo.projectName} maintainers; you can ignore this): ${debugInfoSerialized}.`;
27
+ return `Debug info (this is for the ${projectInfo.projectName} maintainers; you can ignore this): ${debugInfoSerialized}.`;
26
28
  })();
27
29
  const internalError = new Error([
28
- `${internalErrorPrefix} You stumbled upon a bug in ${projectInfo_1.projectInfo.projectName}'s source code.`,
29
- `Reach out at ${projectInfo_1.projectInfo.githubRepository}/issues/new and include this error stack (the error stack is usually enough to fix the problem).`,
30
+ `${internalErrorPrefix} You stumbled upon a bug in ${projectInfo.projectName}'s source code.`,
31
+ `Reach out at ${projectInfo.githubRepository}/issues/new and include this error stack (the error stack is usually enough to fix the problem).`,
30
32
  'A maintainer will fix the bug (usually under 24 hours).',
31
- `Do not hesitate to reach out as it makes ${projectInfo_1.projectInfo.projectName} more robust.`,
33
+ `Do not hesitate to reach out as it makes ${projectInfo.projectName} more robust.`,
32
34
  debugStr,
33
35
  ].join(' '));
34
- (0, logTestStatus_1.logFail)('a bug occurred in @brillout/test-e2e', true);
35
- (0, logError_1.logError)(internalError, 'BUG');
36
+ logFail('a bug occurred in @brillout/test-e2e', true);
37
+ logError(internalError, 'BUG');
36
38
  logDebugInfo();
37
- Logs_1.Logs.logErrorsAndWarnings();
38
- Logs_1.Logs.flushLogs();
39
+ Logs.logErrorsAndWarnings();
40
+ Logs.flushLogs();
39
41
  throw new Error('Bug. See messages above.');
40
42
  }
41
- exports.assert = assert;
42
43
  function assertUsage(condition, errorMessage) {
43
44
  if (condition) {
44
45
  return;
@@ -46,12 +47,10 @@ function assertUsage(condition, errorMessage) {
46
47
  const whiteSpace = errorMessage.startsWith('[') ? '' : ' ';
47
48
  throw new Error(`${usageErrorPrefix}${whiteSpace}${errorMessage}`);
48
49
  }
49
- exports.assertUsage = assertUsage;
50
50
  function getProjectError(errorMessage) {
51
51
  const projectError = new Error(`${errorPrefix} ${errorMessage}`);
52
52
  return projectError;
53
53
  }
54
- exports.getProjectError = getProjectError;
55
54
  let loggedWarnings = new Set();
56
55
  function assertWarning(condition, errorMessage, { onlyOnce }) {
57
56
  if (condition) {
@@ -69,17 +68,15 @@ function assertWarning(condition, errorMessage, { onlyOnce }) {
69
68
  }
70
69
  console.warn(msg);
71
70
  }
72
- exports.assertWarning = assertWarning;
73
71
  function assertInfo(condition, errorMessage) {
74
72
  if (condition) {
75
73
  return;
76
74
  }
77
75
  console.warn(`${infoPrefix} ${errorMessage}`);
78
76
  }
79
- exports.assertInfo = assertInfo;
80
77
  function logDebugInfo() {
81
- (0, logSection_1.logSection)('DEBUG INFO');
82
- const testInfo = (0, getCurrentTest_1.getCurrentTest)();
78
+ logSection('DEBUG INFO');
79
+ const testInfo = getCurrentTest();
83
80
  console.log('testInfo.hasStartedRunning', testInfo.hasStartedRunning);
84
81
  console.log('testInfo.skipped?.reason', testInfo.skipped?.reason);
85
82
  console.log('testInfo.runInfo', testInfo.runInfo);
@@ -1,15 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.cliOptions = void 0;
4
- const parseCli_1 = require("./parseCli");
5
- (0, parseCli_1.prepare)();
6
- const verbose = (0, parseCli_1.check)('--verbose');
7
- const inspect = (0, parseCli_1.check)('--inspect');
8
- const debugEsbuild = (0, parseCli_1.check)('--debug-esbuild');
9
- const bail = (0, parseCli_1.check)('--bail');
1
+ export { cliOptions };
2
+ import { check, prepare, validate } from './parseCli.js';
3
+ prepare();
4
+ const verbose = check('--verbose');
5
+ const inspect = check('--inspect');
6
+ const debugEsbuild = check('--debug-esbuild');
7
+ const bail = check('--bail');
10
8
  // Defined & used in ./findFiles.ts
11
- const exclude = (0, parseCli_1.check)('--exclude');
12
- (0, parseCli_1.validate)();
9
+ const exclude = check('--exclude');
10
+ validate();
13
11
  const cliOptions = {
14
12
  verbose,
15
13
  // To inspect a specific test: `$ touch examples/some-example/INSPECT`
@@ -17,4 +15,3 @@ const cliOptions = {
17
15
  debugEsbuild,
18
16
  bail,
19
17
  };
20
- exports.cliOptions = cliOptions;
@@ -2,7 +2,7 @@ export { findFiles };
2
2
  export { findFilesParseCliArgs };
3
3
  export { filterFiles };
4
4
  export type { FindFilter };
5
- declare type FindFilter = {
5
+ type FindFilter = {
6
6
  terms: string[];
7
7
  exclude: boolean;
8
8
  };