mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
ci: separate unit tests (#10436)
This commit is contained in:
parent
61f4525ae3
commit
c35084dd2c
@ -98,7 +98,7 @@ module.exports = {
|
|||||||
'no-restricted-imports': [
|
'no-restricted-imports': [
|
||||||
'error',
|
'error',
|
||||||
{
|
{
|
||||||
patterns: ['*Events'],
|
patterns: ['*Events', '*.test.js'],
|
||||||
paths: [
|
paths: [
|
||||||
{
|
{
|
||||||
name: 'mitt',
|
name: 'mitt',
|
||||||
|
21
.github/workflows/ci.yml
vendored
21
.github/workflows/ci.yml
vendored
@ -372,6 +372,27 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
docker run -i --init --cap-add=SYS_ADMIN --rm puppeteer-test-image node -e "`cat test/smoke-test.js`"
|
docker run -i --init --cap-add=SYS_ADMIN --rm puppeteer-test-image node -e "`cat test/smoke-test.js`"
|
||||||
|
|
||||||
|
unit-tests:
|
||||||
|
name: '[Required] Unit tests'
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: check-changes
|
||||||
|
if: ${{ contains(fromJSON(needs.check-changes.outputs.changes), 'puppeteer') }}
|
||||||
|
steps:
|
||||||
|
- name: Check out repository
|
||||||
|
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
|
||||||
|
- name: Set up Node.js
|
||||||
|
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
|
||||||
|
with:
|
||||||
|
cache: npm
|
||||||
|
node-version: lts/*
|
||||||
|
- name: Install dependencies
|
||||||
|
run: npm ci
|
||||||
|
env:
|
||||||
|
PUPPETEER_SKIP_DOWNLOAD: true
|
||||||
|
- name: Run unit tests
|
||||||
|
run: |
|
||||||
|
npm run unit --w puppeteer-core -w puppeteer --if-present
|
||||||
|
|
||||||
ng-schematics-tests:
|
ng-schematics-tests:
|
||||||
name: '[Required] Test Angular Schematics'
|
name: '[Required] Test Angular Schematics'
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
@ -98,6 +98,7 @@ usually check through CI:
|
|||||||
[`tsd`](https://github.com/SamVerschueren/tsd).
|
[`tsd`](https://github.com/SamVerschueren/tsd).
|
||||||
- `test:chrome:**` - Tests `puppeteer` on Chromium.
|
- `test:chrome:**` - Tests `puppeteer` on Chromium.
|
||||||
- `test:firefox:**` - Tests `puppeteer` on Firefox.
|
- `test:firefox:**` - Tests `puppeteer` on Firefox.
|
||||||
|
- `unit` - Runs unit tests.
|
||||||
|
|
||||||
The default `npm test` runs `test:{chrome,firefox}:headless` which is generally
|
The default `npm test` runs `test:{chrome,firefox}:headless` which is generally
|
||||||
sufficient.
|
sufficient.
|
||||||
@ -108,6 +109,15 @@ to see if a given test result is expected or not. See more info about the test
|
|||||||
runner in
|
runner in
|
||||||
[`tools/mochaRunner`](https://github.com/puppeteer/puppeteer/tree/main/tools/mochaRunner).
|
[`tools/mochaRunner`](https://github.com/puppeteer/puppeteer/tree/main/tools/mochaRunner).
|
||||||
|
|
||||||
|
### Unit tests
|
||||||
|
|
||||||
|
Tests that only test code (without the running browser) are put next to the classes they test
|
||||||
|
and run using the Node test runner (requires Node 20+):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm run unit
|
||||||
|
```
|
||||||
|
|
||||||
## Code reviews
|
## Code reviews
|
||||||
|
|
||||||
All submissions, including submissions by project members, require review. We
|
All submissions, including submissions by project members, require review. We
|
||||||
|
@ -34,8 +34,9 @@
|
|||||||
"test:firefox:headful": "wireit",
|
"test:firefox:headful": "wireit",
|
||||||
"test:firefox:headless": "wireit",
|
"test:firefox:headless": "wireit",
|
||||||
"test:firefox": "wireit",
|
"test:firefox": "wireit",
|
||||||
"test": "cross-env PUPPETEER_DEFERRED_PROMISE_DEBUG_TIMEOUT=20000 node tools/mochaRunner/lib/main.js --min-tests 1052",
|
"test": "cross-env PUPPETEER_DEFERRED_PROMISE_DEBUG_TIMEOUT=20000 node tools/mochaRunner/lib/main.js --min-tests 1048",
|
||||||
"validate-licenses": "tsx tools/third_party/validate-licenses.ts"
|
"validate-licenses": "tsx tools/third_party/validate-licenses.ts",
|
||||||
|
"unit": "npm run unit --workspaces --if-present"
|
||||||
},
|
},
|
||||||
"wireit": {
|
"wireit": {
|
||||||
"build": {
|
"build": {
|
||||||
|
@ -42,7 +42,8 @@
|
|||||||
"clean": "tsc -b --clean && rm -rf lib src/generated",
|
"clean": "tsc -b --clean && rm -rf lib src/generated",
|
||||||
"generate:package-json": "wireit",
|
"generate:package-json": "wireit",
|
||||||
"generate:sources": "wireit",
|
"generate:sources": "wireit",
|
||||||
"prepack": "wireit"
|
"prepack": "wireit",
|
||||||
|
"unit": "wireit"
|
||||||
},
|
},
|
||||||
"wireit": {
|
"wireit": {
|
||||||
"prepack": {
|
"prepack": {
|
||||||
@ -123,11 +124,18 @@
|
|||||||
"dependencies": [
|
"dependencies": [
|
||||||
"build:tsc"
|
"build:tsc"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
"unit": {
|
||||||
|
"command": "node --test --test-reporter spec lib/cjs",
|
||||||
|
"dependencies": [
|
||||||
|
"build"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"lib",
|
"lib",
|
||||||
"src",
|
"src",
|
||||||
|
"!*.test.js",
|
||||||
"!*.tsbuildinfo"
|
"!*.tsbuildinfo"
|
||||||
],
|
],
|
||||||
"author": "The Chromium Authors",
|
"author": "The Chromium Authors",
|
||||||
|
@ -14,15 +14,16 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import {describe, it} from 'node:test';
|
||||||
|
|
||||||
import expect from 'expect';
|
import expect from 'expect';
|
||||||
import {HTTPRequest} from 'puppeteer-core/internal/api/HTTPRequest.js';
|
|
||||||
import {HTTPResponse} from 'puppeteer-core/internal/api/HTTPResponse.js';
|
import {HTTPRequest} from '../api/HTTPRequest.js';
|
||||||
import {EventEmitter} from 'puppeteer-core/internal/common/EventEmitter.js';
|
import {HTTPResponse} from '../api/HTTPResponse.js';
|
||||||
import {Frame} from 'puppeteer-core/internal/common/Frame.js';
|
|
||||||
import {
|
import {EventEmitter} from './EventEmitter.js';
|
||||||
NetworkManager,
|
import {Frame} from './Frame.js';
|
||||||
NetworkManagerEmittedEvents,
|
import {NetworkManager, NetworkManagerEmittedEvents} from './NetworkManager.js';
|
||||||
} from 'puppeteer-core/internal/common/NetworkManager.js';
|
|
||||||
|
|
||||||
// TODO: develop a helper to generate fake network events for attributes that
|
// TODO: develop a helper to generate fake network events for attributes that
|
||||||
// are not relevant for the network manager to make tests shorter.
|
// are not relevant for the network manager to make tests shorter.
|
||||||
@ -477,13 +478,16 @@ describe('NetworkManager', () => {
|
|||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
manager.setRequestInterception(true);
|
await manager.setRequestInterception(true);
|
||||||
|
|
||||||
const requests: HTTPRequest[] = [];
|
const requests: HTTPRequest[] = [];
|
||||||
manager.on(NetworkManagerEmittedEvents.Request, (request: HTTPRequest) => {
|
manager.on(
|
||||||
request.continue();
|
NetworkManagerEmittedEvents.Request,
|
||||||
requests.push(request);
|
async (request: HTTPRequest) => {
|
||||||
});
|
requests.push(request);
|
||||||
|
await request.continue();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This sequence was taken from an actual CDP session produced by the following
|
* This sequence was taken from an actual CDP session produced by the following
|
@ -115,6 +115,7 @@
|
|||||||
"lib",
|
"lib",
|
||||||
"src",
|
"src",
|
||||||
"install.js",
|
"install.js",
|
||||||
|
"!*.test.js",
|
||||||
"!*.tsbuildinfo"
|
"!*.tsbuildinfo"
|
||||||
],
|
],
|
||||||
"author": "The Chromium Authors",
|
"author": "The Chromium Authors",
|
||||||
|
@ -11,6 +11,12 @@
|
|||||||
"parameters": ["webDriverBiDi"],
|
"parameters": ["webDriverBiDi"],
|
||||||
"expectations": ["PASS"]
|
"expectations": ["PASS"]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"testIdPattern": "[Deferred.spec] *",
|
||||||
|
"platforms": ["darwin", "linux", "win32"],
|
||||||
|
"parameters": ["webDriverBiDi"],
|
||||||
|
"expectations": ["PASS"]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"testIdPattern": "[DeviceRequestPrompt.spec] DeviceRequestPrompt *",
|
"testIdPattern": "[DeviceRequestPrompt.spec] DeviceRequestPrompt *",
|
||||||
"platforms": ["darwin", "linux", "win32"],
|
"platforms": ["darwin", "linux", "win32"],
|
||||||
@ -155,12 +161,6 @@
|
|||||||
"parameters": ["webDriverBiDi"],
|
"parameters": ["webDriverBiDi"],
|
||||||
"expectations": ["FAIL", "TIMEOUT"]
|
"expectations": ["FAIL", "TIMEOUT"]
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"testIdPattern": "[NetworkManager.spec] NetworkManager *",
|
|
||||||
"platforms": ["darwin", "linux", "win32"],
|
|
||||||
"parameters": ["webDriverBiDi"],
|
|
||||||
"expectations": ["PASS"]
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"testIdPattern": "[page.spec] Page Page.browser *",
|
"testIdPattern": "[page.spec] Page Page.browser *",
|
||||||
"platforms": ["darwin", "linux", "win32"],
|
"platforms": ["darwin", "linux", "win32"],
|
||||||
@ -473,12 +473,6 @@
|
|||||||
"parameters": ["chrome", "webDriverBiDi"],
|
"parameters": ["chrome", "webDriverBiDi"],
|
||||||
"expectations": ["PASS"]
|
"expectations": ["PASS"]
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"testIdPattern": "[Deferred.spec] *",
|
|
||||||
"platforms": ["darwin", "linux", "win32"],
|
|
||||||
"parameters": ["webDriverBiDi"],
|
|
||||||
"expectations": ["PASS"]
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"testIdPattern": "[drag-and-drop.spec] *",
|
"testIdPattern": "[drag-and-drop.spec] *",
|
||||||
"platforms": ["darwin", "linux", "win32"],
|
"platforms": ["darwin", "linux", "win32"],
|
||||||
|
Loading…
Reference in New Issue
Block a user