chore: improve docs and scripts (#9107)
This PR updates some docs and scripts related to the recent changes in the repository.
This commit is contained in:
parent
1fbc3c643f
commit
6a05d8e9c1
14
.github/workflows/ci.yml
vendored
14
.github/workflows/ci.yml
vendored
@ -134,10 +134,8 @@ jobs:
|
||||
node-version: latest
|
||||
- name: Install dependencies
|
||||
run: npm ci --ignore-scripts
|
||||
- name: Build libraries
|
||||
- name: Build packages
|
||||
run: npm run build
|
||||
- name: Build tests
|
||||
run: npm run build:test
|
||||
- name: Setup cache for Chromium binary
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
@ -149,7 +147,7 @@ jobs:
|
||||
if: ${{ matrix.os == 'ubuntu-latest' }}
|
||||
run: sudo apt-get install xvfb
|
||||
- name: Tests types
|
||||
run: npm run test:types
|
||||
run: npm run test-types
|
||||
- name: Run all tests (for non-Linux)
|
||||
if: ${{ matrix.os != 'ubuntu-latest' }}
|
||||
run: npm run test -- --test-suite ${{ matrix.suite }}
|
||||
@ -177,10 +175,8 @@ jobs:
|
||||
node-version: latest
|
||||
- name: Install dependencies
|
||||
run: npm ci --ignore-scripts
|
||||
- name: Build libraries
|
||||
- name: Build packages
|
||||
run: npm run build
|
||||
- name: Build tests
|
||||
run: npm run build:test
|
||||
- name: Setup cache for Firefox binary
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
@ -193,7 +189,7 @@ jobs:
|
||||
- name: Install linux dependencies.
|
||||
run: sudo apt-get install xvfb
|
||||
- name: Tests types
|
||||
run: npm run test:types
|
||||
run: npm run test-types
|
||||
- name: Run all tests
|
||||
run: xvfb-run --auto-servernum npm run test -- --test-suite ${{ matrix.suite }}
|
||||
|
||||
@ -247,7 +243,7 @@ jobs:
|
||||
with:
|
||||
name: packages
|
||||
- name: Test bundling and installation
|
||||
run: npm run test:install
|
||||
run: npm run test-install
|
||||
|
||||
docker-tests:
|
||||
name: Test Docker image
|
||||
|
6
.github/workflows/tot-ci.yml
vendored
6
.github/workflows/tot-ci.yml
vendored
@ -43,7 +43,7 @@ jobs:
|
||||
echo "Installing revision $REV"
|
||||
cat src/revisions.ts | sed "s/[0-9]\{6,\}/$REV/" > src/revisions.ts.replaced
|
||||
mv src/revisions.ts.replaced src/revisions.ts
|
||||
npm run build:test
|
||||
npm run build
|
||||
npm install
|
||||
|
||||
- name: Run unit tests in headless
|
||||
@ -81,7 +81,7 @@ jobs:
|
||||
echo "Installing revision $REV"
|
||||
cat src/revisions.ts | sed "s/[0-9]\{6,\}/$REV/" > src/revisions.ts.replaced
|
||||
mv src/revisions.ts.replaced src/revisions.ts
|
||||
npm run build:test
|
||||
npm run build
|
||||
npm install
|
||||
|
||||
- name: Run unit tests in headful
|
||||
@ -119,7 +119,7 @@ jobs:
|
||||
echo "Installing revision $REV"
|
||||
cat src/revisions.ts | sed "s/[0-9]\{6,\}/$REV/" > src/revisions.ts.replaced
|
||||
mv src/revisions.ts.replaced src/revisions.ts
|
||||
npm run build:test
|
||||
npm run build
|
||||
npm install
|
||||
|
||||
- name: Run unit tests in chrome headless
|
||||
|
@ -16,7 +16,7 @@ export declare class Keyboard
|
||||
|
||||
For finer control, you can use [Keyboard.down()](./puppeteer.keyboard.down.md), [Keyboard.up()](./puppeteer.keyboard.up.md), and [Keyboard.sendCharacter()](./puppeteer.keyboard.sendcharacter.md) to manually fire events as if they were generated from a real keyboard.
|
||||
|
||||
On MacOS, keyboard shortcuts like `⌘ A` -> Select All do not work. See [\#1313](https://github.com/puppeteer/puppeteer/issues/1313).
|
||||
On macOS, keyboard shortcuts like `⌘ A` -> Select All do not work. See [\#1313](https://github.com/puppeteer/puppeteer/issues/1313).
|
||||
|
||||
The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the `Keyboard` class.
|
||||
|
||||
|
@ -19,45 +19,78 @@ You generally only need to submit a CLA once, so if you've already submitted one
|
||||
(even if it was for a different project), you probably don't need to do it
|
||||
again.
|
||||
|
||||
## Getting Code
|
||||
## Getting started
|
||||
|
||||
1. Clone this repository
|
||||
|
||||
```bash
|
||||
```sh
|
||||
git clone https://github.com/puppeteer/puppeteer
|
||||
cd puppeteer
|
||||
```
|
||||
|
||||
2. Install the dependencies
|
||||
|
||||
```bash
|
||||
npm install
|
||||
# Downloads the Firefox binary for Firefox tests
|
||||
PUPPETEER_PRODUCT=firefox npm install
|
||||
```sh
|
||||
npm install # or PUPPETEER_PRODUCT=firefox npm install
|
||||
```
|
||||
|
||||
## Building Puppeteer
|
||||
3. Build all packages
|
||||
|
||||
Puppeteer has two configurations for building:
|
||||
|
||||
- `npm run build` (or `npm run build:prod`) - Builds Puppeteer and artifacts
|
||||
used in production.
|
||||
- `npm run build:test` - Builds Puppeteer, test runner, tests, and artifacts used in
|
||||
production.
|
||||
|
||||
## Testing Puppeteer
|
||||
|
||||
For browser testing, you can run
|
||||
|
||||
```bash
|
||||
npm run build:test && npm run test
|
||||
```sh
|
||||
npm run build
|
||||
```
|
||||
|
||||
We also have other tests such as `test:types` that tests types and
|
||||
`test:install` which tests installation. See the `package.json` for more tests
|
||||
(all prefixed with `test`).
|
||||
4. Run all tests
|
||||
|
||||
Puppeteer is using a custom test runner on top of Mocha that consults
|
||||
```sh
|
||||
npm test
|
||||
```
|
||||
|
||||
### macOS ARM and custom executables.
|
||||
|
||||
- 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 npm install
|
||||
PUPPETEER_EXPERIMENTAL_CHROMIUM_MAC_ARM=1 npm run test
|
||||
```
|
||||
|
||||
- To run tests with custom browser executable:
|
||||
|
||||
```bash
|
||||
BINARY=<path-to-chrome/firefox-executable> npm run test:chrome # Or npm run test:firefox
|
||||
```
|
||||
|
||||
## Building a single package
|
||||
|
||||
To build a single package, you can run
|
||||
|
||||
```sh
|
||||
npm run build --workspace <package> # e.g. puppeteer
|
||||
```
|
||||
|
||||
This will build all dependent packages automatically, so specifying a single packages is sufficient. This is all possible due to [wireit](https://github.com/google/wireit) which behaves similar to [GNU Make](https://www.gnu.org/software/make/).
|
||||
|
||||
## Removing stale artifacts
|
||||
|
||||
It's possible some generated artifacts (such as `packages/puppeteer-core/src/types.ts`) can become stale since these artifacts rely on complex conditions (such as names of distinct files) that cannot be captured by the build system. To clean artifacts, you can run
|
||||
|
||||
```sh
|
||||
npm run clean # or npm run clean --workspace <package>
|
||||
```
|
||||
|
||||
## Comprehensive testing
|
||||
|
||||
Outside of `npm test`, there are several other [`npm` scripts](https://docs.npmjs.com/cli/v8/using-npm/scripts) that are usually check through CI:
|
||||
|
||||
- `test-install` - Tests whether `puppeteer` and `puppeteer-core` install properly and are functional.
|
||||
- `test-types` - Tests the TypeScript types in `puppeteer` using [`tsd`](https://github.com/SamVerschueren/tsd).
|
||||
- `test:chrome:**` - Tests `puppeteer` on Chromium.
|
||||
- `test:firefox:**` - Tests `puppeteer` on Firefox.
|
||||
|
||||
The default `npm test` runs `test:{chrome,firefox}:headless` which is generally sufficient.
|
||||
|
||||
Puppeteer uses a custom test runner on top of Mocha that consults
|
||||
the [TestExpectations.json](https://github.com/puppeteer/puppeteer/blob/main/test/TestExpectations.json)
|
||||
to see if a given test result is expected or not. See more info about the test runner in [`tools/mochaRunner`](https://github.com/puppeteer/puppeteer/tree/main/tools/mochaRunner).
|
||||
|
||||
@ -94,38 +127,11 @@ npm run format
|
||||
|
||||
The following is a description of the primary folders in Puppeteer:
|
||||
|
||||
- `src` - contains the source code for Puppeteer.
|
||||
- `test/src` - contains the source code for Puppeteer tests.
|
||||
- `utils`/`scripts` - contains various scripts.
|
||||
- `tools/testserver` - contains the source code for our test servers in testing.
|
||||
- `tools/mochaRunner` - contains the source code for our test runner.
|
||||
- `compat` - contains code separated by module import type. See [`compat/README.md`](https://github.com/puppeteer/puppeteer/blob/main/compat/README.md) for details.
|
||||
- `packages` contains all public source code.
|
||||
- `test` contains all test source code.
|
||||
- `test-d` contains type tests using [`tsd`](https://github.com/SamVerschueren/tsd).
|
||||
- `third_party` contains all dependencies that we vendor into the final build. See the [`third_party/README.md`](https://github.com/puppeteer/puppeteer/blob/main/third_party/README.md) for details.
|
||||
|
||||
### Shipping CJS and ESM bundles
|
||||
|
||||
Puppeteer ships both CommonJS and ES modules, therefore we maintain two `tsconfig` files for each project: `tsconfig.esm.json` and `tsconfig.cjs.json`. At build time we compile twice, once for CommonJS and once for ES modules.
|
||||
|
||||
We compile into the `lib` directory which is what we publish on the npm repository and it's structured like so:
|
||||
|
||||
```
|
||||
lib
|
||||
- cjs
|
||||
- puppeteer <== the output of compiling `src/tsconfig.cjs.json`
|
||||
- third_party <== the output of compiling `third_party/tsconfig.cjs.json`
|
||||
- esm
|
||||
- puppeteer <== the output of compiling `src/tsconfig.esm.json`
|
||||
- third_party <== the output of compiling `third_party/tsconfig.json`
|
||||
```
|
||||
|
||||
### `tsconfig.json` for the tests
|
||||
|
||||
We also maintain `test/tsconfig.json`. This is used to incrementally compile the unit test `*.spec.ts` files. Tests are run against the compiled code we ship to users so it gives us more confidence in our compiled output being correct.
|
||||
|
||||
### Root `tsconfig.json`
|
||||
|
||||
The root `tsconfig.json` exists for the API Extractor; it has to find a `tsconfig.json` in the project's root directory.
|
||||
- `tools` contains miscellaneous scripts that are used in building and etc.
|
||||
- `tools/mochaRunner` - contains the source code for our test runner.
|
||||
|
||||
## API guidelines
|
||||
|
||||
@ -135,7 +141,7 @@ When authoring new API methods, consider the following:
|
||||
- Methods are used in favor of getters/setters.
|
||||
- The only exception is namespaces, e.g. `page.keyboard` and `page.coverage`
|
||||
- All string literals must be small case. This includes event names and option values.
|
||||
- Avoid adding "sugar" API (API that is trivially implementable in user-space) unless they're **very** demanded.
|
||||
- Avoid adding "sugar" API (API that is trivially implementable in user-space) unless they're **extremely** demanded.
|
||||
|
||||
## Commit messages
|
||||
|
||||
@ -168,7 +174,7 @@ Each change to Puppeteer should be thoroughly documented using TSDoc comments. R
|
||||
|
||||
## Running the documentation site locally
|
||||
|
||||
1. At root, install all dependencies with `npm i`.
|
||||
1. At root, install all dependencies with `npm i --ignore-scripts`.
|
||||
2. run `npm run docs` which will generate all the `.md` files on `puppeteer/docs/api`.
|
||||
3. run `npm i` in `puppeteer/website`.
|
||||
4. run `npm start` in `puppeteer/website`.
|
||||
@ -186,70 +192,13 @@ A barrier for introducing new installation dependencies is especially high:
|
||||
|
||||
There are additional considerations for dependencies that are environment agonistic. See the [`third_party/README.md`](https://github.com/puppeteer/puppeteer/blob/main/third_party/README.md) for details.
|
||||
|
||||
## Running & Writing Tests
|
||||
## Testing tips
|
||||
|
||||
- Every feature should be accompanied by a test.
|
||||
- Every public api event/method should be accompanied by a test.
|
||||
- Tests should not depend on external services.
|
||||
- Tests should work on all three platforms: Mac, Linux and Win. This is especially important for screenshot tests.
|
||||
|
||||
Puppeteer tests are located in [the `test` directory](https://github.com/puppeteer/puppeteer/blob/main/test/) and are written using Mocha. See [`test/README.md`](https://github.com/puppeteer/puppeteer/blob/main/test/README.md) for more details.
|
||||
|
||||
The tests are making sure public API methods and events work as expected.
|
||||
|
||||
- To run all tests:
|
||||
|
||||
```bash
|
||||
npm run test
|
||||
```
|
||||
|
||||
- To run a specific test, substitute the `it` with `it.only`:
|
||||
|
||||
```ts
|
||||
...
|
||||
it.only('should work', async function({server, page}) {
|
||||
const response = await page.goto(server.EMPTY_PAGE);
|
||||
expect(response.ok).toBe(true);
|
||||
});
|
||||
```
|
||||
|
||||
- To disable a specific test, substitute the `it` with `it.skip`:
|
||||
|
||||
```ts
|
||||
...
|
||||
// Using "it.skip" to skip specific test
|
||||
it.skip('should work', async function({server, page}) {
|
||||
const response = await page.goto(server.EMPTY_PAGE);
|
||||
expect(response.ok).toBe(true);
|
||||
});
|
||||
```
|
||||
|
||||
- To run Chrome tests in non-headless mode:
|
||||
|
||||
```bash
|
||||
npm run test:chrome:headful
|
||||
```
|
||||
|
||||
- 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 npm install
|
||||
npm run test:firefox
|
||||
```
|
||||
|
||||
- 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 npm install
|
||||
PUPPETEER_EXPERIMENTAL_CHROMIUM_MAC_ARM=1 npm run test:chrome:headless
|
||||
```
|
||||
|
||||
- To run tests with custom browser executable:
|
||||
|
||||
```bash
|
||||
BINARY=<path-to-executable> npm run test:chrome:headless # Or npm run test:firefox
|
||||
```
|
||||
|
||||
If a test is expected to fail on certain configurations or became flaky, update [TestExpectations.json](https://github.com/puppeteer/puppeteer/blob/main/test/TestExpectations.json)
|
||||
to reflect that. See more info about TestExpectations.json in [`tools/mochaRunner`](https://github.com/puppeteer/puppeteer/tree/main/tools/mochaRunner).
|
||||
|
||||
@ -267,28 +216,25 @@ See [Debugging Tips](https://github.com/puppeteer/puppeteer/blob/main/README.md#
|
||||
|
||||
The following steps are needed to update the Chromium version.
|
||||
|
||||
1. Find a suitable Chromium revision
|
||||
Not all revisions have builds for all platforms, so we need to find one that does.
|
||||
To do so, run `tools/check_availability.js -rd` to find the latest suitable `dev` Chromium revision (see `tools/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 check:protocol-revision`.
|
||||
If it fails, update `package.json` with the expected `devtools-protocol` version.
|
||||
1. Run `npm run build && npm run build:test` and `npm install`.
|
||||
1. Run `npm test` 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.
|
||||
1. Find a suitable Chromium revision. Not all revisions have builds for all platforms, so we need to find one that does. The easiest way is to run `tools/check_availability.js -rd` to find the latest suitable `dev` Chromium revision (see `tools/check_availability.js -help` for more options).
|
||||
2. Update `packages/puppeteer-core/src/revisions.ts` with the found revision number.
|
||||
3. Update `versions.js` with the new Chromium-to-Puppeteer version mapping and update `lastMaintainedChromiumVersion` with the latest stable Chrome version.
|
||||
4. Run `npm run check:protocol-revision`. If it fails, update `package.json` with the expected `devtools-protocol` version.
|
||||
5. Run `npm run build` and `npm install`.
|
||||
6. Run `npm test` 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).
|
||||
7. 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)'`.
|
||||
|
||||
### Bisecting upstream changes
|
||||
|
||||
Sometimes, performing a Chromium roll causes tests to fail. To figure out the cause, you need to bisect Chromium revisions to figure out the earliest possible revision that changed the behavior. The script in `tools/bisect.js` can be helpful here. Given a pattern for one or more unit tests, it will automatically bisect the current range:
|
||||
Sometimes, performing a Chromium roll causes tests to fail. To figure out the cause, you need to bisect Chromium revisions to figure out the earliest possible revision that changed the behavior. The `bisect` script can be helpful here. Given a pattern for one or more unit tests, it will automatically bisect the current range:
|
||||
|
||||
```sh
|
||||
node tools/bisect.js --good 686378 --bad 706915 script.js
|
||||
node tools/bisect.js --unit-test Response.fromCache
|
||||
npm run bisect -- --good 686378 --bad 706915 script.js
|
||||
npm run bisect -- --unit-test Response.fromCache
|
||||
```
|
||||
|
||||
By default, it will use the Chromium revision in `src/revisions.ts` from the `main` branch and from the working tree to determine the range to bisect.
|
||||
By default, it will use the Chromium revision in `packages/puppeteer-core/src/revisions.ts` from the `main` branch and from the working tree to determine the range to bisect.
|
||||
|
||||
## Releasing to npm
|
||||
|
||||
|
18
package-lock.json
generated
18
package-lock.json
generated
@ -7,7 +7,8 @@
|
||||
"name": "puppeteer-repo",
|
||||
"hasInstallScript": true,
|
||||
"workspaces": [
|
||||
"packages/*"
|
||||
"packages/*",
|
||||
"test"
|
||||
],
|
||||
"devDependencies": {
|
||||
"@commitlint/cli": "17.1.2",
|
||||
@ -7033,6 +7034,10 @@
|
||||
"node": ">=6"
|
||||
}
|
||||
},
|
||||
"node_modules/test": {
|
||||
"resolved": "test",
|
||||
"link": true
|
||||
},
|
||||
"node_modules/test-exclude": {
|
||||
"version": "6.0.0",
|
||||
"resolved": "https://registry.npmjs.org/test-exclude/-/test-exclude-6.0.0.tgz",
|
||||
@ -7796,6 +7801,11 @@
|
||||
"mime": "3.0.0",
|
||||
"ws": "8.9.0"
|
||||
}
|
||||
},
|
||||
"test": {
|
||||
"dependencies": {
|
||||
"puppeteer": "file:../packages/puppeteer"
|
||||
}
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
@ -12986,6 +12996,12 @@
|
||||
"readable-stream": "^3.1.1"
|
||||
}
|
||||
},
|
||||
"test": {
|
||||
"version": "file:test",
|
||||
"requires": {
|
||||
"puppeteer": "file:../packages/puppeteer"
|
||||
}
|
||||
},
|
||||
"test-exclude": {
|
||||
"version": "6.0.0",
|
||||
"resolved": "https://registry.npmjs.org/test-exclude/-/test-exclude-6.0.0.tgz",
|
||||
|
39
package.json
39
package.json
@ -6,13 +6,13 @@
|
||||
"url": "https://github.com/puppeteer/puppeteer"
|
||||
},
|
||||
"scripts": {
|
||||
"build:test": "wireit",
|
||||
"bisect": "tsx tools/bisect.ts",
|
||||
"build": "npm run build --workspaces --if-present",
|
||||
"check:pinned-deps": "tsx tools/ensure-pinned-deps",
|
||||
"check": "npm run check --workspaces --if-present && run-p check:*",
|
||||
"clean": "npm run clean --workspaces --if-present && rimraf **/.wireit",
|
||||
"commitlint": "commitlint --from=HEAD~1",
|
||||
"debug": "npm run build:test && mocha --inspect-brk",
|
||||
"debug": "mocha --inspect-brk",
|
||||
"docs": "run-s build generate:markdown",
|
||||
"format:eslint": "eslint --ext js --ext ts --fix .",
|
||||
"format:prettier": "prettier --write .",
|
||||
@ -23,35 +23,17 @@
|
||||
"lint": "run-s lint:prettier lint:eslint",
|
||||
"postinstall": "npm run postinstall --workspaces --if-present",
|
||||
"prepare": "husky install",
|
||||
"test:chrome:headful": "npm run test -- --test-suite chrome-headful",
|
||||
"test:chrome:headless-chrome": "npm run test -- --test-suite chrome-new-headless",
|
||||
"test:chrome:headless": "npm run test -- --test-suite chrome-headless",
|
||||
"test-install": "test/test-install.sh",
|
||||
"test-types": "tsd -t packages/puppeteer",
|
||||
"test:chrome:headful": "npm test -- --test-suite chrome-headful",
|
||||
"test:chrome:headless-chrome": "npm test -- --test-suite chrome-new-headless",
|
||||
"test:chrome:headless": "npm test -- --test-suite chrome-headless",
|
||||
"test:chrome": "run-s test:chrome:*",
|
||||
"test:firefox:headful": "npm run test -- --test-suite firefox-headful",
|
||||
"test:firefox:headless": "npm run test -- --test-suite firefox-headless",
|
||||
"test:firefox:headful": "npm test -- --test-suite firefox-headful",
|
||||
"test:firefox:headless": "npm test -- --test-suite firefox-headless",
|
||||
"test:firefox": "run-s test:firefox:*",
|
||||
"test:install": "test/test-install.sh",
|
||||
"test:types": "tsd -t packages/puppeteer",
|
||||
"test": "cross-env PUPPETEER_DEFERRED_PROMISE_DEBUG_TIMEOUT=20000 node tools/mochaRunner/lib/main.js"
|
||||
},
|
||||
"wireit": {
|
||||
"build:test": {
|
||||
"command": "tsc -b test",
|
||||
"clean": "if-file-deleted",
|
||||
"dependencies": [
|
||||
"./packages/puppeteer:build",
|
||||
"./packages/puppeteer-core:build",
|
||||
"./packages/testserver:build"
|
||||
],
|
||||
"files": [
|
||||
"test/src/**"
|
||||
],
|
||||
"output": [
|
||||
"test/build/**",
|
||||
"test/tsconfig.tsbuildinfo"
|
||||
]
|
||||
}
|
||||
},
|
||||
"devDependencies": {
|
||||
"@commitlint/cli": "17.1.2",
|
||||
"@commitlint/config-conventional": "17.1.0",
|
||||
@ -121,6 +103,7 @@
|
||||
"zod": "3.19.1"
|
||||
},
|
||||
"workspaces": [
|
||||
"packages/*"
|
||||
"packages/*",
|
||||
"test"
|
||||
]
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ type KeyDescription = Required<
|
||||
* {@link Keyboard.up}, and {@link Keyboard.sendCharacter}
|
||||
* to manually fire events as if they were generated from a real keyboard.
|
||||
*
|
||||
* On MacOS, keyboard shortcuts like `⌘ A` -\> Select All do not work.
|
||||
* On macOS, keyboard shortcuts like `⌘ A` -\> Select All do not work.
|
||||
* See {@link https://github.com/puppeteer/puppeteer/issues/1313 | #1313}.
|
||||
*
|
||||
* @example
|
||||
|
27
test/package.json
Normal file
27
test/package.json
Normal file
@ -0,0 +1,27 @@
|
||||
{
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"build": "wireit",
|
||||
"clean": "tsc -b --clean && rimraf build"
|
||||
},
|
||||
"wireit": {
|
||||
"build": {
|
||||
"command": "tsc -b",
|
||||
"clean": "if-file-deleted",
|
||||
"dependencies": [
|
||||
"../packages/puppeteer:build",
|
||||
"../packages/testserver:build"
|
||||
],
|
||||
"files": [
|
||||
"src/**"
|
||||
],
|
||||
"output": [
|
||||
"build/**",
|
||||
"tsconfig.tsbuildinfo"
|
||||
]
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"puppeteer": "file:../packages/puppeteer"
|
||||
}
|
||||
}
|
@ -7,7 +7,7 @@ set -e
|
||||
# 2. The install script works and correctly exits without errors
|
||||
# 3. Requiring/importing Puppeteer from Node works.
|
||||
|
||||
# MacOS doesn't support realpath
|
||||
# macOS doesn't support realpath
|
||||
realpath() {
|
||||
[[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"
|
||||
}
|
||||
|
@ -15,20 +15,22 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
const URL = require('url');
|
||||
const debug = require('debug');
|
||||
const pptr = require('..');
|
||||
const browserFetcher = pptr.createBrowserFetcher();
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const {fork, spawn, execSync} = require('child_process');
|
||||
import {execSync, fork, spawn} from 'child_process';
|
||||
import debug from 'debug';
|
||||
import fs from 'fs';
|
||||
import minimist from 'minimist';
|
||||
import path from 'path';
|
||||
import {BrowserFetcher, BrowserFetcherRevisionInfo} from 'puppeteer';
|
||||
import URL from 'url';
|
||||
|
||||
import ProgressBar from 'progress';
|
||||
|
||||
const COLOR_RESET = '\x1b[0m';
|
||||
const COLOR_RED = '\x1b[31m';
|
||||
const COLOR_GREEN = '\x1b[32m';
|
||||
const COLOR_YELLOW = '\x1b[33m';
|
||||
|
||||
const argv = require('minimist')(process.argv.slice(2), {});
|
||||
const argv = minimist(process.argv.slice(2), {});
|
||||
|
||||
const help = `
|
||||
Usage:
|
||||
@ -88,9 +90,8 @@ if (!argv.script && !argv['unit-test']) {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const scriptPath = argv.script ? path.resolve(argv.script) : null;
|
||||
|
||||
if (argv.script && !fs.existsSync(scriptPath)) {
|
||||
const scriptPath = argv.script && path.resolve(argv.script);
|
||||
if (scriptPath && !fs.existsSync(scriptPath)) {
|
||||
console.log(
|
||||
COLOR_RED +
|
||||
'ERROR: Expected to be given a path to a script to run' +
|
||||
@ -100,6 +101,8 @@ if (argv.script && !fs.existsSync(scriptPath)) {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const browserFetcher = new BrowserFetcher();
|
||||
|
||||
(async (scriptPath, good, bad, pattern, noCache) => {
|
||||
const span = Math.abs(good - bad);
|
||||
console.log(
|
||||
@ -114,7 +117,8 @@ if (argv.script && !fs.existsSync(scriptPath)) {
|
||||
if (!revision || revision === good || revision === bad) {
|
||||
break;
|
||||
}
|
||||
let info = browserFetcher.revisionInfo(revision);
|
||||
let info: BrowserFetcherRevisionInfo | undefined =
|
||||
browserFetcher.revisionInfo(revision);
|
||||
const shouldRemove = noCache && !info.local;
|
||||
info = await downloadRevision(revision);
|
||||
const exitCode = await (pattern
|
||||
@ -201,13 +205,12 @@ function runUnitTest(pattern, revisionInfo) {
|
||||
async function downloadRevision(revision) {
|
||||
const log = debug('bisect:download');
|
||||
log(`Downloading ${revision}`);
|
||||
let progressBar = null;
|
||||
let progressBar: ProgressBar | undefined;
|
||||
let lastDownloadedBytes = 0;
|
||||
return await browserFetcher.download(
|
||||
revision,
|
||||
(downloadedBytes, totalBytes) => {
|
||||
if (!progressBar) {
|
||||
const ProgressBar = require('progress');
|
||||
progressBar = new ProgressBar(
|
||||
`- downloading Chromium r${revision} - ${toMegabytes(
|
||||
totalBytes
|
||||
@ -269,15 +272,18 @@ async function revisionToSha(revision) {
|
||||
return json.git_sha;
|
||||
}
|
||||
|
||||
function fetchJSON(url) {
|
||||
return new Promise((resolve, reject) => {
|
||||
async function fetchJSON(url: string): Promise<{git_sha: string}> {
|
||||
const agent = url.startsWith('https://')
|
||||
? require('https')
|
||||
: require('http');
|
||||
const options = URL.parse(url);
|
||||
options.method = 'GET';
|
||||
options.headers = {
|
||||
? await import('https')
|
||||
: await import('http');
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const options = {
|
||||
...URL.parse(url),
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
};
|
||||
const req = agent.request(options, function (res) {
|
||||
let result = '';
|
||||
@ -296,14 +302,13 @@ function fetchJSON(url) {
|
||||
});
|
||||
}
|
||||
|
||||
function getChromiumRevision(gitRevision = null) {
|
||||
const fileName = 'src/revisions.ts';
|
||||
function getChromiumRevision(gitRevision?: string) {
|
||||
const fileName = 'packages/puppeteer-core/src/revisions.ts';
|
||||
const command = gitRevision
|
||||
? `git show ${gitRevision}:${fileName}`
|
||||
: `cat ${fileName}`;
|
||||
const result = execSync(command, {
|
||||
encoding: 'utf8',
|
||||
shell: true,
|
||||
});
|
||||
|
||||
const m = result.match(/chromium: '(\d+)'/);
|
@ -53,8 +53,8 @@ For browser testing, you can run
|
||||
npm run build:test && npm run test
|
||||
```
|
||||
|
||||
We also have other tests such as `test:types` that tests types and
|
||||
`test:install` which tests installation. See the `package.json` for more tests
|
||||
We also have other tests such as `test-types` that tests types and
|
||||
`test-install` which tests installation. See the `package.json` for more tests
|
||||
(all prefixed with `test`).
|
||||
|
||||
Puppeteer is using a custom test runner on top of Mocha that consults
|
||||
|
Loading…
Reference in New Issue
Block a user