@brillout/test-e2e 0.6.14 → 0.6.15

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.
@@ -1,7 +1,14 @@
1
1
  export { isTolerateError };
2
+ export type { TolerateError };
3
+ import { type TestInfo } from '../getCurrentTest.js';
2
4
  import type { LogSource } from '../Logs.js';
3
5
  type LogData = {
4
6
  logSource: LogSource;
5
7
  logText: string;
6
8
  };
9
+ type TolerateError = true | ((args: {
10
+ logSource: LogSource;
11
+ logText: string;
12
+ testInfo: null | TestInfo;
13
+ }) => boolean | undefined);
7
14
  declare function isTolerateError({ logSource, logText }: LogData): boolean;
@@ -8,13 +8,18 @@ function isTolerateError({ logSource, logText }) {
8
8
  return true;
9
9
  }
10
10
  const testInfo = getCurrentTestOptional();
11
+ const isTolerated = (tolerateError) => {
12
+ if (tolerateError === true)
13
+ return true;
14
+ if (tolerateError?.({ logSource, logText, testInfo })) {
15
+ return true;
16
+ }
17
+ };
11
18
  const config = getConfig();
12
- const { tolerateError } = config;
13
- if (tolerateError === true)
19
+ if (isTolerated(config.tolerateError))
14
20
  return true;
15
- if (tolerateError?.({ logSource, logText, testInfo })) {
21
+ if (isTolerated(testInfo?.runInfo?.tolerateError))
16
22
  return true;
17
- }
18
23
  return false;
19
24
  }
20
25
  function tolerateErrorBuiltIn({ logSource, logText }) {
@@ -1,8 +1,9 @@
1
1
  export { getConfig };
2
2
  export { loadConfig };
3
3
  import type { LaunchOptions } from 'playwright-chromium';
4
+ import type { TolerateError } from './Logs/isTolerateError.js';
4
5
  type Config = {
5
- tolerateError?: Function | true;
6
+ tolerateError?: TolerateError;
6
7
  ci?: never;
7
8
  chromiumLaunchOptions?: LaunchOptions;
8
9
  };
@@ -7,6 +7,7 @@ export { getCwd };
7
7
  export { getServerUrl };
8
8
  export type { TestInfo };
9
9
  import type { Page } from 'playwright-chromium';
10
+ import type { TolerateError } from './Logs/isTolerateError.js';
10
11
  type TestInfo = {
11
12
  testFile: string;
12
13
  testName: string;
@@ -16,14 +17,14 @@ type TestInfo = {
16
17
  testFn: Function;
17
18
  }[];
18
19
  testOptions?: {
19
- doNotFailOnWarning: boolean;
20
+ tolerateError?: TolerateError;
20
21
  testFunctionTimeout: number;
21
22
  isFlaky: boolean;
22
23
  };
23
24
  runInfo?: {
24
25
  cmd: string;
25
26
  serverUrl: string;
26
- doNotFailOnWarning: boolean;
27
+ tolerateError?: TolerateError;
27
28
  testFunctionTimeout: number;
28
29
  isFlaky: boolean;
29
30
  isRunCommandThatTerminates: boolean;
@@ -44,16 +45,16 @@ declare function setCurrentTest(testFile: null | string): void;
44
45
  declare function getRunInfo(): {
45
46
  cmd: string;
46
47
  serverUrl: string;
47
- doNotFailOnWarning: boolean;
48
+ tolerateError?: TolerateError | undefined;
48
49
  testFunctionTimeout: number;
49
50
  isFlaky: boolean;
50
51
  isRunCommandThatTerminates: boolean;
51
52
  };
52
- declare function setRunInfo({ cmd, serverUrl, additionalTimeout, doNotFailOnWarning, isFlaky, isRunCommandThatTerminates, }: {
53
+ declare function setRunInfo({ cmd, serverUrl, additionalTimeout, tolerateError, isFlaky, isRunCommandThatTerminates, }: {
53
54
  cmd: string;
54
55
  serverUrl?: string;
55
56
  additionalTimeout?: number;
56
- doNotFailOnWarning?: boolean;
57
+ tolerateError?: TolerateError;
57
58
  isFlaky?: boolean;
58
59
  isRunCommandThatTerminates?: boolean;
59
60
  }): void;
@@ -48,14 +48,14 @@ function getRunInfo() {
48
48
  return testInfo.runInfo;
49
49
  }
50
50
  const serverUrlDefault = 'http://localhost:3000';
51
- function setRunInfo({ cmd, serverUrl = serverUrlDefault, additionalTimeout = 0, doNotFailOnWarning = false, isFlaky = false, isRunCommandThatTerminates = false, }) {
51
+ function setRunInfo({ cmd, serverUrl = serverUrlDefault, additionalTimeout = 0, tolerateError, isFlaky = false, isRunCommandThatTerminates = false, }) {
52
52
  const testInfo = getCurrentTest();
53
53
  const testFunctionTimeout = TIMEOUT_TEST_FUNCTION + additionalTimeout;
54
54
  testInfo.runInfo = {
55
55
  cmd,
56
56
  serverUrl,
57
57
  testFunctionTimeout,
58
- doNotFailOnWarning,
58
+ tolerateError,
59
59
  isFlaky,
60
60
  isRunCommandThatTerminates,
61
61
  };
package/dist/run.d.ts CHANGED
@@ -1,12 +1,13 @@
1
1
  export { run };
2
- declare function run(cmd: string, { additionalTimeout, serverIsReadyMessage, serverIsReadyDelay, inspect, cwd, doNotFailOnWarning, serverUrl, isFlaky, }?: {
2
+ import type { TolerateError } from './Logs/isTolerateError.js';
3
+ declare function run(cmd: string, { additionalTimeout, serverIsReadyMessage, serverIsReadyDelay, inspect, cwd, tolerateError, serverUrl, isFlaky, }?: {
3
4
  additionalTimeout?: number;
4
5
  serverIsReadyMessage?: string | ((log: string) => boolean);
5
6
  serverIsReadyDelay?: number;
6
7
  inspect?: boolean;
7
8
  /** deprecated */
8
9
  cwd?: string;
9
- doNotFailOnWarning?: boolean;
10
+ tolerateError?: TolerateError;
10
11
  serverUrl?: string;
11
12
  isFlaky?: boolean;
12
13
  }): void;
package/dist/run.js CHANGED
@@ -8,14 +8,14 @@ import { page } from './page.js';
8
8
  import { TIMEOUT_NPM_SCRIPT, TIMEOUT_PLAYWRIGHT, TIMEOUT_PROCESS_TERMINATION } from './TIMEOUTS.js';
9
9
  function run(cmd, {
10
10
  //baseUrl = '',
11
- additionalTimeout = 0, serverIsReadyMessage, serverIsReadyDelay = 1000, inspect = cliOptions.inspect, cwd, doNotFailOnWarning, serverUrl, isFlaky, } = {}) {
11
+ additionalTimeout = 0, serverIsReadyMessage, serverIsReadyDelay = 1000, inspect = cliOptions.inspect, cwd, tolerateError, serverUrl, isFlaky, } = {}) {
12
12
  assert(cwd === undefined);
13
13
  additionalTimeout += serverIsReadyDelay;
14
14
  setRunInfo({
15
15
  cmd,
16
16
  serverUrl,
17
17
  additionalTimeout,
18
- doNotFailOnWarning,
18
+ tolerateError,
19
19
  isFlaky,
20
20
  });
21
21
  if (inspect) {
package/dist/runAll.js CHANGED
@@ -184,10 +184,9 @@ async function runTests(testInfo, isFinalAttempt) {
184
184
  done(!!err);
185
185
  testInfo.afterEach(!!err);
186
186
  {
187
- const failOnWarning = !testInfo.runInfo.doNotFailOnWarning;
188
187
  const isFailureFromLogs = Logs.hasFailureLog({
189
- includeBrowserWarnings: failOnWarning,
190
- includeStderr: failOnWarning,
188
+ includeBrowserWarnings: true,
189
+ includeStderr: true,
191
190
  });
192
191
  const isFailure = err || isFailureFromLogs;
193
192
  if (isFailure) {
@@ -208,7 +207,8 @@ async function runTests(testInfo, isFinalAttempt) {
208
207
  logFailure(err, `the test "${testDesc}" threw an error`, isFinalAttempt);
209
208
  }
210
209
  else {
211
- assert(Logs.hasFailureLog({ includeBrowserWarnings: failOnWarning, includeStderr: true }));
210
+ assert(Logs.hasFailureLog({ includeBrowserWarnings: true, includeStderr: true }));
211
+ const failOnWarning = testInfo.runInfo.tolerateError !== true;
212
212
  logFailure(null, `${getErrorType(failOnWarning)} occurred while running the test "${testDesc}"`, isFinalAttempt);
213
213
  }
214
214
  return false;
@@ -1,4 +1,5 @@
1
1
  export { runCommand };
2
+ // TO-DO/eventually: use @brillout/shell
2
3
  import { exec } from 'child_process';
3
4
  import { genPromise } from './genPromise.js';
4
5
  import { humanizeTime } from './humanizeTime.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brillout/test-e2e",
3
- "version": "0.6.14",
3
+ "version": "0.6.15",
4
4
  "bin": "./bin.js",
5
5
  "main": "./dist/index.js",
6
6
  "type": "module",