2020-08-03 23:41:48 +03:00
|
|
|
/**
|
|
|
|
* Copyright 2018 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.
|
|
|
|
*/
|
2020-09-03 07:43:38 +03:00
|
|
|
|
2022-03-26 02:05:50 +03:00
|
|
|
import { contextTest as it, expect } from '../../config/browserTest';
|
2021-04-05 19:18:56 +03:00
|
|
|
|
2021-10-26 23:45:53 +03:00
|
|
|
it.skip(({ trace }) => trace === 'on');
|
2021-08-20 05:09:19 +03:00
|
|
|
|
2021-09-27 19:58:08 +03:00
|
|
|
it('should work', async function({ page, server }) {
|
2021-05-09 03:45:04 +03:00
|
|
|
await page.coverage.startJSCoverage();
|
2021-05-25 18:10:43 +03:00
|
|
|
await page.goto(server.PREFIX + '/jscoverage/simple.html', { waitUntil: 'load' });
|
2021-05-09 03:45:04 +03:00
|
|
|
const coverage = await page.coverage.stopJSCoverage();
|
|
|
|
expect(coverage.length).toBe(1);
|
|
|
|
expect(coverage[0].url).toContain('/jscoverage/simple.html');
|
|
|
|
expect(coverage[0].functions.find(f => f.functionName === 'foo').ranges[0].count).toEqual(1);
|
|
|
|
});
|
2020-08-03 23:41:48 +03:00
|
|
|
|
2021-09-27 19:58:08 +03:00
|
|
|
it('should report sourceURLs', async function({ page, server }) {
|
2021-05-09 03:45:04 +03:00
|
|
|
await page.coverage.startJSCoverage();
|
|
|
|
await page.goto(server.PREFIX + '/jscoverage/sourceurl.html');
|
|
|
|
const coverage = await page.coverage.stopJSCoverage();
|
|
|
|
expect(coverage.length).toBe(1);
|
|
|
|
expect(coverage[0].url).toBe('nicename.js');
|
|
|
|
});
|
2020-08-03 23:41:48 +03:00
|
|
|
|
2021-09-27 19:58:08 +03:00
|
|
|
it('should ignore eval() scripts by default', async function({ page, server }) {
|
2021-05-09 03:45:04 +03:00
|
|
|
await page.coverage.startJSCoverage();
|
|
|
|
await page.goto(server.PREFIX + '/jscoverage/eval.html');
|
|
|
|
const coverage = await page.coverage.stopJSCoverage();
|
|
|
|
expect(coverage.length).toBe(1);
|
|
|
|
});
|
2020-08-03 23:41:48 +03:00
|
|
|
|
2021-09-27 19:58:08 +03:00
|
|
|
it('shouldn\'t ignore eval() scripts if reportAnonymousScripts is true', async function({ page, server }) {
|
|
|
|
await page.coverage.startJSCoverage({ reportAnonymousScripts: true });
|
2021-05-09 03:45:04 +03:00
|
|
|
await page.goto(server.PREFIX + '/jscoverage/eval.html');
|
|
|
|
const coverage = await page.coverage.stopJSCoverage();
|
|
|
|
expect(coverage.find(entry => entry.url === '').source).toBe('console.log("foo")');
|
|
|
|
expect(coverage.length).toBe(2);
|
|
|
|
});
|
2020-08-03 23:41:48 +03:00
|
|
|
|
2021-09-27 19:58:08 +03:00
|
|
|
it('should report multiple scripts', async function({ page, server }) {
|
2021-05-09 03:45:04 +03:00
|
|
|
await page.coverage.startJSCoverage();
|
|
|
|
await page.goto(server.PREFIX + '/jscoverage/multiple.html');
|
|
|
|
const coverage = await page.coverage.stopJSCoverage();
|
|
|
|
expect(coverage.length).toBe(2);
|
|
|
|
coverage.sort((a, b) => a.url.localeCompare(b.url));
|
|
|
|
expect(coverage[0].url).toContain('/jscoverage/script1.js');
|
|
|
|
expect(coverage[1].url).toContain('/jscoverage/script2.js');
|
|
|
|
});
|
2020-08-03 23:41:48 +03:00
|
|
|
|
2021-09-27 19:58:08 +03:00
|
|
|
it('should report scripts across navigations when disabled', async function({ page, server }) {
|
|
|
|
await page.coverage.startJSCoverage({ resetOnNavigation: false });
|
2021-05-09 03:45:04 +03:00
|
|
|
await page.goto(server.PREFIX + '/jscoverage/multiple.html');
|
|
|
|
await page.goto(server.EMPTY_PAGE);
|
|
|
|
const coverage = await page.coverage.stopJSCoverage();
|
|
|
|
expect(coverage.length).toBe(2);
|
|
|
|
});
|
2020-08-03 23:41:48 +03:00
|
|
|
|
2021-09-27 19:58:08 +03:00
|
|
|
it('should NOT report scripts across navigations when enabled', async function({ page, server }) {
|
2021-05-09 03:45:04 +03:00
|
|
|
await page.coverage.startJSCoverage(); // Enabled by default.
|
|
|
|
await page.goto(server.PREFIX + '/jscoverage/multiple.html');
|
|
|
|
await page.goto(server.EMPTY_PAGE);
|
|
|
|
const coverage = await page.coverage.stopJSCoverage();
|
|
|
|
expect(coverage.length).toBe(0);
|
|
|
|
});
|
2020-08-03 23:41:48 +03:00
|
|
|
|
2021-09-27 19:58:08 +03:00
|
|
|
it('should not hang when there is a debugger statement', async function({ page, server }) {
|
2021-05-09 03:45:04 +03:00
|
|
|
await page.coverage.startJSCoverage();
|
|
|
|
await page.goto(server.EMPTY_PAGE);
|
|
|
|
await page.evaluate(() => {
|
|
|
|
debugger; // eslint-disable-line no-debugger
|
2020-08-03 23:41:48 +03:00
|
|
|
});
|
2021-05-09 03:45:04 +03:00
|
|
|
await page.coverage.stopJSCoverage();
|
2021-02-25 00:28:22 +03:00
|
|
|
});
|