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

Set up and improve code coverage #943

Merged
merged 35 commits into from
Jun 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
de6ba6c
Set up code coverage thresholds
macbre May 28, 2021
c9c505e
Merge remote-tracking branch 'origin/devel' into coverage
macbre May 31, 2021
deb8557
windowPerformance: fix "ReferenceError: cov_xxx is not defined"
macbre May 31, 2021
361af7f
More /* istanbul ignore next */
macbre May 31, 2021
60d7326
Name all anonymous function to ease debugging
macbre May 31, 2021
6bc710b
Add missing instanbul annotation for page.evaluateOnNewDocument() call
macbre Jun 1, 2021
558f2e1
test/modules/mock.js excluded from code coverage
macbre Jun 1, 2021
f28eacf
lib/index.js: skip coverage for two code branches
macbre Jun 1, 2021
5008ce8
jest: add --detectOpenHandles flag
macbre Jun 2, 2021
6485a29
lib/index.js: move /* istanbul ignore next */
macbre Jun 2, 2021
8479a55
lib/index.js: prettier
macbre Jun 2, 2021
a373889
Bump coverage requirements
macbre Jun 2, 2021
546bcd5
Exclude test/integration-test-extra.js from coverage report
macbre Jun 2, 2021
c519c6d
lib/browser.js: skip coverage for Docker/AWSlambda-specific cases
macbre Jun 2, 2021
08d27bf
lib/browser.js: skip coverage for catch blocks
macbre Jun 2, 2021
6200eed
Code coverage to be improved
macbre Jun 2, 2021
a99d1fe
npm run unit-test: include test/results.test.js
macbre Jun 2, 2021
557f62b
Test results.incrMetric()
macbre Jun 2, 2021
0f6984f
Test case for results.getAllOffenders()
macbre Jun 2, 2021
5652790
Test cases for results.getUrl() and results.getGenerator()
macbre Jun 2, 2021
fc79623
Add test case for pre-filled Results()
macbre Jun 2, 2021
85262c8
cacheHits: test case for Age greater then zero
macbre Jun 2, 2021
babdc99
modules/cacheHits/cacheHits.js now has 100% code coverage, yay!
macbre Jun 2, 2021
647a076
core/results.js now has 100% code coverage, yay!
macbre Jun 2, 2021
b7e1c6e
core/resumodules/keepAlive.js100% code coverage, yay!
macbre Jun 3, 2021
53015d3
test/modules/mock.js: improve metrics and offenders assertions when t…
macbre Jun 3, 2021
39b136e
modules/cacheHits/cacheHits.js: improve Age header value parsing
macbre Jun 3, 2021
af08aec
prettier: skip coverage/ directory
macbre Jun 3, 2021
0e48332
npm install fast-stats
macbre Jun 3, 2021
e323df9
Use npm module instead of lib/fast-stats.js file
macbre Jun 3, 2021
1b6385c
core/results.js nowts.js100% code coverage, yay!
macbre Jun 3, 2021
1498a12
core/resumodules/domains/domains.js100% code coverage, yay!
macbre Jun 3, 2021
64f96fa
modules/staticAssets now has 100% code coverage, yay!
macbre Jun 3, 2021
220ff3f
modules/requestsStats now has 100% code coverage, yay!
macbre Jun 3, 2021
0d1af8b
jest: bump coverage thresholds
macbre Jun 3, 2021
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
7 changes: 6 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,13 @@ jobs:
run: |
./test/server-start.sh

npm test
npm test 2>&1 | tee /tmp/npm-test.log

- name: Code coverage to be improved
run: |
cat /tmp/npm-test.log | grep '|' | head -n4
cat /tmp/npm-test.log | grep '|' | grep -v '100 | 100 | 100 | 10' | grep '\.js'

- name: Check that bin/phantomas.js works
run: ./bin/phantomas.js http://127.0.0.1:8888/ --pretty | grep "generator" -A4

Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
test/webroot/
coverage/
*.md
*.yml
*.yaml
Expand Down
3 changes: 2 additions & 1 deletion core/modules/navigationTiming/scope.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
(function (phantomas) {
/* istanbul ignore next */
(function navigationTimingScope(phantomas) {
// Prevent events from being sent from an iframe. Only from the main document.
if (window.parent !== window || window.location.href === "about:blank") {
return;
Expand Down
3 changes: 2 additions & 1 deletion core/scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
*
* Code below is executed in page's "scope" (injected by lib/browser.js)
*/
(function (scope) {
/* istanbul ignore next */
(function coreScope(scope) {
"use strict";

// create a scope
Expand Down
2 changes: 2 additions & 0 deletions extensions/pageSource/pageSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ module.exports = (phantomas) => {
return new Promise(async (resolve) => {
// https://github.com/GoogleChrome/puppeteer/blob/v1.11.0/docs/api.md#pageevaluatepagefunction-args
const bodyHandle = await page.$("body");

/* istanbul ignore next */
const html = await page.evaluate((body) => body.innerHTML, bodyHandle);

// phantomas.log(html);
Expand Down
3 changes: 3 additions & 0 deletions extensions/scroll/scroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ module.exports = function (phantomas) {
return new Promise(async (resolve) => {
phantomas.log("Scrolling the page...");

/* istanbul ignore next */
await page.evaluate(() => document.body.scrollIntoView(false));

/* istanbul ignore next */
const scrollOffset = await page.evaluate(() => document.body.scrollTop);

// wait for lazy loading to do its job
Expand Down
10 changes: 7 additions & 3 deletions lib/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ Browser.prototype.init = async (phantomasOptions) => {
}

// customize path to Chromium binary
/* istanbul ignore next */
if (env["PHANTOMAS_CHROMIUM_EXECUTABLE"]) {
options.executablePath = env["PHANTOMAS_CHROMIUM_EXECUTABLE"];
}

// detect that we run inside a container
// @see https://github.com/jessfraz/dockerfiles/issues/65
// @see https://github.com/Zenika/alpine-chrome#-the-best-with-seccomp
/* istanbul ignore next */
if (env["DOCKERIZED"]) {
debug("Docker environment detected");
debug(
Expand All @@ -58,6 +60,7 @@ Browser.prototype.init = async (phantomasOptions) => {
// detect that we run inside an Amazon Lambda machine
// (note: the LAMBDA_TASK_ROOT env variable is automatically set by AWS)
// @see https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html#configuration-envvars-runtime
/* istanbul ignore next */
if (env["LAMBDA_TASK_ROOT"]) {
// Chrome then requires some more flags
options.args.push(
Expand All @@ -74,7 +77,7 @@ Browser.prototype.init = async (phantomasOptions) => {
// https://github.com/puppeteer/puppeteer/blob/main/docs/api.md#puppeteerlaunchoptions
this.browser = await puppeteer.launch(options);
this.page = await this.browser.newPage();
} catch (ex) {
} catch (ex) /* istanbul ignore next */ {
debug("Puppeteer failed to launch: %s", ex);
throw ex;
}
Expand Down Expand Up @@ -172,6 +175,7 @@ Browser.prototype.init = async (phantomasOptions) => {
this.onRequestLoaded = (eventName, data) => {
var meta = responses[data.requestId];

/* istanbul ignore if */
if (typeof meta === "undefined") {
// the browser sometimes looses trace of a request, let's ignore.
networkDebug(
Expand Down Expand Up @@ -312,7 +316,7 @@ Browser.prototype.visit = (url, waitUntil, timeout) => {
debug("Metrics: %s", JSON.stringify(metrics));

this.events.emit("metrics", metrics); // @desc Emitted when Chromuim's page.metrics() has been called
} catch (ex) {
} catch (ex) /* istanbul ignore next */ {
debug("Get metrics failed: " + ex);
return reject(ex);
}
Expand All @@ -330,7 +334,7 @@ Browser.prototype.close = async () => {

// The page is closed, let's close the browser
if (this.browser && this.browser.isConnected()) await this.browser.close();
} catch (ex) {
} catch (ex) /* istanbul ignore next */ {
debug("An exception was raised in Browser.prototype.close(): " + ex);
debug(ex);
}
Expand Down
Loading