@brillout/test-e2e 0.4.14 → 0.4.16

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,6 +1,7 @@
1
1
  export { getCurrentTest };
2
2
  export { getCurrentTestOptional };
3
3
  export { setCurrentTest };
4
+ export type { TestInfo };
4
5
  import type { Page } from 'playwright-chromium';
5
6
  declare type TestInfo = {
6
7
  testFile: string;
package/dist/runAll.js CHANGED
@@ -54,13 +54,48 @@ async function buildAndTest(testFile, browser, isSecondAttempt) {
54
54
  finally {
55
55
  cleanBuild();
56
56
  }
57
- const { success, clean } = await runTests(browser, isSecondAttempt);
58
- await clean();
57
+ const success = await runServerAndTests(browser, isSecondAttempt);
59
58
  (0, getCurrentTest_2.setCurrentTest)(null);
60
59
  return success;
61
60
  }
62
- async function runTests(browser, isSecondAttempt) {
61
+ async function runServerAndTests(browser, isSecondAttempt) {
63
62
  const testInfo = (0, getCurrentTest_1.getCurrentTest)();
63
+ // Set when user calls `run()`
64
+ (0, utils_1.assert)(testInfo.runInfo);
65
+ (0, utils_1.assert)(testInfo.startServer);
66
+ (0, utils_1.assert)(testInfo.terminateServer);
67
+ const isFinalAttempt = isSecondAttempt || !testInfo.runInfo.isFlaky;
68
+ const page = await browser.newPage();
69
+ testInfo.page = page;
70
+ try {
71
+ await testInfo.startServer();
72
+ }
73
+ catch (err) {
74
+ logFailure(err, 'an error occurred while starting the server', isFinalAttempt);
75
+ return false;
76
+ }
77
+ let success = await runTests(testInfo, isFinalAttempt);
78
+ await testInfo.terminateServer();
79
+ await page.close();
80
+ // Check whether stderr emitted during testInfo.terminateServer()
81
+ if (success) {
82
+ const failOnWarning = true;
83
+ if (Logs_1.Logs.hasFailLogs(failOnWarning) &&
84
+ // See comments about taskkill in src/setup.ts
85
+ !(0, utils_1.isWindows)()) {
86
+ logFailure(null, `${getErrorType(failOnWarning)} occurred during server termination`, isFinalAttempt);
87
+ success = false;
88
+ }
89
+ }
90
+ if (!success && !testInfo.runInfo.isFlaky)
91
+ (0, parallel_ci_1.abortIfParallelCI)();
92
+ if (success) {
93
+ (0, logTestStatus_1.logPass)();
94
+ }
95
+ Logs_1.Logs.clearLogs();
96
+ return success;
97
+ }
98
+ async function runTests(testInfo, isFinalAttempt) {
64
99
  if (utils_1.isTTY) {
65
100
  console.log();
66
101
  console.log(testInfo.testFile);
@@ -70,37 +105,13 @@ async function runTests(browser, isSecondAttempt) {
70
105
  (0, logTestStatus_1.logWarn)(testInfo.skipped);
71
106
  (0, utils_1.assertUsage)(!testInfo.runInfo, 'You cannot call `run()` after calling `skip()`');
72
107
  (0, utils_1.assertUsage)(testInfo.tests === undefined, 'You cannot call `test()` after calling `skip()`');
73
- return { success: true, clean: async () => { } };
108
+ return true;
74
109
  }
75
- const page = await browser.newPage();
76
- testInfo.page = page;
77
110
  // Set when user calls `run()`
78
111
  (0, utils_1.assert)(testInfo.runInfo);
79
- (0, utils_1.assert)(testInfo.startServer);
80
- (0, utils_1.assert)(testInfo.terminateServer);
81
112
  (0, utils_1.assert)(testInfo.afterEach);
82
113
  // Set when user calls `test()`
83
114
  (0, utils_1.assert)(testInfo.tests);
84
- const { isFlaky } = testInfo.runInfo;
85
- const isFinalAttempt = isSecondAttempt || !isFlaky;
86
- const clean = async () => {
87
- await testInfo.terminateServer?.();
88
- await page.close();
89
- };
90
- const failure = () => {
91
- if (!isFlaky)
92
- (0, parallel_ci_1.abortIfParallelCI)();
93
- return { success: false, clean };
94
- };
95
- try {
96
- await testInfo.startServer();
97
- }
98
- catch (err) {
99
- (0, logTestStatus_1.logFail)('an error occurred while starting the server', isFinalAttempt);
100
- (0, logError_1.logError)(err);
101
- Logs_1.Logs.flushLogs();
102
- return failure();
103
- }
104
115
  for (const { testDesc, testFn } of testInfo.tests) {
105
116
  Logs_1.Logs.add({
106
117
  logSource: 'test()',
@@ -122,37 +133,28 @@ async function runTests(browser, isSecondAttempt) {
122
133
  const isFailure = err || hasErrorLog;
123
134
  if (isFailure) {
124
135
  if (err) {
125
- (0, logTestStatus_1.logFail)(`the test "${testDesc}" threw an error`, isFinalAttempt);
126
- (0, logError_1.logError)(err);
136
+ logFailure(err, `the test "${testDesc}" threw an error`, isFinalAttempt);
127
137
  }
128
138
  else if (hasErrorLog) {
129
- (0, logTestStatus_1.logFail)(`${getErrorType(failOnWarning)} occurred while running the test "${testDesc}"`, isFinalAttempt);
139
+ logFailure(null, `${getErrorType(failOnWarning)} occurred while running the test "${testDesc}"`, isFinalAttempt);
130
140
  }
131
141
  else {
132
142
  (0, utils_1.assert)(false);
133
143
  }
134
- Logs_1.Logs.logErrorsAndWarnings();
135
- Logs_1.Logs.flushLogs();
136
- return failure();
144
+ return false;
137
145
  }
138
146
  }
139
147
  Logs_1.Logs.clearLogs();
140
148
  }
141
- // Check whether stderr emitted during testInfo.terminateServer()
142
- {
143
- const failOnWarning = true;
144
- if (Logs_1.Logs.hasFailLogs(failOnWarning) &&
145
- // See comments about taskkill in src/setup.ts
146
- !(0, utils_1.isWindows)()) {
147
- (0, logTestStatus_1.logFail)(`${getErrorType(failOnWarning)} occurred during server termination`, isFinalAttempt);
148
- Logs_1.Logs.logErrorsAndWarnings();
149
- Logs_1.Logs.flushLogs();
150
- return failure();
151
- }
149
+ return true;
150
+ }
151
+ function logFailure(err, reason, isFinalAttempt) {
152
+ (0, logTestStatus_1.logFail)(reason, isFinalAttempt);
153
+ if (err) {
154
+ (0, logError_1.logError)(err);
152
155
  }
153
- Logs_1.Logs.clearLogs();
154
- (0, logTestStatus_1.logPass)();
155
- return { success: true, clean };
156
+ Logs_1.Logs.logErrorsAndWarnings();
157
+ Logs_1.Logs.flushLogs();
156
158
  }
157
159
  function getErrorType(failOnWarning) {
158
160
  return !failOnWarning ? 'error(s)' : 'error(s)/warning(s)';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brillout/test-e2e",
3
- "version": "0.4.14",
3
+ "version": "0.4.16",
4
4
  "bin": "./bin.js",
5
5
  "main": "./dist/index.js",
6
6
  "scripts": {