From 9d9801192ea1cbf811d5e0e367ba985a92c50e3d Mon Sep 17 00:00:00 2001 From: Pavel Feldman Date: Fri, 17 Jul 2020 16:09:27 -0700 Subject: [PATCH] test: wire test commands to jest (#3014) --- .github/workflows/tests.yml | 42 ++++++++++++---------------------- package.json | 12 ++++------ src/logger.ts | 14 ++++++++++++ test/electron/electron.jest.js | 9 ++++---- 4 files changed, 36 insertions(+), 41 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index abf08d35d2..d41a8180da 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -37,14 +37,12 @@ jobs: # XVFB-RUN merges both STDOUT and STDERR, whereas we need only STDERR # Wrap `npm run` in a subshell to redirect STDERR to file. # Enable core dumps in the subshell. - - run: xvfb-run --auto-servernum -- bash -c "ulimit -c unlimited && npm run test 2>./testrun.log" - env: - BROWSER: ${{ matrix.browser }} - DEBUG: "*,-pw:wrapped*" - run: xvfb-run --auto-servernum -- bash -c "ulimit -c unlimited && npm run jest -- --testTimeout=30000" if: ${{ always() }} env: BROWSER: ${{ matrix.browser }} + DEBUG: "*,-pw:wrapped*" + DEBUG_FILE: "testrun.log" - uses: actions/upload-artifact@v1 if: failure() with: @@ -76,14 +74,11 @@ jobs: - uses: microsoft/playwright-github-action@v1 - run: npm ci - run: npm run build - - run: npm run test 2>./${{ matrix.browser }}-mac-testrun.log + - run: npm run jest -- --testTimeout=30000 env: BROWSER: ${{ matrix.browser }} DEBUG: "*,-pw:wrapped*" - - run: npm run jest -- --testTimeout=30000 - if: ${{ always() }} - env: - BROWSER: ${{ matrix.browser }} + DEBUG_FILE: "testrun.log" - uses: actions/upload-artifact@v1 if: failure() with: @@ -93,7 +88,7 @@ jobs: if: failure() with: name: ${{ matrix.browser }}-mac-testrun.log - path: ${{ matrix.browser }}-mac-testrun.log + path: testrun.log test_win: name: "Windows" @@ -110,16 +105,12 @@ jobs: - uses: microsoft/playwright-github-action@v1 - run: npm ci - run: npm run build - - run: npm run test 2>./${{ matrix.browser }}-win-testrun.log + - run: npm run jest -- --testTimeout=30000 shell: bash env: BROWSER: ${{ matrix.browser }} DEBUG: "*,-pw:wrapped*" - - run: npm run jest -- --testTimeout=30000 - if: ${{ always() }} - shell: bash - env: - BROWSER: ${{ matrix.browser }} + DEBUG_FILE: "testrun.log" - uses: actions/upload-artifact@v1 if: failure() with: @@ -129,7 +120,7 @@ jobs: if: failure() with: name: ${{ matrix.browser }}-win-testrun.log - path: ${{ matrix.browser }}-win-testrun.log + path: testrun.log test-package-installations: runs-on: ubuntu-latest @@ -166,30 +157,29 @@ jobs: # XVFB-RUN merges both STDOUT and STDERR, whereas we need only STDERR # Wrap `npm run` in a subshell to redirect STDERR to file. # Enable core dumps in the subshell. - - run: xvfb-run --auto-servernum -- bash -c "ulimit -c unlimited && npm run test -- --line-break=100 2>./headful-linux-testrun.log" - env: - DEBUG: "*" - HEADLESS: "false" - run: xvfb-run --auto-servernum -- bash -c "ulimit -c unlimited && npm run jest -- --testTimeout=30000" if: ${{ always() }} env: BROWSER: "chromium" HEADLESS: "false" + DEBUG_FILE: "testrun.log" - run: xvfb-run --auto-servernum -- bash -c "ulimit -c unlimited && npm run jest -- --testTimeout=30000" if: ${{ always() }} env: BROWSER: "firefox" HEADLESS: "false" + DEBUG_FILE: "testrun.log" - run: xvfb-run --auto-servernum -- bash -c "ulimit -c unlimited && npm run jest -- --testTimeout=30000" if: ${{ always() }} env: BROWSER: "webkit" HEADLESS: "false" + DEBUG_FILE: "testrun.log" - uses: actions/upload-artifact@v1 if: failure() with: name: headful-linux-testrun.log - path: headful-linux-testrun.log + path: testrun.log - uses: actions/upload-artifact@v1 if: failure() with: @@ -218,15 +208,11 @@ jobs: # XVFB-RUN merges both STDOUT and STDERR, whereas we need only STDERR # Wrap `npm run` in a subshell to redirect STDERR to file. # Enable core dumps in the subshell. - - run: xvfb-run --auto-servernum -- bash -c "ulimit -c unlimited && npm run test 2>./testrun.log" + - run: xvfb-run --auto-servernum -- bash -c "ulimit -c unlimited && npm run jest -- --testTimeout=30000" env: BROWSER: ${{ matrix.browser }} DEBUG: "*,-pw:wrapped*" - PWCHANNEL: ${{ matrix.transport }} - - run: xvfb-run --auto-servernum -- bash -c "ulimit -c unlimited && npm run jest -- --testTimeout=30000" - if: ${{ always() }} - env: - BROWSER: ${{ matrix.browser }} + DEBUG_FILE: "testrun.log" PWCHANNEL: ${{ matrix.transport }} - uses: actions/upload-artifact@v1 if: failure() diff --git a/package.json b/package.json index f8beaec180..1613705085 100644 --- a/package.json +++ b/package.json @@ -9,14 +9,10 @@ "node": ">=10.15.0" }, "scripts": { - "ctest": "cross-env BROWSER=chromium node --unhandled-rejections=strict test/test.js", - "ftest": "cross-env BROWSER=firefox node --unhandled-rejections=strict test/test.js", - "wtest": "cross-env BROWSER=webkit node --unhandled-rejections=strict test/test.js", - "test": "cross-env node --unhandled-rejections=strict test/test.js", - "ccoverage": "cross-env COVERAGE=true BROWSER=chromium node --unhandled-rejections=strict test/test.js", - "fcoverage": "cross-env COVERAGE=true BROWSER=firefox node --unhandled-rejections=strict test/test.js", - "wcoverage": "cross-env COVERAGE=true BROWSER=webkit node --unhandled-rejections=strict test/test.js", - "coverage": "cross-env COVERAGE=true node --unhandled-rejections=strict test/test.js", + "ctest": "cross-env BROWSER=chromium npm run jest", + "ftest": "cross-env BROWSER=firefox npm run jest", + "wtest": "cross-env BROWSER=webkit npm run jest", + "test": "npm run ctest && npm run ftest && npm run wtest", "eslint": "[ \"$CI\" = true ] && eslint --quiet -f codeframe --ext js,ts ./src || eslint --ext js,ts ./src", "tsc": "tsc -p .", "tsc-installer": "tsc -p ./src/install/tsconfig.json", diff --git a/src/logger.ts b/src/logger.ts index 5e4ec35c45..246424a588 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -15,6 +15,7 @@ */ import * as debug from 'debug'; +import * as fs from 'fs'; import { helper } from './helper'; import { LoggerSink, LoggerSeverity } from './loggerSink'; @@ -142,6 +143,19 @@ const colorMap = new Map([ export class DebugLoggerSink { private _debuggers = new Map(); + constructor() { + if (process.env.DEBUG_FILE) { + const ansiRegex = new RegExp([ + '[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)', + '(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))' + ].join('|'), 'g'); + const stream = fs.createWriteStream(process.env.DEBUG_FILE); + (debug as any).log = (data: string) => { + stream.write(data.replace(ansiRegex, '')); + stream.write('\n'); + }; + } + } isEnabled(name: string, severity: LoggerSeverity): boolean { return debug.enabled(`pw:${name}`); diff --git a/test/electron/electron.jest.js b/test/electron/electron.jest.js index 4f8356530f..b80da4025c 100644 --- a/test/electron/electron.jest.js +++ b/test/electron/electron.jest.js @@ -15,11 +15,10 @@ */ const path = require('path'); -const config = require('../test.config'); -const utils = require('../utils'); - const electronName = process.platform === 'win32' ? 'electron.cmd' : 'electron'; +const { CHROMIUM } = testOptions; + registerFixture('application', async ({playwright}, test) => { const electronPath = path.join(__dirname, '..', '..', 'node_modules', '.bin', electronName); const application = await playwright.electron.launch(electronPath, { @@ -41,7 +40,7 @@ registerFixture('window', async ({application}, test) => { } }); -describe('Electron', function() { +describe.skip(!CHROMIUM)('Electron', function() { it('should script application', async ({ application }) => { const appPath = await application.evaluate(async ({ app }) => app.getAppPath()); expect(appPath).toContain('electron'); @@ -124,7 +123,7 @@ describe('Electron', function() { }); }); -describe('Electron per window', function() { +describe.skip(!CHROMIUM)('Electron per window', function() { it('should click the button', async({window, server}) => { await window.goto(server.PREFIX + '/input/button.html'); await window.click('button');