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
Conversation
@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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this 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 |
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
:)
There was a problem hiding this comment.
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.
Current state of affairs:
gulp (build|dist) --coverage [--fortesting, --extensions, etc.]
creates binaries with instrumented codegulp serve --coverage=live
runs the server with automatic code coverage collectionv0.js
that reports to the coverage endpoint on pageunload
amphtml/build-system/server/app.js
gulp e2e --coverage
runs the e2e test suite with code coverage collectionistanbul
's coverage variable (__coverage__
) from the page context and aggregating it after each test case (seeamphtml/build-system/tasks/e2e/describes-e2e.js
)amphtml/build-system/tasks/e2e/index.js
)amp-ad-exit
tests almost all fail with an error message likejavascript 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 somehowamphtml/build-system/tasks/codecov-upload.js
is already configured for e2e test coveragegulp codecov-upload
is run, it will be reported with thee2e_tests
tage2e.log
contained first the output from a no-coverage one, followed by the output from a coverage rungulp build --fortesting && gulp e2e --nobuild --headless
gulp build --fortesting --coverageh && gulp e2e --nobuild --headless --coverage