Skip to content

Commit 9d98011

Browse files
authored
test: wire test commands to jest (#3014)
1 parent 8904f40 commit 9d98011

File tree

4 files changed

+36
-41
lines changed

4 files changed

+36
-41
lines changed

.github/workflows/tests.yml

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,12 @@ jobs:
3737
# XVFB-RUN merges both STDOUT and STDERR, whereas we need only STDERR
3838
# Wrap `npm run` in a subshell to redirect STDERR to file.
3939
# Enable core dumps in the subshell.
40-
- run: xvfb-run --auto-servernum -- bash -c "ulimit -c unlimited && npm run test 2>./testrun.log"
41-
env:
42-
BROWSER: ${{ matrix.browser }}
43-
DEBUG: "*,-pw:wrapped*"
4440
- run: xvfb-run --auto-servernum -- bash -c "ulimit -c unlimited && npm run jest -- --testTimeout=30000"
4541
if: ${{ always() }}
4642
env:
4743
BROWSER: ${{ matrix.browser }}
44+
DEBUG: "*,-pw:wrapped*"
45+
DEBUG_FILE: "testrun.log"
4846
- uses: actions/upload-artifact@v1
4947
if: failure()
5048
with:
@@ -76,14 +74,11 @@ jobs:
7674
- uses: microsoft/playwright-github-action@v1
7775
- run: npm ci
7876
- run: npm run build
79-
- run: npm run test 2>./${{ matrix.browser }}-mac-testrun.log
80-
env:
81-
BROWSER: ${{ matrix.browser }}
82-
DEBUG: "*,-pw:wrapped*"
8377
- run: npm run jest -- --testTimeout=30000
84-
if: ${{ always() }}
8578
env:
8679
BROWSER: ${{ matrix.browser }}
80+
DEBUG: "*,-pw:wrapped*"
81+
DEBUG_FILE: "testrun.log"
8782
- uses: actions/upload-artifact@v1
8883
if: failure()
8984
with:
@@ -93,7 +88,7 @@ jobs:
9388
if: failure()
9489
with:
9590
name: ${{ matrix.browser }}-mac-testrun.log
96-
path: ${{ matrix.browser }}-mac-testrun.log
91+
path: testrun.log
9792

9893
test_win:
9994
name: "Windows"
@@ -110,16 +105,12 @@ jobs:
110105
- uses: microsoft/playwright-github-action@v1
111106
- run: npm ci
112107
- run: npm run build
113-
- run: npm run test 2>./${{ matrix.browser }}-win-testrun.log
114-
shell: bash
115-
env:
116-
BROWSER: ${{ matrix.browser }}
117-
DEBUG: "*,-pw:wrapped*"
118108
- run: npm run jest -- --testTimeout=30000
119-
if: ${{ always() }}
120109
shell: bash
121110
env:
122111
BROWSER: ${{ matrix.browser }}
112+
DEBUG: "*,-pw:wrapped*"
113+
DEBUG_FILE: "testrun.log"
123114
- uses: actions/upload-artifact@v1
124115
if: failure()
125116
with:
@@ -129,7 +120,7 @@ jobs:
129120
if: failure()
130121
with:
131122
name: ${{ matrix.browser }}-win-testrun.log
132-
path: ${{ matrix.browser }}-win-testrun.log
123+
path: testrun.log
133124

134125
test-package-installations:
135126
runs-on: ubuntu-latest
@@ -166,30 +157,29 @@ jobs:
166157
# XVFB-RUN merges both STDOUT and STDERR, whereas we need only STDERR
167158
# Wrap `npm run` in a subshell to redirect STDERR to file.
168159
# Enable core dumps in the subshell.
169-
- run: xvfb-run --auto-servernum -- bash -c "ulimit -c unlimited && npm run test -- --line-break=100 2>./headful-linux-testrun.log"
170-
env:
171-
DEBUG: "*"
172-
HEADLESS: "false"
173160
- run: xvfb-run --auto-servernum -- bash -c "ulimit -c unlimited && npm run jest -- --testTimeout=30000"
174161
if: ${{ always() }}
175162
env:
176163
BROWSER: "chromium"
177164
HEADLESS: "false"
165+
DEBUG_FILE: "testrun.log"
178166
- run: xvfb-run --auto-servernum -- bash -c "ulimit -c unlimited && npm run jest -- --testTimeout=30000"
179167
if: ${{ always() }}
180168
env:
181169
BROWSER: "firefox"
182170
HEADLESS: "false"
171+
DEBUG_FILE: "testrun.log"
183172
- run: xvfb-run --auto-servernum -- bash -c "ulimit -c unlimited && npm run jest -- --testTimeout=30000"
184173
if: ${{ always() }}
185174
env:
186175
BROWSER: "webkit"
187176
HEADLESS: "false"
177+
DEBUG_FILE: "testrun.log"
188178
- uses: actions/upload-artifact@v1
189179
if: failure()
190180
with:
191181
name: headful-linux-testrun.log
192-
path: headful-linux-testrun.log
182+
path: testrun.log
193183
- uses: actions/upload-artifact@v1
194184
if: failure()
195185
with:
@@ -218,15 +208,11 @@ jobs:
218208
# XVFB-RUN merges both STDOUT and STDERR, whereas we need only STDERR
219209
# Wrap `npm run` in a subshell to redirect STDERR to file.
220210
# Enable core dumps in the subshell.
221-
- run: xvfb-run --auto-servernum -- bash -c "ulimit -c unlimited && npm run test 2>./testrun.log"
222-
env:
223-
BROWSER: ${{ matrix.browser }}
224-
DEBUG: "*,-pw:wrapped*"
225-
PWCHANNEL: ${{ matrix.transport }}
226211
- run: xvfb-run --auto-servernum -- bash -c "ulimit -c unlimited && npm run jest -- --testTimeout=30000"
227-
if: ${{ always() }}
228212
env:
229213
BROWSER: ${{ matrix.browser }}
214+
DEBUG: "*,-pw:wrapped*"
215+
DEBUG_FILE: "testrun.log"
230216
PWCHANNEL: ${{ matrix.transport }}
231217
- uses: actions/upload-artifact@v1
232218
if: failure()

package.json

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,10 @@
99
"node": ">=10.15.0"
1010
},
1111
"scripts": {
12-
"ctest": "cross-env BROWSER=chromium node --unhandled-rejections=strict test/test.js",
13-
"ftest": "cross-env BROWSER=firefox node --unhandled-rejections=strict test/test.js",
14-
"wtest": "cross-env BROWSER=webkit node --unhandled-rejections=strict test/test.js",
15-
"test": "cross-env node --unhandled-rejections=strict test/test.js",
16-
"ccoverage": "cross-env COVERAGE=true BROWSER=chromium node --unhandled-rejections=strict test/test.js",
17-
"fcoverage": "cross-env COVERAGE=true BROWSER=firefox node --unhandled-rejections=strict test/test.js",
18-
"wcoverage": "cross-env COVERAGE=true BROWSER=webkit node --unhandled-rejections=strict test/test.js",
19-
"coverage": "cross-env COVERAGE=true node --unhandled-rejections=strict test/test.js",
12+
"ctest": "cross-env BROWSER=chromium npm run jest",
13+
"ftest": "cross-env BROWSER=firefox npm run jest",
14+
"wtest": "cross-env BROWSER=webkit npm run jest",
15+
"test": "npm run ctest && npm run ftest && npm run wtest",
2016
"eslint": "[ \"$CI\" = true ] && eslint --quiet -f codeframe --ext js,ts ./src || eslint --ext js,ts ./src",
2117
"tsc": "tsc -p .",
2218
"tsc-installer": "tsc -p ./src/install/tsconfig.json",

src/logger.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
import * as debug from 'debug';
18+
import * as fs from 'fs';
1819
import { helper } from './helper';
1920
import { LoggerSink, LoggerSeverity } from './loggerSink';
2021

@@ -142,6 +143,19 @@ const colorMap = new Map<string, number>([
142143

143144
export class DebugLoggerSink {
144145
private _debuggers = new Map<string, debug.IDebugger>();
146+
constructor() {
147+
if (process.env.DEBUG_FILE) {
148+
const ansiRegex = new RegExp([
149+
'[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)',
150+
'(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))'
151+
].join('|'), 'g');
152+
const stream = fs.createWriteStream(process.env.DEBUG_FILE);
153+
(debug as any).log = (data: string) => {
154+
stream.write(data.replace(ansiRegex, ''));
155+
stream.write('\n');
156+
};
157+
}
158+
}
145159

146160
isEnabled(name: string, severity: LoggerSeverity): boolean {
147161
return debug.enabled(`pw:${name}`);

test/electron/electron.jest.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@
1515
*/
1616

1717
const path = require('path');
18-
const config = require('../test.config');
19-
const utils = require('../utils');
20-
2118
const electronName = process.platform === 'win32' ? 'electron.cmd' : 'electron';
2219

20+
const { CHROMIUM } = testOptions;
21+
2322
registerFixture('application', async ({playwright}, test) => {
2423
const electronPath = path.join(__dirname, '..', '..', 'node_modules', '.bin', electronName);
2524
const application = await playwright.electron.launch(electronPath, {
@@ -41,7 +40,7 @@ registerFixture('window', async ({application}, test) => {
4140
}
4241
});
4342

44-
describe('Electron', function() {
43+
describe.skip(!CHROMIUM)('Electron', function() {
4544
it('should script application', async ({ application }) => {
4645
const appPath = await application.evaluate(async ({ app }) => app.getAppPath());
4746
expect(appPath).toContain('electron');
@@ -124,7 +123,7 @@ describe('Electron', function() {
124123
});
125124
});
126125

127-
describe('Electron per window', function() {
126+
describe.skip(!CHROMIUM)('Electron per window', function() {
128127
it('should click the button', async({window, server}) => {
129128
await window.goto(server.PREFIX + '/input/button.html');
130129
await window.click('button');

0 commit comments

Comments
 (0)