This directory hosts the API tests for DevTools. These tests run DevTools SDK and foundation models against a target page connected over CDP, without needing to spin up the full DevTools frontend UI. We use Mocha as the testing framework.
Each test receives a state object containing {inspectedPage, universe} as its first parameter:
describe('My API Test', () => { it('runs against inspected page', async ({inspectedPage, universe}) => { await inspectedPage.goToHtml('<h1>Hello World</h1>'); // Interact with universe models or inspectedPage... }); });
setup)Use the setup function inside a describe block to customize suite settings before universe is created:
creationOptions: Partial Universe.CreationOptions passed to Universe (e.g. hostConfig, inspectorFrontendHost, supportsEmulation, overrideAutoStartModels, settingsCreationOptions).targetUrl: Initial URL to navigate the inspected page to FIRST, before the Universe is attached.describe('Suite with custom hostConfig', () => { setup({ creationOptions: { hostConfig: { devToolsConsoleInsights: {enabled: true}, }, }, targetUrl: 'https://example.com', }); it('runs with custom config', async ({universe}) => { // ... }); });
Note that npm run test -- front_end runs unit tests as well. To run API tests specifically, specify a glob matching .test.api.ts files:
npm run test -- "front_end/**/*.test.api.ts"
To run a specific API test file:
npm run test -- front_end/foundation/Universe.test.api.ts
To use out/Debug instead of the default out/Default target directory:
npm run test -- -t Debug "front_end/**/*.test.api.ts"
To run API tests in debug mode:
npm run test -- --debug "front_end/**/*.test.api.ts"
Check the output of npm run test -- --help for an overview of all available options.
You can debug the API test process by inspecting the Node.js process that executes the test suite.
Passing --debug to npm run test starts the Node.js runner with inspector support enabled (--inspect). You can attach to the process by:
chrome://inspect in Chrome.