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

WIP: Enabling test coverage on e2e tests #31787

Closed
wants to merge 8 commits into from

Conversation

rcebulko
Copy link
Contributor

@rcebulko rcebulko commented Jan 4, 2021

Current state of affairs:

  • gulp (build|dist) --coverage [--fortesting, --extensions, etc.] creates binaries with instrumented code
  • gulp serve --coverage=live runs the server with automatic code coverage collection
    • This works by appending an event handler to v0.js that reports to the coverage endpoint on page unload
    • This code lives in amphtml/build-system/server/app.js
  • gulp e2e --coverage runs the e2e test suite with code coverage collection
    • This works by extracting istanbul's coverage variable (__coverage__) from the page context and aggregating it after each test case (see amphtml/build-system/tasks/e2e/describes-e2e.js)
    • After all tests are complete, the aggregated coverage object is reported to the endpoint (see amphtml/build-system/tasks/e2e/index.js)
    • The coverage report is opened automatically upon test suite completion
  • Currently, a handful of tests fail for me
    • Some are timeout or other similar errors that don't seem related, but I'm not yet certain
    • amp-ad-exit tests almost all fail with an error message like javascript error: cov_1xqb08d7d9 is not defined
    • istanbul instrumentation is configured to use the name __coverage__ for the coverage variable, suggesting these may be references to instrumentation Karma is trying to automatically provide somehow
  • amphtml/build-system/tasks/codecov-upload.js is already configured for e2e test coverage
    • If the e2e coverage data is created when gulp codecov-upload is run, it will be reported with the e2e_tests tag
    • This is the same way unit and integration test coverage is reported
  • The file e2e.logcontained first the output from a no-coverage one, followed by the output from a coverage run
    • First run command: gulp build --fortesting && gulp e2e --nobuild --headless
    • Second run command: gulp build --fortesting --coverageh && gulp e2e --nobuild --headless --coverage
    • Diff: b11e565

@rcebulko
Copy link
Contributor Author

rcebulko commented Jan 4, 2021

@rsimha PTAL :)

@@ -51,7 +51,7 @@ jobs:
- stage: build
name: 'Unminified Build'
script:
- unbuffer node build-system/pr-check/unminified-build.js
- travis wait 30 unbuffer node build-system/pr-check/unminified-build.js
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this, the longer --coverage build will timeout on Travis

Copy link
Contributor

@rsimha rsimha Jan 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As written, this will increase the time taken by all Travis builds because the "test" stage will now have to wait for (up to) a 30 minute "build" stage.

The good news is that we should be able to solve this problem with the move to CircleCI, which I believe allows for more sophisticated matrices (e.g. create a separate independent "coverage" stage, which starts at the beginning and runs in parallel with the "build" and "test" stages, which run serially.)

I expect to make progress on this in the next week or so, will loop you in when the coast is clear to try this out.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for reminding me about this, forgot to note it! My thinking was this would only be viable for something like the Nightly builds, and probably shouldn't be a part of CI during the development day. Even if Circle CI supports splitting the work off, e2e test coverage shouldn't fluctuate massively from one commit to another, and daily data would be sufficient as a metric.

@@ -67,7 +67,7 @@ async function main() {
) {
downloadDistOutput(FILENAME);
timedExecOrDie('gulp update-packages');
timedExecOrDie('gulp e2e --nobuild --headless --compiled');
timedExecOrDie('gulp e2e --nobuild --headless --compiled --coverage');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should eventually be gated with argv.coverage; likewise with the gulp dist/gulp build commands below, which I had just enabled --coverage on while experimenting/trying to get it to run on Travis.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. Adding an additional job to the CI matrix isn't that expensive, so we should probably just do all coverage measurements in a parallel job.

@@ -64,7 +64,9 @@ import {stubElementsForDoc} from './service/custom-element-registry';
* @type {boolean|undefined}
*/
const shouldMainBootstrapRun = !self.IS_AMP_ALT;

// NO SUBMIT PLZ
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change was to trigger build targets, "DO NOT SUBMIT" will make Travis fail before running the tests themselves

Copy link
Contributor

@rsimha rsimha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the work so far, @rcebulko. I've added a couple of comments below.

@@ -51,7 +51,7 @@ jobs:
- stage: build
name: 'Unminified Build'
script:
- unbuffer node build-system/pr-check/unminified-build.js
- travis wait 30 unbuffer node build-system/pr-check/unminified-build.js
Copy link
Contributor

@rsimha rsimha Jan 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As written, this will increase the time taken by all Travis builds because the "test" stage will now have to wait for (up to) a 30 minute "build" stage.

The good news is that we should be able to solve this problem with the move to CircleCI, which I believe allows for more sophisticated matrices (e.g. create a separate independent "coverage" stage, which starts at the beginning and runs in parallel with the "build" and "test" stages, which run serially.)

I expect to make progress on this in the next week or so, will loop you in when the coast is clear to try this out.

@@ -67,7 +67,7 @@ async function main() {
) {
downloadDistOutput(FILENAME);
timedExecOrDie('gulp update-packages');
timedExecOrDie('gulp e2e --nobuild --headless --compiled');
timedExecOrDie('gulp e2e --nobuild --headless --compiled --coverage');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. Adding an additional job to the CI matrix isn't that expensive, so we should probably just do all coverage measurements in a parallel job.

AMPHTML ads FIE environment

product1 ad opened:
JavascriptError: javascript error: cov_1xqb08d7d9 is not defined
Copy link
Contributor

@rsimha rsimha Jan 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Searching for this error led me to istanbuljs/istanbuljs#499, which mentions among other things the fact that a babel transform might be hoisting the coverage variable.

I wonder if it's possible to / worth playing with the order of babel plugins in test-config.js, pre-closure-config.js, and unminified-config.js by moving the instrumentation transform to the end.

Side note: I misspelled the plugin name as instanbulPlugin in test-config.js :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds like a very plausible culprit. It's certainly possible to play with the order of plugins, and I did a lot of experimentation with varied results (though I do not recall every variation I attempted). TL;DR - Sometimes re-ordering results in coverage being generated for the binaries, rather than the source files. In theory it should be possible to do instrumentation at any step and transform the source maps along the way, but I never managed to get that working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants