@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/getConfig.js CHANGED
@@ -1,37 +1,31 @@
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.loadConfig = exports.getConfig = void 0;
7
- const path_1 = __importDefault(require("path"));
8
- const fs_1 = __importDefault(require("fs"));
9
- const utils_1 = require("./utils");
1
+ export { getConfig };
2
+ export { loadConfig };
3
+ import path from 'path';
4
+ import fs from 'fs';
5
+ import { assert, assertUsage, fsWindowsBugWorkaround, isCallable, isObject } from './utils.js';
10
6
  const configFileName = 'test-e2e.config.mjs';
11
7
  let config = null;
12
8
  function getConfig() {
13
- (0, utils_1.assert)(config);
9
+ assert(config);
14
10
  return config;
15
11
  }
16
- exports.getConfig = getConfig;
17
12
  async function loadConfig() {
18
13
  const configFilePath = find();
19
14
  if (!configFilePath) {
20
15
  config = {};
21
16
  return;
22
17
  }
23
- const configFileExports = (await import((0, utils_1.fsWindowsBugWorkaround)(configFilePath)));
24
- (0, utils_1.assertUsage)('default' in configFileExports, `${configFileName} should have a default export`);
18
+ const configFileExports = (await import(fsWindowsBugWorkaround(configFilePath)));
19
+ assertUsage('default' in configFileExports, `${configFileName} should have a default export`);
25
20
  assertConfig(configFileExports.default);
26
21
  config = configFileExports.default;
27
22
  }
28
- exports.loadConfig = loadConfig;
29
23
  function assertConfig(config) {
30
- (0, utils_1.assertUsage)((0, utils_1.isObject)(config), `${configFileName} default export should be an object`);
24
+ assertUsage(isObject(config), `${configFileName} default export should be an object`);
31
25
  Object.entries(config).forEach(([key, val]) => {
32
26
  const wrongType = `${configFileName} export default { ${key} } should be a`;
33
27
  if (key === 'tolerateError') {
34
- (0, utils_1.assertUsage)((0, utils_1.isCallable)(val), `${wrongType} function`);
28
+ assertUsage(isCallable(val), `${wrongType} function`);
35
29
  }
36
30
  else if (key === 'ci') {
37
31
  // Only used by .github/workflows/ci/getTestJobs.mjs
@@ -39,19 +33,19 @@ function assertConfig(config) {
39
33
  return;
40
34
  }
41
35
  else {
42
- (0, utils_1.assertUsage)(false, `${configFileName} unknown config ${key}`);
36
+ assertUsage(false, `${configFileName} unknown config ${key}`);
43
37
  }
44
38
  });
45
39
  }
46
40
  function find() {
47
41
  let dir = process.cwd();
48
42
  while (true) {
49
- const configFilePath = path_1.default.join(dir, configFileName);
50
- if (fs_1.default.existsSync(configFilePath)) {
43
+ const configFilePath = path.join(dir, configFileName);
44
+ if (fs.existsSync(configFilePath)) {
51
45
  return configFilePath;
52
46
  }
53
47
  const dirPrevious = dir;
54
- dir = path_1.default.dirname(dir);
48
+ dir = path.dirname(dir);
55
49
  if (dir === dirPrevious) {
56
50
  return null;
57
51
  }
@@ -7,7 +7,7 @@ export { getCwd };
7
7
  export { getServerUrl };
8
8
  export type { TestInfo };
9
9
  import type { Page } from 'playwright-chromium';
10
- declare type TestInfo = {
10
+ type TestInfo = {
11
11
  testFile: string;
12
12
  testName: string;
13
13
  tests?: {
@@ -1,23 +1,22 @@
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.getServerUrl = exports.getCwd = exports.setRunInfo = exports.getRunInfo = exports.setCurrentTest = exports.getCurrentTestOptional = exports.getCurrentTest = void 0;
7
- const utils_1 = require("./utils");
8
- const path_1 = __importDefault(require("path"));
9
- const TIMEOUTS_1 = require("./TIMEOUTS");
1
+ export { getCurrentTest };
2
+ export { getCurrentTestOptional };
3
+ export { setCurrentTest };
4
+ export { getRunInfo };
5
+ export { setRunInfo };
6
+ export { getCwd };
7
+ export { getServerUrl };
8
+ import { assert } from './utils.js';
9
+ import path from 'path';
10
+ import { TIMEOUT_TEST_FUNCTION } from './TIMEOUTS.js';
10
11
  let testInfo = null;
11
12
  function getCurrentTest() {
12
13
  if (!testInfo)
13
14
  throw new Error('testInfo missing');
14
15
  return testInfo;
15
16
  }
16
- exports.getCurrentTest = getCurrentTest;
17
17
  function getCurrentTestOptional() {
18
18
  return testInfo;
19
19
  }
20
- exports.getCurrentTestOptional = getCurrentTestOptional;
21
20
  function setCurrentTest(testFile) {
22
21
  if (testFile) {
23
22
  testInfo = {
@@ -29,11 +28,10 @@ function setCurrentTest(testFile) {
29
28
  testInfo = null;
30
29
  }
31
30
  }
32
- exports.setCurrentTest = setCurrentTest;
33
31
  function getTestName(testFile) {
34
32
  const pathRelative = removeRootDir(testFile);
35
33
  if (testFile.includes('examples')) {
36
- return path_1.default.dirname(pathRelative);
34
+ return path.dirname(pathRelative);
37
35
  }
38
36
  else {
39
37
  return pathRelative;
@@ -41,19 +39,18 @@ function getTestName(testFile) {
41
39
  }
42
40
  function removeRootDir(filePath) {
43
41
  const rootDir = process.cwd();
44
- (0, utils_1.assert)(filePath.startsWith(rootDir));
42
+ assert(filePath.startsWith(rootDir));
45
43
  return filePath.slice(rootDir.length);
46
44
  }
47
45
  function getRunInfo() {
48
46
  const testInfo = getCurrentTest();
49
- (0, utils_1.assert)(testInfo.runInfo);
47
+ assert(testInfo.runInfo);
50
48
  return testInfo.runInfo;
51
49
  }
52
- exports.getRunInfo = getRunInfo;
53
50
  const serverUrlDefault = 'http://localhost:3000';
54
51
  function setRunInfo({ cmd, serverUrl = serverUrlDefault, additionalTimeout = 0, doNotFailOnWarning = false, isFlaky = false, isRunCommandThatTerminates = false, }) {
55
52
  const testInfo = getCurrentTest();
56
- const testFunctionTimeout = TIMEOUTS_1.TIMEOUT_TEST_FUNCTION + additionalTimeout;
53
+ const testFunctionTimeout = TIMEOUT_TEST_FUNCTION + additionalTimeout;
57
54
  testInfo.runInfo = {
58
55
  cmd,
59
56
  serverUrl,
@@ -63,16 +60,13 @@ function setRunInfo({ cmd, serverUrl = serverUrlDefault, additionalTimeout = 0,
63
60
  isRunCommandThatTerminates,
64
61
  };
65
62
  }
66
- exports.setRunInfo = setRunInfo;
67
63
  function getCwd() {
68
64
  const { testFile } = getCurrentTest();
69
- const cwd = path_1.default.dirname(testFile);
65
+ const cwd = path.dirname(testFile);
70
66
  return cwd;
71
67
  }
72
- exports.getCwd = getCwd;
73
68
  function getServerUrl() {
74
69
  const testInfo = getCurrentTest();
75
70
  const serverUrl = testInfo.runInfo?.serverUrl;
76
71
  return serverUrl;
77
72
  }
78
- exports.getServerUrl = getServerUrl;
package/dist/index.d.ts CHANGED
@@ -1,14 +1,14 @@
1
- export { expect } from './chai/expect';
2
- export { test } from './test';
3
- export { page } from './page';
4
- export { editFile, editFileRevert } from './editFile';
5
- export { testScreenshotFixture } from './testScreenshotFixture';
1
+ export { expect } from './chai/expect.js';
2
+ export { test } from './test.js';
3
+ export { page } from './page.js';
4
+ export { editFile, editFileRevert } from './editFile.js';
5
+ export { testScreenshotFixture } from './testScreenshotFixture.js';
6
6
  export { partRegex } from '@brillout/part-regex';
7
- export { autoRetry } from './autoRetry';
8
- export { fetch, fetchHtml } from './fetch';
9
- export { expectLog } from './Logs';
10
- export { run } from './run';
11
- export { skip } from './skip';
12
- export { isMinNodeVersion, isCI, isLinux, isWindows, isMac, sleep } from './utils';
13
- export { getServerUrl } from './getCurrentTest';
14
- export { runCommandThatTerminates } from './runCommandThatTerminates';
7
+ export { autoRetry } from './autoRetry.js';
8
+ export { fetch, fetchHtml } from './fetch.js';
9
+ export { expectLog } from './Logs.js';
10
+ export { run } from './run.js';
11
+ export { skip } from './skip.js';
12
+ export { isMinNodeVersion, isCI, isLinux, isWindows, isMac, sleep } from './utils.js';
13
+ export { getServerUrl } from './getCurrentTest.js';
14
+ export { runCommandThatTerminates } from './runCommandThatTerminates.js';
package/dist/index.js CHANGED
@@ -1,38 +1,14 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.runCommandThatTerminates = exports.getServerUrl = exports.sleep = exports.isMac = exports.isWindows = exports.isLinux = exports.isCI = exports.isMinNodeVersion = exports.skip = exports.run = exports.expectLog = exports.fetchHtml = exports.fetch = exports.autoRetry = exports.partRegex = exports.testScreenshotFixture = exports.editFileRevert = exports.editFile = exports.page = exports.test = exports.expect = void 0;
4
- var expect_1 = require("./chai/expect");
5
- Object.defineProperty(exports, "expect", { enumerable: true, get: function () { return expect_1.expect; } });
6
- var test_1 = require("./test");
7
- Object.defineProperty(exports, "test", { enumerable: true, get: function () { return test_1.test; } });
8
- var page_1 = require("./page");
9
- Object.defineProperty(exports, "page", { enumerable: true, get: function () { return page_1.page; } });
10
- var editFile_1 = require("./editFile");
11
- Object.defineProperty(exports, "editFile", { enumerable: true, get: function () { return editFile_1.editFile; } });
12
- Object.defineProperty(exports, "editFileRevert", { enumerable: true, get: function () { return editFile_1.editFileRevert; } });
13
- var testScreenshotFixture_1 = require("./testScreenshotFixture");
14
- Object.defineProperty(exports, "testScreenshotFixture", { enumerable: true, get: function () { return testScreenshotFixture_1.testScreenshotFixture; } });
15
- var part_regex_1 = require("@brillout/part-regex");
16
- Object.defineProperty(exports, "partRegex", { enumerable: true, get: function () { return part_regex_1.partRegex; } });
17
- var autoRetry_1 = require("./autoRetry");
18
- Object.defineProperty(exports, "autoRetry", { enumerable: true, get: function () { return autoRetry_1.autoRetry; } });
19
- var fetch_1 = require("./fetch");
20
- Object.defineProperty(exports, "fetch", { enumerable: true, get: function () { return fetch_1.fetch; } });
21
- Object.defineProperty(exports, "fetchHtml", { enumerable: true, get: function () { return fetch_1.fetchHtml; } });
22
- var Logs_1 = require("./Logs");
23
- Object.defineProperty(exports, "expectLog", { enumerable: true, get: function () { return Logs_1.expectLog; } });
24
- var run_1 = require("./run");
25
- Object.defineProperty(exports, "run", { enumerable: true, get: function () { return run_1.run; } });
26
- var skip_1 = require("./skip");
27
- Object.defineProperty(exports, "skip", { enumerable: true, get: function () { return skip_1.skip; } });
28
- var utils_1 = require("./utils");
29
- Object.defineProperty(exports, "isMinNodeVersion", { enumerable: true, get: function () { return utils_1.isMinNodeVersion; } });
30
- Object.defineProperty(exports, "isCI", { enumerable: true, get: function () { return utils_1.isCI; } });
31
- Object.defineProperty(exports, "isLinux", { enumerable: true, get: function () { return utils_1.isLinux; } });
32
- Object.defineProperty(exports, "isWindows", { enumerable: true, get: function () { return utils_1.isWindows; } });
33
- Object.defineProperty(exports, "isMac", { enumerable: true, get: function () { return utils_1.isMac; } });
34
- Object.defineProperty(exports, "sleep", { enumerable: true, get: function () { return utils_1.sleep; } });
35
- var getCurrentTest_1 = require("./getCurrentTest");
36
- Object.defineProperty(exports, "getServerUrl", { enumerable: true, get: function () { return getCurrentTest_1.getServerUrl; } });
37
- var runCommandThatTerminates_1 = require("./runCommandThatTerminates");
38
- Object.defineProperty(exports, "runCommandThatTerminates", { enumerable: true, get: function () { return runCommandThatTerminates_1.runCommandThatTerminates; } });
1
+ export { expect } from './chai/expect.js';
2
+ export { test } from './test.js';
3
+ export { page } from './page.js';
4
+ export { editFile, editFileRevert } from './editFile.js';
5
+ export { testScreenshotFixture } from './testScreenshotFixture.js';
6
+ export { partRegex } from '@brillout/part-regex';
7
+ export { autoRetry } from './autoRetry.js';
8
+ export { fetch, fetchHtml } from './fetch.js';
9
+ export { expectLog } from './Logs.js';
10
+ export { run } from './run.js';
11
+ export { skip } from './skip.js';
12
+ export { isMinNodeVersion, isCI, isLinux, isWindows, isMac, sleep } from './utils.js';
13
+ export { getServerUrl } from './getCurrentTest.js';
14
+ export { runCommandThatTerminates } from './runCommandThatTerminates.js';
package/dist/logError.js CHANGED
@@ -1,9 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.logError = void 0;
4
- const logSection_1 = require("./logSection");
1
+ export { logError };
2
+ import { logSection } from './logSection.js';
5
3
  function logError(err, sectionTitle = 'ERROR') {
6
- (0, logSection_1.logSection)(sectionTitle);
4
+ logSection(sectionTitle);
7
5
  console.log(err);
8
6
  }
9
- exports.logError = logError;
@@ -1,15 +1,9 @@
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.logSection = void 0;
7
- const picocolors_1 = __importDefault(require("@brillout/picocolors"));
1
+ export { logSection };
2
+ import pc from '@brillout/picocolors';
8
3
  function logSection(sectionTitle) {
9
4
  const title = `vvvvvv ${sectionTitle} vvvvvv`;
10
5
  const width = title.length;
11
- console.log(picocolors_1.default.bold('v'.repeat(width)));
12
- console.log(picocolors_1.default.bold(title));
13
- console.log(picocolors_1.default.bold('v'.repeat(width)));
6
+ console.log(pc.bold('v'.repeat(width)));
7
+ console.log(pc.bold(title));
8
+ console.log(pc.bold('v'.repeat(width)));
14
9
  }
15
- exports.logSection = logSection;
@@ -1,21 +1,18 @@
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.TEST_FAIL = exports.hasFail = exports.logBoot = exports.logFail = exports.logWarn = exports.logPass = void 0;
7
- exports.TEST_FAIL = 'TEST_FAIL';
8
- const getCurrentTest_1 = require("./getCurrentTest");
9
- const utils_1 = require("./utils");
10
- const picocolors_1 = __importDefault(require("@brillout/picocolors"));
1
+ export { logPass };
2
+ export { logWarn };
3
+ export { logFail };
4
+ export { logBoot };
5
+ export { hasFail };
6
+ export const TEST_FAIL = 'TEST_FAIL';
7
+ import { getCurrentTest } from './getCurrentTest.js';
8
+ import { assert, isTTY } from './utils.js';
9
+ import pc from '@brillout/picocolors';
11
10
  function logPass() {
12
11
  logStatus(false);
13
12
  }
14
- exports.logPass = logPass;
15
13
  function logWarn(warning) {
16
14
  logStatus(false, warning);
17
15
  }
18
- exports.logWarn = logWarn;
19
16
  function logFail(reason, isFinalAttempt) {
20
17
  if (isFinalAttempt) {
21
18
  logStatus(true);
@@ -24,16 +21,15 @@ function logFail(reason, isFinalAttempt) {
24
21
  logStatus(false, "Failed but marked as `isFlaky`; it'll be re-tried at the end.");
25
22
  }
26
23
  const { FAIL } = getStatusTags();
27
- const color = (s) => picocolors_1.default.red(picocolors_1.default.bold(s));
28
- const msg = `Test ${isFinalAttempt ? FAIL : 'failed'} because ${reason}, see below. [${exports.TEST_FAIL}]`;
24
+ const color = (s) => pc.red(pc.bold(s));
25
+ const msg = `Test ${isFinalAttempt ? FAIL : 'failed'} because ${reason}, see below. [${TEST_FAIL}]`;
29
26
  console.log(color(msg));
30
27
  }
31
- exports.logFail = logFail;
32
28
  function logStatus(isFail, warning) {
33
- const { testFile } = (0, getCurrentTest_1.getCurrentTest)();
29
+ const { testFile } = getCurrentTest();
34
30
  const { PASS, FAIL, WARN } = getStatusTags();
35
31
  if (warning) {
36
- (0, utils_1.assert)(!isFail);
32
+ assert(!isFail);
37
33
  console.log(`${WARN} ${testFile} (${warning})`);
38
34
  }
39
35
  else if (isFail) {
@@ -45,23 +41,21 @@ function logStatus(isFail, warning) {
45
41
  }
46
42
  }
47
43
  function getStatusTags() {
48
- const PASS = picocolors_1.default.bold(picocolors_1.default.white(picocolors_1.default.bgGreen(' PASS ')));
49
- const FAIL = picocolors_1.default.bold(picocolors_1.default.white(picocolors_1.default.bgRed(' FAIL ')));
50
- const WARN = picocolors_1.default.bold(picocolors_1.default.white(picocolors_1.default.bgYellow(' WARN ')));
51
- const BOOT = picocolors_1.default.bold(picocolors_1.default.white(picocolors_1.default.bgBlack(' BOOT ')));
44
+ const PASS = pc.bold(pc.white(pc.bgGreen(' PASS ')));
45
+ const FAIL = pc.bold(pc.white(pc.bgRed(' FAIL ')));
46
+ const WARN = pc.bold(pc.white(pc.bgYellow(' WARN ')));
47
+ const BOOT = pc.bold(pc.white(pc.bgBlack(' BOOT ')));
52
48
  return { PASS, FAIL, WARN, BOOT };
53
49
  }
54
50
  function logBoot() {
55
- if (!utils_1.isTTY)
51
+ if (!isTTY)
56
52
  return;
57
- const { testFile } = (0, getCurrentTest_1.getCurrentTest)();
53
+ const { testFile } = getCurrentTest();
58
54
  const { BOOT } = getStatusTags();
59
55
  console.log();
60
56
  console.log(`${BOOT} ${testFile}`);
61
57
  }
62
- exports.logBoot = logBoot;
63
58
  let hasFailLog = false;
64
59
  function hasFail() {
65
60
  return hasFailLog;
66
61
  }
67
- exports.hasFail = hasFail;
package/dist/page.js CHANGED
@@ -1,13 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.page = void 0;
4
- const getCurrentTest_1 = require("./getCurrentTest");
1
+ export { page };
2
+ import { getCurrentTest } from './getCurrentTest.js';
5
3
  const page = new Proxy({}, {
6
4
  get(_, prop) {
7
- const { page } = (0, getCurrentTest_1.getCurrentTest)();
5
+ const { page } = getCurrentTest();
8
6
  if (!page)
9
7
  throw new Error("`page` isn't available. Make sure to access `page` only inside test() calls. In particular, if test() is async, then make sure to await all asynchronous code executed by your async test().");
10
8
  return page[prop];
11
9
  },
12
10
  });
13
- exports.page = page;
@@ -1,25 +1,19 @@
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.getTestFilesForCurrentJob = exports.isParallelCI = void 0;
7
- const utils_1 = require("./utils");
8
- const fs_1 = __importDefault(require("fs"));
9
- const path_1 = __importDefault(require("path"));
1
+ export { isParallelCI };
2
+ export { getTestFilesForCurrentJob };
3
+ import { assert } from './utils.js';
4
+ import fs from 'fs';
5
+ import path from 'path';
10
6
  const cwd = process.cwd();
11
7
  function isParallelCI() {
12
8
  return getTestFilesForCurrentJob() !== null;
13
9
  }
14
- exports.isParallelCI = isParallelCI;
15
10
  function getTestFilesForCurrentJob() {
16
11
  if (!('TEST_FILES' in process.env))
17
12
  return null;
18
- (0, utils_1.assert)(process.env.TEST_FILES);
19
- const testFiles = process.env.TEST_FILES.split(' ').map((filePathRelative) => path_1.default.join(cwd, filePathRelative));
13
+ assert(process.env.TEST_FILES);
14
+ const testFiles = process.env.TEST_FILES.split(' ').map((filePathRelative) => path.join(cwd, filePathRelative));
20
15
  testFiles.forEach((testFile) => {
21
- (0, utils_1.assert)(fs_1.default.existsSync(testFile), testFile);
16
+ assert(fs.existsSync(testFile), testFile);
22
17
  });
23
18
  return testFiles;
24
19
  }
25
- exports.getTestFilesForCurrentJob = getTestFilesForCurrentJob;
package/dist/run.js CHANGED
@@ -1,19 +1,17 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.run = void 0;
4
- const utils_1 = require("./utils");
5
- const utils_2 = require("./utils");
6
- const Logs_1 = require("./Logs");
7
- const editFile_1 = require("./editFile");
8
- const getCurrentTest_1 = require("./getCurrentTest");
9
- const page_1 = require("./page");
10
- const TIMEOUTS_1 = require("./TIMEOUTS");
1
+ export { run };
2
+ import { sleep, logProgress, cliOptions, isLinux, runCommandLongRunning } from './utils.js';
3
+ import { assert } from './utils.js';
4
+ import { Logs } from './Logs.js';
5
+ import { editFileAssertReverted, editFileRevert } from './editFile.js';
6
+ import { getCurrentTest, getCwd, getServerUrl, setRunInfo } from './getCurrentTest.js';
7
+ import { page } from './page.js';
8
+ import { TIMEOUT_NPM_SCRIPT, TIMEOUT_PLAYWRIGHT, TIMEOUT_PROCESS_TERMINATION } from './TIMEOUTS.js';
11
9
  function run(cmd, {
12
10
  //baseUrl = '',
13
- additionalTimeout = 0, serverIsReadyMessage, serverIsReadyDelay = 1000, inspect = utils_1.cliOptions.inspect, cwd, doNotFailOnWarning, serverUrl, isFlaky, } = {}) {
14
- (0, utils_2.assert)(cwd === undefined);
11
+ additionalTimeout = 0, serverIsReadyMessage, serverIsReadyDelay = 1000, inspect = cliOptions.inspect, cwd, doNotFailOnWarning, serverUrl, isFlaky, } = {}) {
12
+ assert(cwd === undefined);
15
13
  additionalTimeout += serverIsReadyDelay;
16
- (0, getCurrentTest_1.setRunInfo)({
14
+ setRunInfo({
17
15
  cmd,
18
16
  serverUrl,
19
17
  additionalTimeout,
@@ -21,12 +19,12 @@ additionalTimeout = 0, serverIsReadyMessage, serverIsReadyDelay = 1000, inspect
21
19
  isFlaky,
22
20
  });
23
21
  if (inspect) {
24
- Logs_1.Logs.logEagerly = 'all';
22
+ Logs.logEagerly = 'all';
25
23
  }
26
- else if (utils_1.cliOptions.verbose) {
27
- Logs_1.Logs.logEagerly = 'logs';
24
+ else if (cliOptions.verbose) {
25
+ Logs.logEagerly = 'logs';
28
26
  }
29
- const testInfo = (0, getCurrentTest_1.getCurrentTest)();
27
+ const testInfo = getCurrentTest();
30
28
  let runProcess = null;
31
29
  testInfo.startServer = async () => {
32
30
  runProcess = await startProcess({
@@ -35,11 +33,11 @@ additionalTimeout = 0, serverIsReadyMessage, serverIsReadyDelay = 1000, inspect
35
33
  serverIsReadyMessage,
36
34
  serverIsReadyDelay,
37
35
  });
38
- page_1.page.on('console', onConsole);
39
- page_1.page.on('pageerror', onPageError);
36
+ page.on('console', onConsole);
37
+ page.on('pageerror', onPageError);
40
38
  // This setting will change the default maximum time for all the methods accepting timeout option.
41
39
  // https://playwright.dev/docs/api/class-page#page-set-default-timeout
42
- page_1.page.setDefaultTimeout(TIMEOUTS_1.TIMEOUT_PLAYWRIGHT + additionalTimeout);
40
+ page.setDefaultTimeout(TIMEOUT_PLAYWRIGHT + additionalTimeout);
43
41
  /*
44
42
  await bailOnTimeout(
45
43
  async () => {
@@ -51,19 +49,19 @@ additionalTimeout = 0, serverIsReadyMessage, serverIsReadyDelay = 1000, inspect
51
49
  };
52
50
  testInfo.afterEach = (hasFailed) => {
53
51
  if (!hasFailed) {
54
- (0, editFile_1.editFileAssertReverted)();
52
+ editFileAssertReverted();
55
53
  }
56
54
  else {
57
- (0, editFile_1.editFileRevert)();
55
+ editFileRevert();
58
56
  }
59
57
  };
60
58
  testInfo.terminateServer = async () => {
61
- Logs_1.Logs.add({
59
+ Logs.add({
62
60
  logSource: 'run()',
63
61
  logText: 'Terminate server.',
64
62
  });
65
- page_1.page.off('console', onConsole);
66
- page_1.page.off('pageerror', onPageError);
63
+ page.off('console', onConsole);
64
+ page.off('pageerror', onPageError);
67
65
  // runProcess is undefined if startProcess() failed
68
66
  if (runProcess) {
69
67
  await runProcess.terminate();
@@ -73,7 +71,7 @@ additionalTimeout = 0, serverIsReadyMessage, serverIsReadyDelay = 1000, inspect
73
71
  // Also called when the page throws an error or a warning
74
72
  function onConsole(msg) {
75
73
  const type = msg.type();
76
- Logs_1.Logs.add({
74
+ Logs.add({
77
75
  logSource: (() => {
78
76
  if (type === 'error') {
79
77
  return 'Browser Error';
@@ -93,7 +91,7 @@ additionalTimeout = 0, serverIsReadyMessage, serverIsReadyDelay = 1000, inspect
93
91
  }
94
92
  // For uncaught exceptions
95
93
  function onPageError(err) {
96
- Logs_1.Logs.add({
94
+ Logs.add({
97
95
  logSource: 'Browser Error',
98
96
  logText: JSON.stringify({
99
97
  text: err.message,
@@ -102,9 +100,8 @@ additionalTimeout = 0, serverIsReadyMessage, serverIsReadyDelay = 1000, inspect
102
100
  });
103
101
  }
104
102
  }
105
- exports.run = run;
106
103
  async function startProcess({ serverIsReadyMessage, serverIsReadyDelay, additionalTimeout, cmd, }) {
107
- const cwd = (0, getCurrentTest_1.getCwd)();
104
+ const cwd = getCwd();
108
105
  if (!serverIsReadyMessage) {
109
106
  serverIsReadyMessage = (log) => {
110
107
  const serverIsReady =
@@ -117,26 +114,26 @@ async function startProcess({ serverIsReadyMessage, serverIsReadyDelay, addition
117
114
  return serverIsReady;
118
115
  };
119
116
  }
120
- Logs_1.Logs.add({
117
+ Logs.add({
121
118
  logSource: 'run()',
122
119
  logText: `Spawn command \`${cmd}\``,
123
120
  });
124
- const done = (0, utils_1.logProgress)(`[run] ${cmd}`);
125
- const { terminate, isReadyPromise } = (0, utils_1.runCommandLongRunning)({
121
+ const done = logProgress(`[run] ${cmd}`);
122
+ const { terminate, isReadyPromise } = runCommandLongRunning({
126
123
  cmd,
127
124
  cwd,
128
125
  isReadyLog: serverIsReadyMessage,
129
- isReadyTimeout: TIMEOUTS_1.TIMEOUT_NPM_SCRIPT + additionalTimeout,
130
- killPort: process.env.CI || !(0, utils_1.isLinux)() ? false : getServerPort(),
126
+ isReadyTimeout: TIMEOUT_NPM_SCRIPT + additionalTimeout,
127
+ killPort: process.env.CI || !isLinux() ? false : getServerPort(),
131
128
  onStderr(data, { loggedAfterExit }) {
132
- Logs_1.Logs.add({
129
+ Logs.add({
133
130
  logSource: 'stderr',
134
131
  logText: data,
135
132
  loggedAfterExit,
136
133
  });
137
134
  },
138
135
  onStdout(data, { loggedAfterExit }) {
139
- Logs_1.Logs.add({
136
+ Logs.add({
140
137
  logSource: 'stdout',
141
138
  logText: data,
142
139
  loggedAfterExit,
@@ -144,25 +141,25 @@ async function startProcess({ serverIsReadyMessage, serverIsReadyDelay, addition
144
141
  },
145
142
  onExit(errMsg) {
146
143
  if (!errMsg) {
147
- Logs_1.Logs.add({
144
+ Logs.add({
148
145
  logSource: 'run()',
149
146
  logText: `Process termination (expected)`,
150
147
  });
151
148
  }
152
149
  else {
153
- Logs_1.Logs.add({
150
+ Logs.add({
154
151
  logSource: 'run() failure',
155
152
  logText: errMsg,
156
153
  });
157
154
  }
158
155
  },
159
156
  onTerminationError(errMsg) {
160
- Logs_1.Logs.add({
157
+ Logs.add({
161
158
  logSource: 'run() failure',
162
159
  logText: errMsg,
163
160
  });
164
161
  },
165
- terminationTimeout: TIMEOUTS_1.TIMEOUT_PROCESS_TERMINATION,
162
+ terminationTimeout: TIMEOUT_PROCESS_TERMINATION,
166
163
  });
167
164
  let err;
168
165
  try {
@@ -170,22 +167,22 @@ async function startProcess({ serverIsReadyMessage, serverIsReadyDelay, addition
170
167
  }
171
168
  catch (err_) {
172
169
  err = err_;
173
- (0, utils_2.assert)(err);
170
+ assert(err);
174
171
  }
175
172
  done(!!err);
176
173
  if (err)
177
174
  throw err;
178
- Logs_1.Logs.add({
175
+ Logs.add({
179
176
  logSource: 'run()',
180
177
  logText: 'Server is ready.',
181
178
  });
182
- await (0, utils_1.sleep)(serverIsReadyDelay);
179
+ await sleep(serverIsReadyDelay);
183
180
  return { terminate };
184
181
  }
185
182
  function getServerPort() {
186
- const serverUrl = (0, getCurrentTest_1.getServerUrl)();
183
+ const serverUrl = getServerUrl();
187
184
  const portStr = serverUrl.split(':').slice(-1)[0].split('/')[0];
188
- (0, utils_2.assert)(/\d+/.test(portStr), { serverUrl });
185
+ assert(/\d+/.test(portStr), { serverUrl });
189
186
  const port = parseInt(portStr, 10);
190
187
  return port;
191
188
  }
package/dist/runAll.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export { runAll };
2
- import { type FindFilter } from './utils';
2
+ import { type FindFilter } from './utils.js';
3
3
  declare function runAll(filter: null | FindFilter): Promise<void>;