From 329195011facb8cd4dadc844d3b1505d99852c63 Mon Sep 17 00:00:00 2001 From: Alex Rudenko Date: Mon, 27 Jun 2022 12:35:09 +0200 Subject: [PATCH] chore: fix chrome-headless ci (#8560) --- .github/workflows/ci.yml | 22 +++++++++++----------- test/src/fixtures.spec.ts | 8 ++++++-- test/src/navigation.spec.ts | 23 ++++++++++++++--------- 3 files changed, 31 insertions(+), 22 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 75f2c48c..dd7252ec 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -183,9 +183,9 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - # Include active LTS + current Node.js version. + # Include a current Node.js version. # https://github.com/nodejs/Release#release-schedule - node: [16, 18] + node: [18] steps: - name: Checkout uses: actions/checkout@v3 @@ -209,7 +209,6 @@ jobs: npm run build - name: Run unit tests in headful mode uses: nick-invision/retry@v2 - continue-on-error: true env: CHROMIUM: true HEADLESS: false @@ -218,15 +217,14 @@ jobs: command: xvfb-run --auto-servernum npm run test:unit timeout_minutes: 10 - chrome-headless: + linux-chrome-headless: runs-on: ${{ matrix.os }} strategy: matrix: # https://github.com/actions/virtual-environments#available-environments - os: [ubuntu-latest, macos-latest, windows-latest] - # Include active LTS + current Node.js version. + os: [ubuntu-latest] # https://github.com/nodejs/Release#release-schedule - node: [16, 18] + node: [18] steps: - name: Checkout uses: actions/checkout@v3 @@ -238,17 +236,19 @@ jobs: node-version: ${{ matrix.node }} - name: Install dependencies run: | + sudo apt-get install xvfb + # Ensure both a Chromium and a Firefox binary are available. + PUPPETEER_PRODUCT=firefox npm install npm install - ls .local-chromium + ls .local-chromium .local-firefox - name: Build run: | npm run build - name: Run unit tests uses: nick-invision/retry@v2 - continue-on-error: true env: CHROMIUM: true with: max_attempts: 1 - command: npm run test:unit:chrome-headless - timeout_minutes: 30 + command: xvfb-run --auto-servernum npm run test:unit:chrome-headless + timeout_minutes: 10 diff --git a/test/src/fixtures.spec.ts b/test/src/fixtures.spec.ts index 72e462ef..e20054dc 100644 --- a/test/src/fixtures.spec.ts +++ b/test/src/fixtures.spec.ts @@ -22,8 +22,12 @@ import {getTestState, itHeadlessOnly} from './mocha-utils.js'; import path from 'path'; describe('Fixtures', function () { - itHeadlessOnly('dumpio option should work with pipe option ', async () => { - const {defaultBrowserOptions, puppeteerPath} = getTestState(); + itHeadlessOnly('dumpio option should work with pipe option', async () => { + const {defaultBrowserOptions, puppeteerPath, headless} = getTestState(); + if (headless === 'chrome') { + // This test only works in the old headless mode. + return; + } let dumpioData = ''; const {spawn} = await import('child_process'); diff --git a/test/src/navigation.spec.ts b/test/src/navigation.spec.ts index f123c720..1743c855 100644 --- a/test/src/navigation.spec.ts +++ b/test/src/navigation.spec.ts @@ -160,15 +160,20 @@ describe('navigation', function () { } }); - /* If you are running this on pre-Catalina versions of macOS this will fail locally. - /* Mac OSX Catalina outputs a different message than other platforms. - * See https://support.google.com/chrome/thread/18125056?hl=en for details. - * If you're running pre-Catalina Mac OSX this test will fail locally. - */ - const EXPECTED_SSL_CERT_MESSAGE = - os.platform() === 'darwin' + function getExpectedSSLCertMessage(): string { + const {headless} = getTestState(); + /** + * If you are running this on pre-Catalina versions of macOS this will fail + * locally. Mac OSX Catalina outputs a different message than other + * platforms. See https://support.google.com/chrome/thread/18125056?hl=en + * for details. If you're running pre-Catalina Mac OSX this test will fail + * locally. + * In chrome-headless, the message is also different. + */ + return os.platform() === 'darwin' && headless !== 'chrome' ? 'net::ERR_CERT_INVALID' : 'net::ERR_CERT_AUTHORITY_INVALID'; + } itFailsFirefox('should fail when navigating to bad SSL', async () => { const {page, httpsServer, isChrome} = getTestState(); @@ -191,7 +196,7 @@ describe('navigation', function () { return (error = error_); }); if (isChrome) { - expect(error.message).toContain(EXPECTED_SSL_CERT_MESSAGE); + expect(error.message).toContain(getExpectedSSLCertMessage()); } else { expect(error.message).toContain('SSL_ERROR_UNKNOWN'); } @@ -210,7 +215,7 @@ describe('navigation', function () { return (error = error_); }); if (isChrome) { - expect(error.message).toContain(EXPECTED_SSL_CERT_MESSAGE); + expect(error.message).toContain(getExpectedSSLCertMessage()); } else { expect(error.message).toContain('SSL_ERROR_UNKNOWN'); }