3e80667048
<!-- Thanks for submitting a pull request! Please provide enough information so that others can review your pull request. --> **What kind of change does this PR introduce?** types fix **Did you add tests for your changes?** No **If relevant, did you update the documentation?** Not relevant **Summary** I am updating `import`s of `devtools-protocol` to always use named import instead of the default. For some reason, typescript doesn't understand when it is imported as default. ``` node_modules/puppeteer-core/lib/esm/puppeteer/common/TargetManager.d.ts:23:59 - error TS2694: Namespace '"/Users/kyrylo/pacakge/node_modules/puppeteer-core/node_modules/devtools-protocol/types/protocol"' has no exported member 'Target'. 23 export declare type TargetFactory = (targetInfo: Protocol.Target.TargetInfo, session?: CDPSession) => Target; ~~~~~~ Found 1 error in node_modules/puppeteer-core/lib/esm/puppeteer/common/TargetManager.d.ts:23 ``` **Does this PR introduce a breaking change?** No <!-- If this PR introduces a breaking change, please describe the impact and a migration path for existing applications. --> **Other information** I am updating `import`s of `devtools-protocol` to always use named import instead of the default. |
||
---|---|---|
.. | ||
assets | ||
fixtures | ||
golden-chromium | ||
golden-firefox | ||
installation | ||
src | ||
.eslintrc.js | ||
package.json | ||
README.md | ||
TestExpectations.json | ||
TestSuites.json | ||
tsconfig.json |
Puppeteer tests
Unit tests in Puppeteer are written using Mocha as the test runner and Expect as the assertions library.
Test state
We have some common setup that runs before each test and is defined in mocha-utils.js
.
You can use the getTestState
function to read state. It exposes the following that you can use in your tests. These will be reset/tidied between tests automatically for you:
puppeteer
: an instance of the Puppeteer library. This is exactly what you'd get if you ranrequire('puppeteer')
.puppeteerPath
: the path to the root source file for Puppeteer.defaultBrowserOptions
: the default options the Puppeteer browser is launched from in test mode, so tests can use them and override if required.server
: a dummy test server instance (seepackages/testserver
for more).httpsServer
: a dummy test server HTTPS instance (seepackages/testserver
for more).isFirefox
: true if running in Firefox.isChrome
: true if running Chromium.isHeadless
: true if the test is in headless mode.
If your test needs a browser instance, you can use the setupTestBrowserHooks()
function which will automatically configure a browser that will be cleaned between each test suite run. You access this via getTestState()
.
If your test needs a Puppeteer page and context, you can use the setupTestPageAndContextHooks()
function which will configure these. You can access page
and context
from getTestState()
once you have done this.
The best place to look is an existing test to see how they use the helpers.
Skipping tests in specific conditions
To skip tests edit the TestExpecations file. See test runner documentation for more details.
Running tests
- To run all tests applicable for your platform:
npm test
- Important: don't forget to first build the code if you're testing local changes:
npm run build && npm test
- To run a specific test, substitute the
it
withit.only
:
...
it.only('should work', async function() {
const {server, page} = getTestState();
const response = await page.goto(server.EMPTY_PAGE);
expect(response.ok).toBe(true);
});
- To disable a specific test, substitute the
it
withit.skip
:
...
it.skip('should work', async function({server, page}) {
const {server, page} = getTestState();
const response = await page.goto(server.EMPTY_PAGE);
expect(response.ok).toBe(true);
});
- To run Chrome headful tests:
npm run test:chrome:headful
- To run tests with custom browser executable:
BINARY=<path-to-executable> npm run test:chrome:headless # Or npm run test:firefox