mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
chore: namespace commands (#8494)
This commit is contained in:
parent
465a7c405f
commit
75c3f94a54
11
.eslintrc.js
11
.eslintrc.js
@ -178,16 +178,5 @@ module.exports = {
|
||||
'@typescript-eslint/explicit-module-boundary-types': 2,
|
||||
},
|
||||
},
|
||||
{
|
||||
files: ['test-browser/**/*.js'],
|
||||
parserOptions: {
|
||||
sourceType: 'module',
|
||||
},
|
||||
env: {
|
||||
es6: true,
|
||||
browser: true,
|
||||
es2020: true,
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
34
.github/workflows/ci.yml
vendored
34
.github/workflows/ci.yml
vendored
@ -49,13 +49,13 @@ jobs:
|
||||
|
||||
- name: Run code checks
|
||||
run: |
|
||||
npm run ensure-pinned-deps
|
||||
npm run test:pinned-deps
|
||||
npm run lint
|
||||
# Skipping as it's flakey and we are not currently using the new documentation site in the wild yet.
|
||||
# See https://github.com/puppeteer/puppeteer/issues/7710 for more info
|
||||
# npm run generate-docs
|
||||
npm run ensure-correct-devtools-protocol-revision
|
||||
npm run test-types-file
|
||||
# npm run generate:docs
|
||||
npm run test:protocol-revision
|
||||
npm run test:types
|
||||
|
||||
- name: Run commit lint
|
||||
run: |
|
||||
@ -68,15 +68,15 @@ jobs:
|
||||
CHROMIUM: true
|
||||
with:
|
||||
max_attempts: 3
|
||||
command: xvfb-run --auto-servernum npm run unit
|
||||
command: xvfb-run --auto-servernum npm run test:unit
|
||||
timeout_minutes: 10
|
||||
|
||||
- name: Run unit tests with coverage
|
||||
env:
|
||||
CHROMIUM: true
|
||||
run: |
|
||||
xvfb-run --auto-servernum npm run unit-with-coverage
|
||||
xvfb-run --auto-servernum npm run assert-unit-coverage
|
||||
xvfb-run --auto-servernum npm run test:unit:coverage
|
||||
xvfb-run --auto-servernum npm run test:coverage
|
||||
|
||||
- name: Run unit tests on Firefox
|
||||
uses: nick-invision/retry@v2
|
||||
@ -86,18 +86,14 @@ jobs:
|
||||
with:
|
||||
max_attempts: 3
|
||||
timeout_minutes: 10
|
||||
command: xvfb-run --auto-servernum npm run funit
|
||||
|
||||
- name: Run browser tests
|
||||
run: |
|
||||
npm run test-browser
|
||||
command: xvfb-run --auto-servernum npm run test:unit:firefox
|
||||
|
||||
- name: Test bundling and installation
|
||||
env:
|
||||
CHROMIUM: true
|
||||
run: |
|
||||
# Note: this modifies package.json to test puppeteer-core.
|
||||
npm run test-install
|
||||
npm run test:install
|
||||
# Undo those changes.
|
||||
git checkout --force
|
||||
|
||||
@ -133,14 +129,14 @@ jobs:
|
||||
env:
|
||||
CHROMIUM: true
|
||||
run: |
|
||||
npm run unit
|
||||
npm run test:unit
|
||||
|
||||
- name: Run unit tests on Firefox
|
||||
uses: nick-invision/retry@v2
|
||||
with:
|
||||
max_attempts: 3
|
||||
timeout_minutes: 10
|
||||
command: npm run funit
|
||||
command: npm run test:unit:firefox
|
||||
|
||||
windows:
|
||||
# https://github.com/actions/virtual-environments#available-environments
|
||||
@ -176,7 +172,7 @@ jobs:
|
||||
env:
|
||||
CHROMIUM: true
|
||||
run: |
|
||||
npm run unit
|
||||
npm run test:unit
|
||||
|
||||
- name: Run unit tests on Firefox
|
||||
uses: nick-invision/retry@v2
|
||||
@ -187,7 +183,7 @@ jobs:
|
||||
with:
|
||||
max_attempts: 3
|
||||
timeout_minutes: 10
|
||||
command: npm run funit
|
||||
command: npm run test:unit:firefox
|
||||
|
||||
linux-headful:
|
||||
# https://github.com/actions/virtual-environments#available-environments
|
||||
@ -226,7 +222,7 @@ jobs:
|
||||
HEADLESS: false
|
||||
with:
|
||||
max_attempts: 1
|
||||
command: xvfb-run --auto-servernum npm run unit
|
||||
command: xvfb-run --auto-servernum npm run test:unit
|
||||
timeout_minutes: 10
|
||||
|
||||
chrome-headless:
|
||||
@ -261,5 +257,5 @@ jobs:
|
||||
CHROMIUM: true
|
||||
with:
|
||||
max_attempts: 1
|
||||
command: npm run chrome-headless-unit
|
||||
command: npm run test:unit:chrome-headless
|
||||
timeout_minutes: 30
|
||||
|
6
.github/workflows/tot-ci.yml
vendored
6
.github/workflows/tot-ci.yml
vendored
@ -50,7 +50,7 @@ jobs:
|
||||
HEADLESS: true
|
||||
with:
|
||||
max_attempts: 3
|
||||
command: xvfb-run --auto-servernum npm run unit
|
||||
command: xvfb-run --auto-servernum npm run test:unit
|
||||
timeout_minutes: 10
|
||||
|
||||
- name: Run unit tests in headful
|
||||
@ -61,7 +61,7 @@ jobs:
|
||||
HEADLESS: false
|
||||
with:
|
||||
max_attempts: 3
|
||||
command: xvfb-run --auto-servernum npm run unit
|
||||
command: xvfb-run --auto-servernum npm run test:unit
|
||||
timeout_minutes: 10
|
||||
|
||||
- name: Run unit tests in chrome headless
|
||||
@ -71,5 +71,5 @@ jobs:
|
||||
CHROMIUM: true
|
||||
with:
|
||||
max_attempts: 3
|
||||
command: xvfb-run --auto-servernum npm run chrome-headless-unit
|
||||
command: xvfb-run --auto-servernum npm run test:unit:chrome-headless
|
||||
timeout_minutes: 10
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/bin/sh
|
||||
. "$(dirname "$0")/_/husky.sh"
|
||||
|
||||
npm run eslint
|
||||
npm run lint:eslint
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/bin/sh
|
||||
. "$(dirname "$0")/_/husky.sh"
|
||||
|
||||
npm run tsc && npm run eslint && npm run doc && npm run prettier && npm run ensure-pinned-deps
|
||||
npm run build:tsc && npm run lint:eslint && npm run doc && npm run lint:prettier && npm run test:pinned-deps
|
||||
|
@ -63,7 +63,7 @@ npm install
|
||||
3. Run Puppeteer tests locally. For more information about tests, read [Running & Writing Tests](#running--writing-tests).
|
||||
|
||||
```bash
|
||||
npm run unit
|
||||
npm run test:unit
|
||||
```
|
||||
|
||||
## Code reviews
|
||||
@ -76,20 +76,20 @@ information on using pull requests.
|
||||
## Code Style
|
||||
|
||||
- Coding style is fully defined in [`.eslintrc`](https://github.com/puppeteer/puppeteer/blob/main/.eslintrc.js) and we automatically format our code with [Prettier](https://prettier.io).
|
||||
- It's recommended to set-up Prettier into your editor, or you can run `npm run eslint-fix` to automatically format any files.
|
||||
- It's recommended to set-up Prettier into your editor, or you can run `npm run lint:eslint:fix` to automatically format any files.
|
||||
- If you're working in a JS file, code should be annotated with [closure annotations](https://github.com/google/closure-compiler/wiki/Annotating-JavaScript-for-the-Closure-Compiler).
|
||||
- If you're working in a TS file, you should explicitly type all variables and return types. You'll get ESLint warnings if you don't so if you're not sure use them as guidelines, and feel free to ask us for help!
|
||||
|
||||
To run ESLint, use:
|
||||
|
||||
```bash
|
||||
npm run eslint
|
||||
npm run lint:eslint
|
||||
```
|
||||
|
||||
You can check your code (both JS & TS) type-checks by running:
|
||||
|
||||
```bash
|
||||
npm run tsc
|
||||
npm run build:tsc
|
||||
```
|
||||
|
||||
## TypeScript guidelines
|
||||
@ -170,7 +170,7 @@ npm run doc
|
||||
To format the documentation markdown and its code snippets, use:
|
||||
|
||||
```bash
|
||||
npm run prettier-fix
|
||||
npm run format
|
||||
```
|
||||
|
||||
## Writing TSDoc Comments
|
||||
@ -183,7 +183,7 @@ Each change to Puppeteer should be thoroughly documented using TSDoc comments. R
|
||||
## Running New Documentation website locally
|
||||
|
||||
- In the Puppeteer's folder, install all dependencies with `npm i`.
|
||||
- run `npm run generate-docs` which will generate all the `.md` files on `puppeteer/website/docs`.
|
||||
- run `npm run generate:docs` which will generate all the `.md` files on `puppeteer/website/docs`.
|
||||
- run `npm i` on `puppeteer/website`.
|
||||
- run `npm start` on `puppeteer/website`.
|
||||
|
||||
@ -214,7 +214,7 @@ Despite being named 'unit', these are integration tests, making sure public API
|
||||
- To run all tests:
|
||||
|
||||
```bash
|
||||
npm run unit
|
||||
npm run test:unit
|
||||
```
|
||||
|
||||
- To run a specific test, substitute the `it` with `it.only`:
|
||||
@ -241,27 +241,27 @@ npm run unit
|
||||
- To run tests in non-headless mode:
|
||||
|
||||
```bash
|
||||
HEADLESS=false npm run unit
|
||||
HEADLESS=false npm run test:unit
|
||||
```
|
||||
|
||||
- To run Firefox tests, firstly ensure you have Firefox installed locally (you only need to do this once, not on every test run) and then you can run the tests:
|
||||
|
||||
```bash
|
||||
PUPPETEER_PRODUCT=firefox node install.js
|
||||
PUPPETEER_PRODUCT=firefox npm run unit
|
||||
PUPPETEER_PRODUCT=firefox npm run test:unit
|
||||
```
|
||||
|
||||
- To run experimental Chromium MacOS ARM tests, firstly ensure you have correct Chromium version installed locally (you only need to do this once, not on every test run) and then you can run the tests:
|
||||
|
||||
```bash
|
||||
PUPPETEER_EXPERIMENTAL_CHROMIUM_MAC_ARM=1 node install.js
|
||||
PUPPETEER_EXPERIMENTAL_CHROMIUM_MAC_ARM=1 npm run unit
|
||||
PUPPETEER_EXPERIMENTAL_CHROMIUM_MAC_ARM=1 npm run test:unit
|
||||
```
|
||||
|
||||
- To run tests with custom browser executable:
|
||||
|
||||
```bash
|
||||
BINARY=<path-to-executable> npm run unit
|
||||
BINARY=<path-to-executable> npm run test:unit
|
||||
```
|
||||
|
||||
## Public API Coverage
|
||||
@ -289,10 +289,10 @@ The following steps are needed to update the Chromium version.
|
||||
To do so, run `utils/check_availability.js -rd` to find the latest suitable `dev` Chromium revision (see `utils/check_availability.js -help` for more options).
|
||||
1. Update `src/revisions.ts` with the found revision number.
|
||||
1. Update `versions.js` with the new Chromium-to-Puppeteer version mapping and update `lastMaintainedChromiumVersion` with the latest stable Chrome version.
|
||||
1. Run `npm run ensure-correct-devtools-protocol-revision`.
|
||||
1. Run `npm run test:protocol-revision`.
|
||||
If it fails, update `package.json` with the expected `devtools-protocol` version.
|
||||
1. Run `npm run tsc` and `npm install`.
|
||||
1. Run `npm run unit` and ensure that all tests pass. If a test fails, [bisect](#bisecting-upstream-changes) the upstream cause of the failure, and either update the test expectations accordingly (if it was an intended change) or work around the changes in Puppeteer (if it’s not desirable to change Puppeteer’s observable behavior).
|
||||
1. Run `npm run build:tsc` and `npm install`.
|
||||
1. Run `npm run test:unit` and ensure that all tests pass. If a test fails, [bisect](#bisecting-upstream-changes) the upstream cause of the failure, and either update the test expectations accordingly (if it was an intended change) or work around the changes in Puppeteer (if it’s not desirable to change Puppeteer’s observable behavior).
|
||||
1. Commit and push your changes and open a pull request.
|
||||
The commit message must contain the version in `Chromium <version> (<revision>)` format to ensure that [pptr.dev](https://pptr.dev/) can parse it correctly, e.g. `'feat(chromium): roll to Chromium 90.0.4427.0 (r856583)'`.
|
||||
|
||||
|
66
package.json
66
package.json
@ -27,44 +27,39 @@
|
||||
"node": ">=14.1.0"
|
||||
},
|
||||
"scripts": {
|
||||
"test-browser": "wtr",
|
||||
"test-browser-watch": "wtr --watch",
|
||||
"unit": "npm run tsc-cjs && npm run tsc-compat-cjs && mocha --config mocha-config/puppeteer-unit-tests.js",
|
||||
"chrome-headless-unit": "cross-env HEADLESS=chrome npm run unit",
|
||||
"unit-debug": "npm run tsc-cjs && npm run tsc-compat-cjs && mocha --inspect-brk --config mocha-config/puppeteer-unit-tests.js",
|
||||
"unit-with-coverage": "cross-env COVERAGE=1 npm run unit",
|
||||
"assert-unit-coverage": "cross-env COVERAGE=1 mocha --config mocha-config/coverage-tests.js",
|
||||
"funit": "cross-env PUPPETEER_PRODUCT=firefox npm run unit",
|
||||
"test": "npm run build && npm run lint --silent && npm run unit-with-coverage && npm run test-browser",
|
||||
"prepare": "node typescript-if-required.js && ([[ $HUSKY = 0 ]] || husky install)",
|
||||
"test": "npm run build && npm run lint --silent && npm run test:unit:coverage",
|
||||
"test:unit": "npm run build:tsc:cjs && npm run build:tsc:cjs:compat && mocha --config mocha-config/puppeteer-unit-tests.js",
|
||||
"test:unit:firefox": "cross-env PUPPETEER_PRODUCT=firefox npm run test:unit",
|
||||
"test:unit:coverage": "cross-env COVERAGE=1 npm run test:unit",
|
||||
"test:unit:chrome-headless": "cross-env HEADLESS=chrome npm run test:unit",
|
||||
"test:protocol-revision": "ts-node -s scripts/ensure-correct-devtools-protocol-package",
|
||||
"test:pinned-deps": "ts-node -s scripts/ensure-pinned-deps",
|
||||
"test:install": "scripts/test-install.sh",
|
||||
"test:debug": "npm run build:tsc:cjs && npm run build:tsc:cjs:compat && mocha --inspect-brk --config mocha-config/puppeteer-unit-tests.js",
|
||||
"test:coverage": "cross-env COVERAGE=1 mocha --config mocha-config/coverage-tests.js",
|
||||
"test:types": "ts-node -s scripts/test-ts-definition-files.ts",
|
||||
"prepublishOnly": "npm run build",
|
||||
"dev-install": "npm run build && node install.js",
|
||||
"prepare": "node typescript-if-required.js && ([[ $HUSKY = 0 ]] || husky install)",
|
||||
"lint": "npm run build && npm run lint:eslint && npm run doc && npm run lint:prettier",
|
||||
"lint:prettier": "prettier --check .",
|
||||
"lint:eslint": "([ \"$CI\" = true ] && eslint --ext js --ext ts --quiet -f codeframe . || eslint --ext js --ext ts .)",
|
||||
"lint:eslint:fix": "eslint --ext js --ext ts --fix .",
|
||||
"install": "node install.js",
|
||||
"eslint": "([ \"$CI\" = true ] && eslint --ext js --ext ts --quiet -f codeframe . || eslint --ext js --ext ts .)",
|
||||
"eslint-fix": "eslint --ext js --ext ts --fix .",
|
||||
"commitlint": "commitlint --from=HEAD~1",
|
||||
"prettier": "prettier --check .",
|
||||
"prettier-fix": "prettier --write .",
|
||||
"lint": "npm run build && npm run eslint && npm run doc && npm run prettier",
|
||||
"generate:types": "npm run clean:docs && api-extractor run --local --verbose",
|
||||
"generate:esm-package-json": "echo '{\"type\": \"module\"}' > lib/esm/package.json",
|
||||
"generate:docs": "npm run generate:types && api-documenter markdown -i docs-api-json -o website/docs && node utils/remove-tag.js",
|
||||
"generate:docs:testing": "commonmark docs/api.md > docs/api.html",
|
||||
"format": "prettier --write .",
|
||||
"doc": "node utils/doclint/cli.js",
|
||||
"generate-api-docs-for-testing": "commonmark docs/api.md > docs/api.html",
|
||||
"clean-lib": "rimraf lib",
|
||||
"build": "npm run tsc && npm run generate-d-ts && npm run generate-esm-package-json",
|
||||
"tsc": "npm run clean-lib && tsc --version && (npm run tsc-cjs && npm run tsc-esm) && (npm run tsc-compat-cjs && npm run tsc-compat-esm)",
|
||||
"tsc-cjs": "tsc -b src/tsconfig.cjs.json",
|
||||
"tsc-esm": "tsc -b src/tsconfig.esm.json",
|
||||
"tsc-compat-cjs": "tsc -b compat/cjs/tsconfig.json",
|
||||
"tsc-compat-esm": "tsc -b compat/esm/tsconfig.json",
|
||||
"apply-next-version": "node utils/apply_next_version.js",
|
||||
"test-install": "scripts/test-install.sh",
|
||||
"clean-docs": "rimraf website/docs && rimraf docs-api-json",
|
||||
"generate-d-ts": "npm run clean-docs && api-extractor run --local --verbose",
|
||||
"generate-docs": "npm run generate-d-ts && api-documenter markdown -i docs-api-json -o website/docs && node utils/remove-tag.js",
|
||||
"generate-esm-package-json": "echo '{\"type\": \"module\"}' > lib/esm/package.json",
|
||||
"ensure-correct-devtools-protocol-revision": "ts-node -s scripts/ensure-correct-devtools-protocol-package",
|
||||
"ensure-pinned-deps": "ts-node -s scripts/ensure-pinned-deps",
|
||||
"test-types-file": "ts-node -s scripts/test-ts-definition-files.ts",
|
||||
"build-docs-production": "cd website && npm install && npm run build"
|
||||
"commitlint": "commitlint --from=HEAD~1",
|
||||
"clean:lib": "rimraf lib",
|
||||
"clean:docs": "rimraf website/docs && rimraf docs-api-json",
|
||||
"build": "npm run build:tsc && npm run generate:types && npm run generate:esm-package-json",
|
||||
"build:tsc": "npm run clean:lib && tsc --version && (npm run build:tsc:cjs && npm run build:tsc:esm) && (npm run build:tsc:cjs:compat && npm run build:tsc:esm:compat)",
|
||||
"build:tsc:esm": "tsc -b src/tsconfig.esm.json",
|
||||
"build:tsc:esm:compat": "tsc -b compat/esm/tsconfig.json",
|
||||
"build:tsc:cjs": "tsc -b src/tsconfig.cjs.json",
|
||||
"build:tsc:cjs:compat": "tsc -b compat/cjs/tsconfig.json"
|
||||
},
|
||||
"files": [
|
||||
"lib",
|
||||
@ -105,7 +100,6 @@
|
||||
"@types/ws": "8.5.3",
|
||||
"@typescript-eslint/eslint-plugin": "5.27.0",
|
||||
"@typescript-eslint/parser": "5.27.0",
|
||||
"@web/test-runner": "0.13.28",
|
||||
"commonmark": "0.30.0",
|
||||
"cross-env": "7.0.3",
|
||||
"eslint": "8.16.0",
|
||||
|
@ -76,7 +76,7 @@ const PROJECT_FOLDERS = [...EXPECTED_ERRORS.keys()];
|
||||
if (!process.env['CI']) {
|
||||
console.log(`IMPORTANT: this script assumes you have compiled Puppeteer
|
||||
and its types file before running. Make sure you have run:
|
||||
=> npm run tsc && npm run generate-d-ts
|
||||
=> npm run build:tsc && npm run generate:types
|
||||
before executing this script locally.`);
|
||||
}
|
||||
|
||||
|
@ -1,55 +0,0 @@
|
||||
/**
|
||||
* Copyright 2020 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { Connection } from '../lib/esm/puppeteer/common/Connection.js';
|
||||
import { BrowserWebSocketTransport } from '../lib/esm/puppeteer/common/BrowserWebSocketTransport.js';
|
||||
import puppeteer from '../lib/esm/puppeteer/puppeteer.js';
|
||||
import expect from '../node_modules/expect/build-es5/index.js';
|
||||
import { getWebSocketEndpoint } from './helper.js';
|
||||
|
||||
describe('creating a Connection', () => {
|
||||
it('can create a real connection to the backend and send messages', async () => {
|
||||
const wsUrl = getWebSocketEndpoint();
|
||||
const transport = await BrowserWebSocketTransport.create(wsUrl);
|
||||
|
||||
const connection = new Connection(wsUrl, transport);
|
||||
const result = await connection.send('Browser.getVersion');
|
||||
/* We can't expect exact results as the version of Chrome/CDP might change
|
||||
* and we don't want flakey tests, so let's assert the structure, which is
|
||||
* enough to confirm the result was received successfully.
|
||||
*/
|
||||
expect(result).toEqual({
|
||||
protocolVersion: expect.any(String),
|
||||
jsVersion: expect.any(String),
|
||||
revision: expect.any(String),
|
||||
userAgent: expect.any(String),
|
||||
product: expect.any(String),
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('puppeteer.connect', () => {
|
||||
it('can connect over websocket and make requests to the backend', async () => {
|
||||
const wsUrl = getWebSocketEndpoint();
|
||||
const browser = await puppeteer.connect({
|
||||
browserWSEndpoint: wsUrl,
|
||||
});
|
||||
|
||||
const version = await browser.version();
|
||||
const versionLooksCorrect = /.+Chrome\/\d{2}/.test(version);
|
||||
expect(version).toEqual(expect.any(String));
|
||||
expect(versionLooksCorrect).toEqual(true);
|
||||
});
|
||||
});
|
@ -1,65 +0,0 @@
|
||||
/**
|
||||
* Copyright 2020 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { debug } from '../lib/esm/puppeteer/common/Debug.js';
|
||||
import expect from '../node_modules/expect/build-es5/index.js';
|
||||
|
||||
describe('debug', () => {
|
||||
let originalLog;
|
||||
let logs;
|
||||
beforeEach(() => {
|
||||
originalLog = console.log;
|
||||
logs = [];
|
||||
console.log = (...args) => {
|
||||
logs.push(args);
|
||||
};
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
console.log = originalLog;
|
||||
});
|
||||
|
||||
it('should return a function', async () => {
|
||||
expect(debug('foo')).toBeInstanceOf(Function);
|
||||
});
|
||||
|
||||
it('does not log to the console if __PUPPETEER_DEBUG global is not set', async () => {
|
||||
const debugFn = debug('foo');
|
||||
debugFn('lorem', 'ipsum');
|
||||
|
||||
expect(logs.length).toEqual(0);
|
||||
});
|
||||
|
||||
it('logs to the console if __PUPPETEER_DEBUG global is set to *', async () => {
|
||||
globalThis.__PUPPETEER_DEBUG = '*';
|
||||
const debugFn = debug('foo');
|
||||
debugFn('lorem', 'ipsum');
|
||||
|
||||
expect(logs.length).toEqual(1);
|
||||
expect(logs).toEqual([['foo:', 'lorem', 'ipsum']]);
|
||||
});
|
||||
|
||||
it('logs only messages matching the __PUPPETEER_DEBUG prefix', async () => {
|
||||
globalThis.__PUPPETEER_DEBUG = 'foo';
|
||||
const debugFoo = debug('foo');
|
||||
const debugBar = debug('bar');
|
||||
debugFoo('a');
|
||||
debugBar('b');
|
||||
|
||||
expect(logs.length).toEqual(1);
|
||||
expect(logs).toEqual([['foo:', 'a']]);
|
||||
});
|
||||
});
|
@ -1,27 +0,0 @@
|
||||
/**
|
||||
* Copyright 2020 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns the web socket endpoint for the backend of the browser the tests run
|
||||
* in. Used to create connections to that browser in Puppeteer for unit tests.
|
||||
*
|
||||
* It's available on window.__ENV__ because setup code in
|
||||
* web-test-runner.config.js puts it there. If you're changing this code (or
|
||||
* that code), make sure the other is updated accordingly.
|
||||
*/
|
||||
export function getWebSocketEndpoint() {
|
||||
return window.__ENV__.wsEndpoint;
|
||||
}
|
@ -42,13 +42,13 @@ Despite being named 'unit', these are integration tests, making sure public API
|
||||
- To run all tests:
|
||||
|
||||
```bash
|
||||
npm run unit
|
||||
npm run test:unit
|
||||
```
|
||||
|
||||
- **Important**: don't forget to first run TypeScript if you're testing local changes:
|
||||
|
||||
```bash
|
||||
npm run tsc && npm run unit
|
||||
npm run build:tsc && npm run test:unit
|
||||
```
|
||||
|
||||
- To run a specific test, substitute the `it` with `it.only`:
|
||||
@ -77,11 +77,11 @@ npm run tsc && npm run unit
|
||||
- To run tests in non-headless mode:
|
||||
|
||||
```bash
|
||||
HEADLESS=false npm run unit
|
||||
HEADLESS=false npm run test:unit
|
||||
```
|
||||
|
||||
- To run tests with custom browser executable:
|
||||
|
||||
```bash
|
||||
BINARY=<path-to-executable> npm run unit
|
||||
BINARY=<path-to-executable> npm run test:unit
|
||||
```
|
||||
|
@ -40,7 +40,7 @@ const fileExists = async (filePath) =>
|
||||
* place.
|
||||
*/
|
||||
async function compileTypeScript() {
|
||||
return exec('npm run tsc').catch((error) => {
|
||||
return exec('npm run build:tsc').catch((error) => {
|
||||
console.error('Error running TypeScript', error);
|
||||
process.exit(1);
|
||||
});
|
||||
|
@ -1,31 +0,0 @@
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const execSync = require('child_process').execSync;
|
||||
|
||||
// Compare current HEAD to upstream main SHA.
|
||||
// If they are not equal - refuse to publish since
|
||||
// we're not tip-of-tree.
|
||||
const upstream_sha = execSync(
|
||||
`git ls-remote https://github.com/puppeteer/puppeteer --tags main | cut -f1`
|
||||
).toString('utf8');
|
||||
const current_sha = execSync(`git rev-parse HEAD`).toString('utf8');
|
||||
if (upstream_sha.trim() !== current_sha.trim()) {
|
||||
console.log('REFUSING TO PUBLISH: this is not tip-of-tree!');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const package = require('../package.json');
|
||||
let version = package.version;
|
||||
const dashIndex = version.indexOf('-');
|
||||
if (dashIndex !== -1) version = version.substring(0, dashIndex);
|
||||
version += '-next.' + Date.now();
|
||||
console.log('Setting version to ' + version);
|
||||
package.version = version;
|
||||
fs.writeFileSync(
|
||||
path.join(__dirname, '..', 'package.json'),
|
||||
JSON.stringify(package, undefined, 2) + '\n'
|
||||
);
|
||||
|
||||
console.log(
|
||||
'IMPORTANT: you should update the pinned version of devtools-protocol to match the new revision.'
|
||||
);
|
@ -172,7 +172,7 @@ function runScript(scriptPath, revisionInfo) {
|
||||
function runUnitTest(pattern, revisionInfo) {
|
||||
const log = debug('bisect:rununittest');
|
||||
log('Running unit test');
|
||||
const child = spawn('npm run unit', ['--', '-g', pattern], {
|
||||
const child = spawn('npm run test:unit', ['--', '-g', pattern], {
|
||||
stdio: ['inherit', 'inherit', 'inherit', 'ipc'],
|
||||
shell: true,
|
||||
env: {
|
||||
|
@ -17,7 +17,6 @@
|
||||
|
||||
const assert = require('assert');
|
||||
const https = require('https');
|
||||
// run `npm run dev-install` if lib dir is missing
|
||||
const BrowserFetcher =
|
||||
require('../lib/cjs/puppeteer/node/BrowserFetcher.js').BrowserFetcher;
|
||||
|
||||
|
@ -146,7 +146,7 @@ async function run() {
|
||||
const clearExit = errors.length + warnings.length === 0;
|
||||
if (!clearExit && !process.env.GITHUB_ACTIONS) {
|
||||
console.log(
|
||||
'\nIs your lib/ directory up to date? You might need to `npm run tsc`.\n'
|
||||
'\nIs your lib/ directory up to date? You might need to `npm run build:tsc`.\n'
|
||||
);
|
||||
}
|
||||
|
||||
|
2
vendor/README.md
vendored
2
vendor/README.md
vendored
@ -9,5 +9,5 @@ The process for updating a vendored dependency is:
|
||||
1. `npm install {DEP NAME HERE}`
|
||||
2. `cp -r node_modules/DEP vendor`
|
||||
3. Update `eslintrc.js` to forbid importing DEP directly (see the `Mitt` rule already defined in there).
|
||||
4. Use the new DEP, and run `npm run tsc` to check everything compiles successfully.
|
||||
4. Use the new DEP, and run `npm run build:tsc` to check everything compiles successfully.
|
||||
5. If the dep ships as compiled JS, you may need to disable TypeScript checking the file. Add an entry to the `excludes` property of the TSConfig files in `vendor`. (again, see the entry that's already there for Mitt as an example). Don't forget to update both the ESM and CJS config files.
|
||||
|
@ -1,44 +0,0 @@
|
||||
/**
|
||||
* Copyright 2020 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
const { chromeLauncher } = require('@web/test-runner-chrome');
|
||||
|
||||
module.exports = {
|
||||
files: ['test-browser/**/*.spec.js'],
|
||||
browserStartTimeout: 60 * 1000,
|
||||
browsers: [
|
||||
chromeLauncher({
|
||||
async createPage({ browser }) {
|
||||
const page = await browser.newPage();
|
||||
page.evaluateOnNewDocument((wsEndpoint) => {
|
||||
window.__ENV__ = { wsEndpoint };
|
||||
}, browser.wsEndpoint());
|
||||
|
||||
return page;
|
||||
},
|
||||
}),
|
||||
],
|
||||
plugins: [
|
||||
{
|
||||
// turn expect UMD into an es module
|
||||
name: 'esmify-expect',
|
||||
transform(context) {
|
||||
if (context.path === '/node_modules/expect/build-es5/index.js') {
|
||||
return `const module = {}; const exports = {};\n${context.body};\n export default module.exports;`;
|
||||
}
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
Loading…
Reference in New Issue
Block a user