Remove old browser (headless) tests (#37433)

This commit is contained in:
Peter Bengtsson 2023-06-02 12:16:58 -04:00 коммит произвёл GitHub
Родитель fcf16575c0
Коммит bc960c6447
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
8 изменённых файлов: 84 добавлений и 1937 удалений

79
.github/workflows/browser-test.yml поставляемый
Просмотреть файл

@ -1,79 +0,0 @@
name: Browser Tests
# **What it does**: This runs our browser tests on pull requests.
# **Why we have it**: This is the only way we currently test our browser JavaScript.
# **Who does it impact**: Docs engineering, open-source engineering contributors.
on:
workflow_dispatch:
pull_request:
paths:
- '**.js'
- '**.mjs'
- '**.ts'
- '**.tsx'
- jest.config.js
- package.json
# In case something like eslint or tsc or prettier upgrades
- package-lock.json
# Ultimately, for debugging this workflow itself
- .github/workflows/browser-test.yml
permissions:
contents: read
# This allows a subsequently queued workflow run to interrupt previous runs
concurrency:
group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'
cancel-in-progress: true
env:
ELASTICSEARCH_URL: http://localhost:9200/
jobs:
build:
if: github.repository == 'github/docs-internal' || github.repository == 'github/docs'
runs-on: ${{ fromJSON('["ubuntu-latest", "ubuntu-20.04-xl"]')[github.repository == 'github/docs-internal'] }}
steps:
- name: Checkout
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab
- uses: ./.github/actions/setup-elasticsearch
- name: Setup Node.js
uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516
with:
node-version-file: 'package.json'
cache: npm
- name: Install dependencies
env:
# This makes it so the puppeteer npm package doesn't bother
# to download a copy of chromium because it can use
# `$PUPPETEER_EXECUTABLE_PATH` from the ubuntu Action container.
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: true
run: npm ci --include=optional
- uses: ./.github/actions/get-docs-early-access
if: ${{ github.repository == 'github/docs-internal' }}
with:
token: ${{ secrets.DOCUBOT_REPO_PAT }}
- name: Cache nextjs build
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8
with:
path: .next/cache
key: ${{ runner.os }}-nextjs-${{ hashFiles('package*.json') }}
- name: Run build script
run: npm run build
- name: Index fixtures into the local Elasticsearch
run: npm run index-test-fixtures
- name: Check that Elasticsearch is accessible
run: |
curl --fail --retry-connrefused --retry 5 -I ${{ env.ELASTICSEARCH_URL }}
- name: Run browser-test
run: npm run browser-test

Просмотреть файл

@ -1,6 +1,5 @@
// https://jestjs.io/docs/en/configuration.html
const isBrowser = process.env.BROWSER
const isActions = Boolean(process.env.GITHUB_ACTIONS)
const reporters = ['default']
@ -18,7 +17,6 @@ export default {
statements: -5,
},
},
preset: isBrowser ? 'jest-puppeteer' : undefined,
moduleNameMapper: {
// fix for "Unexpected token 'export'" error when running jest
'@primer/behaviors': '<rootDir>/node_modules/@primer/behaviors/dist/cjs/index.js',
@ -26,14 +24,13 @@ export default {
reporters,
modulePathIgnorePatterns: ['assets/'],
setupFilesAfterEnv: ['./jest.setup.js', 'jest-expect-message'],
...(isBrowser ? {} : { testEnvironment: 'node' }),
testEnvironment: 'node',
testPathIgnorePatterns: [
'node_modules/',
'vendor/',
'tests/fixtures/',
'tests/helpers/',
'tests/javascripts/',
...(isBrowser ? [] : ['tests/browser/browser.js']),
],
testMatch: ['**/tests/**/*.js'],
testLocationInResults: isActions,

1891
package-lock.json сгенерированный

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -139,7 +139,6 @@
"http-status-code": "^2.1.0",
"husky": "^8.0.1",
"jest": "29.5.0",
"jest-environment-puppeteer": "^5.0.4",
"jest-expect-message": "1.1.3",
"jest-fail-on-console": "^3.0.1",
"jest-github-actions-reporter": "^1.0.3",
@ -174,14 +173,11 @@
"name": "docs.github.com",
"optionalDependencies": {
"esm": "^3.2.25",
"jest-puppeteer": "^5.0.4",
"puppeteer": "^9.1.1",
"website-scraper": "^5.3.1"
},
"private": true,
"repository": "https://github.com/github/docs",
"scripts": {
"browser-test": "cross-env BROWSER=1 ENABLED_LANGUAGES=en,ja NODE_OPTIONS=--experimental-vm-modules JEST_PUPPETEER_CONFIG=jest-puppeteer.config.cjs jest tests/browser/browser.js",
"build": "next build",
"debug": "cross-env NODE_ENV=development ENABLED_LANGUAGES=en nodemon --inspect server.js",
"dev": "cross-env npm start",

Просмотреть файл

@ -1,7 +1,5 @@
#!/usr/bin/env node
import teardownJestPuppeteer from 'jest-environment-puppeteer/teardown.js'
import { START_JEST_SERVER, isServerHealthy, killServer } from './server-for-jest.js'
export default async () => {
@ -12,13 +10,4 @@ export default async () => {
killServer()
}
}
// The way jest-puppeteer works is that you add a preset in
// `jest.config.js` but that preset will clash with the execution
// of this script. So we have to manually do what we do normally
// do in `jest.config.js`
// Note, we can delete this when we migrate to Playwright.
if (process.env.BROWSER) {
await teardownJestPuppeteer()
}
}

Просмотреть файл

@ -1,7 +1,5 @@
#!/usr/bin/env node
import setupJestPuppeteer from 'jest-environment-puppeteer/setup.js'
import { main } from '../start-server.js'
import { PORT, START_JEST_SERVER, isServerHealthy, isPortRunning } from './server-for-jest.js'
@ -30,13 +28,4 @@ export default async () => {
} else {
console.warn(`jest is NOT automatically starting a server on port :${PORT}`)
}
// The way jest-puppeteer works is that you add a preset in
// `jest.config.js` but that preset will clash with the execution
// of this script. So we have to manually do what we do normally
// do in `jest.config.js`.
// Note, we can delete this when we migrate to Playwright.
if (process.env.BROWSER) {
await setupJestPuppeteer()
}
}

Просмотреть файл

@ -13,18 +13,13 @@ custom reporters for different types of test output, etc.
### Install optional dependencies
We typically rely on CI to run our tests, so some large test-only
dependencies are considered **optional** (for example, puppeteer). To run the tests locally, you'll
dependencies are considered **optional**. To run the tests locally, you'll
need to make sure optional dependencies are installed by running:
```sh
npm ci --include=optional
```
If you run into the error "Could not find expected browser (chrome) locally", you may need to install the expected chromium version manually with:
```
node node_modules/puppeteer/install.js
```
### Running all the tests
Once you've followed the development instructions above, you can run the entire

Просмотреть файл

@ -1,13 +0,0 @@
import { jest } from '@jest/globals'
jest.useFakeTimers({ legacyFakeTimers: true })
/* global page */
describe('homepage', () => {
jest.setTimeout(60 * 1000)
test('should be titled "GitHub Docs"', async () => {
await page.goto('http://localhost:4000')
await expect(page.title()).resolves.toMatch('GitHub Docs')
})
})