[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core(fr): add snapshot and timespan support to no-unload-listeners audit #12830

Merged
merged 7 commits into from
Jul 28, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
unit test
  • Loading branch information
adamraine committed Jul 21, 2021
commit 4ff27577fc73c831d962d563e450b85077c478e3
32 changes: 32 additions & 0 deletions lighthouse-core/test/gather/gatherers/js-usage-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const Driver = require('../../../gather/driver.js');
const Connection = require('../../../gather/connections/connection.js');
const JsUsage = require('../../../gather/gatherers/js-usage.js');
const {createMockSendCommandFn, createMockOnFn} = require('../mock-commands.js');
const {createMockContext} = require('../../fraggle-rock/gather/mock-driver.js');
const {flushAllTimersAndMicrotasks} = require('../../test-utils.js');

describe('JsUsage gatherer', () => {
Expand Down Expand Up @@ -105,4 +106,35 @@ describe('JsUsage gatherer', () => {
}
`);
});

it('uses best effort coverage in snapshot mode', async () => {
const coverage = [{scriptId: '1', url: 'https://www.example.com'}];
const context = createMockContext();
context.gatherMode = 'snapshot';
context.driver._session.on
.mockEvent('Debugger.scriptParsed', {
scriptId: '1',
embedderName: 'https://www.example.com',
});
context.driver._session.sendCommand
// Events are flushed on domain enable.
.mockResponse('Debugger.enable', async () => await flushAllTimersAndMicrotasks)
.mockResponse('Profiler.enable', {})
.mockResponse('Profiler.getBestEffortCoverage', {result: coverage})
.mockResponse('Profiler.disable', {})
.mockResponse('Debugger.disable', {});

const artifact = await new JsUsage().getArtifact(context.asContext());

expect(artifact).toMatchInlineSnapshot(`
Object {
"https://www.example.com": Array [
Object {
"scriptId": "1",
"url": "https://www.example.com",
},
],
}
`);
});
});