-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Test: Collapse passed tests in Travis. #16755
Conversation
1191e78
to
7aaf678
Compare
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.
Nice! The only question I have with this is whether it's possible to (or should) be included in the @wordpress/jest-preset-defaults
package instead? That way the alternative reporter is available in a wider scope?
I added it to all the test suites in this repo. I don't know if we want it to be part of the package that other repos might use or if it's something that should be specific to this one. Personally, I do think that having it in the package is a good idea. We can also always easily move it later. cc @youknowriad |
Having it in the preset works for me 👍 |
7aaf678
to
be26416
Compare
Done 🎉 |
@@ -23,5 +23,6 @@ | |||
"transform": { | |||
"^.+\\.[jt]sx?$": "<rootDir>/node_modules/babel-jest" | |||
}, | |||
"verbose": true | |||
"verbose": true, | |||
"reporters": [ "../../../@wordpress/jest-preset-default/scripts/travis-fold-passes-reporter.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.
hmm... is this path right?
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.
Yes, <rootDir>
does not work there in .json
files for some reason.
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.
Did you test it outside of Gutenberg repository? In other places we use <rootDir>
, e.g.:
<rootDir>/node_modules/@wordpress/jest-preset-default/scripts/setup-globals.js
As far as I remember this is the only way to make it work for Jest presets. At least this was the case in the past.
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.
huh, I would have thought the path would be relative to the jest-preset.json
file. I'm just wondering how well/if this will work things consuming this package (other than gutenberg). So with this being a relative path, would ./scripts/travis-fold-passes-reporter.js
not work?
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.
It's relative to the core jest package.
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.
It looks like they migrated to jest-preset.js
in this PR: thymikee/jest-preset-angular#204. I assume Jest improved the handling for presets.
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.
Still doesn't replace <rootDir>
.
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.
@gziolo might be suggesting to resolve it using something like require.resolve
in JavaScript?
require.resolve( '@wordpress/jest-preset-default/scripts/travis-fold-passes-reporter' )
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.
We should use <rootDir>/node_modules/@wordpress/jest-preset-default/scripts/...
like with the other paths in this file, but first we need to update the package so that the new reporter file is present in the directory in node_modules
.
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.
I don't remember :) The way it's implemented at the moment, it won't work when installed from npm for all projects using wp-scripts test-unit-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.
In this branch, when I run tests locally, I see the "Pass" label, but no details of the specific tests.
This is without any TRAVIS
environment variable.
npm run test-unit packages/blocks/src/api/test/validation.js
> gutenberg@6.9.0 test-unit /Users/andrew/Documents/Code/gutenberg
> wp-scripts test-unit-js --config test/unit/jest.config.js "packages/blocks/src/api/test/validation.js"
PASS packages/blocks/src/api/test/validation.js
packages/jest-preset-default/scripts/travis-fold-passes-reporter.js
Outdated
Show resolved
Hide resolved
packages/jest-preset-default/scripts/travis-fold-passes-reporter.js
Outdated
Show resolved
Hide resolved
@@ -23,5 +23,6 @@ | |||
"transform": { | |||
"^.+\\.[jt]sx?$": "<rootDir>/node_modules/babel-jest" | |||
}, | |||
"verbose": true | |||
"verbose": true, | |||
"reporters": [ "../../../@wordpress/jest-preset-default/scripts/travis-fold-passes-reporter.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.
@gziolo might be suggesting to resolve it using something like require.resolve
in JavaScript?
require.resolve( '@wordpress/jest-preset-default/scripts/travis-fold-passes-reporter' )
be26416
to
8d8024c
Compare
Good catch. We use |
Can this be simplified to conditionally override the reported in this config file: This way this change will be isolated to Gutenberg. This will prevent enforcing the verbose reporter when running locally, make the issue with providing the path to the custom reporter no longer present. |
We already do this with
This is only temporary, until the file is in |
@@ -27,5 +27,6 @@ | |||
"transform": { | |||
"^.+\\.[jt]sx?$": "<rootDir>/node_modules/babel-jest" | |||
}, | |||
"verbose": true | |||
"verbose": true, |
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.
With the latest changes, I wonder if this line is even necessary. And then, it gets me considering, if someone was to use this preset as a base, and then override "verbose": false
, would it actually disable the VerboseRunner
from being used?
It seems like something where the additional reporter shouldn't be making any assumptions outside its own custom behavior, which we could do if we included "default"
in the reporters array:
https://jestjs.io/docs/en/configuration#reporters-arraymodulename--modulename-options
I suppose the problem then is: What would the export of travis-folder-passes.reporter.js
be in the else
condition of 'TRAVIS' in process.env
?
I could see a few options:
- Move the condition into each of the
onTestResult
andonRunComplete
to treat them as a noop. - Maybe it's enough to revert back to extending
DefaultReporter
if we include'default'
in thereporters
configuration? - Or, we could convert this file to a JavaScript file, and conditionally include the custom reporter path based on the
process.env
condition.
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.
Move the condition into each of the onTestResult and onRunComplete to treat them as a noop.
We still need to extend either the verbose or default reporter to get some output without running 2 reporters in Travis.
Maybe it's enough to revert back to extending DefaultReporter if we include 'default' in the reporters configuration?
Likewise, that would run the 2 reporters.
Or, we could convert this file to a JavaScript file, and conditionally include the custom reporter path based on the process.env condition.
That would work.
A potentially easier solution that respects the actual configuration would be to read the current Jest config, which reporters are constructed with:
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.
Seems to work: f7c72e7.
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.
I think it can work. It still doesn't quite sit well with me, since it makes assumptions about what the default behavior would be from our custom code, rather than just letting Jest deal with the defaults. Converting jest-preset.json
to a JavaScript file and manipulating the reporters
array feels like a more durable long-term solution. I'm fine to explore that separately.
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.
Agreed.
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.
In the failing end-to-end test (which itself doesn't appear to be related), I see that the passes aren't collapsed. Do we use a separate configuration for this? See: https://travis-ci.com/WordPress/gutenberg/jobs/262393864 |
It looks like E2E tests are using the |
Can we update that in a follow-up PR? |
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.
Sure
Closes #16744
Description
This PR replaces the default jest reporter with a subclass that folds passed tests when running in Travis CI.
How has this been tested?
Tests were run locally and the default reporter was used. Now we need to verify the new reporter works as expected in Travis.
Types of Changes
Build Tooling: Collapse passed tests in Travis.
Checklist: