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

Don't rebuild packages when test file gets updated #11799

Closed
gziolo opened this issue Nov 13, 2018 · 3 comments · Fixed by #14468
Closed

Don't rebuild packages when test file gets updated #11799

gziolo opened this issue Nov 13, 2018 · 3 comments · Fixed by #14468
Labels
Good First Issue An issue that's suitable for someone looking to contribute for the first time [Type] Build Tooling Issues or PRs related to build tooling [Type] Enhancement A suggestion for improvement.

Comments

@gziolo
Copy link
Member

gziolo commented Nov 13, 2018

As discussed on Slack with @youknowriad, it looks like our watch script for packages is too greedy and rebuilds them when non-production code gets updated: https://wordpress.slack.com/archives/C5UNMSU4R/p1542097900320400
screen shot 2018-11-13 at 09 30 05

We should exclude test files from the list of files which trigger rebuild of the packages. It looks like we already exclude some types of files, so it might be possible to extend the following function:

// Exclude deceitful source-like files, such as editor swap files.
const isSourceFile = ( filename ) => {
return /.\.(js|scss)$/.test( filename );
};

By the way, it looks like the message printed on the console is also wrong. I didn't rename any file but I added a few modifications.

@gziolo gziolo added [Type] Enhancement A suggestion for improvement. Good First Issue An issue that's suitable for someone looking to contribute for the first time [Type] Build Tooling Issues or PRs related to build tooling labels Nov 13, 2018
@Jackie6
Copy link
Contributor

Jackie6 commented Mar 14, 2019

@gziolo Hi greg
According to the documentation here, all test files are in the "test" folder. So can we just skip those files in the "test" folder using the following code?

// Exclude test files and deceitful source-like files, such as editor swap files.

const isSourceFile = ( filename ) => {
	return ! /\/test\//.test( filename ) && /.\.(js|scss)$/.test( filename );
};

You mention that the message printed on the console is also wrong.But I do not know how to reproduce this error. When I run npm run dev, the webpack will not watch for changes and rebuild packages even I have modified the code. BTW, I am using varying vagrant vagrants and Mac OS.

@gziolo
Copy link
Member Author

gziolo commented Mar 15, 2019

@Jackie6, it's almost true. There are some exceptions with how tests are discovered. There are 3 patterns which can be used:
https://github.com/WordPress/gutenberg/blob/master/packages/jest-preset-default/jest-preset.json#L18-L20
However, the one you shared covers 95% of cases so it would be a good start. We might want to include /__tests__/ as well. Can you open PR with your proposal?

When I run npm run dev, the webpack will not watch for changes and rebuild packages even I have modified the code. BTW, I am using varying vagrant vagrants and Mac OS.

That's surprising, this command starts watch mode so it should trigger changes any time any code is updated inside packages folder according to the rule you are about to update.

@Jackie6
Copy link
Contributor

Jackie6 commented Mar 15, 2019

@gziolo Hi Greg. Thank you for pointing out the test match pattern.
However, the testMatch is not a standard regex, it is based on jest micromatch.

"testMatch": [
"**/__tests__/**/*.js",
"**/?(*.)(spec|test).js",
"**/test/*.js"
],

So I translate the patterns to regex. I have created a pull request to fix this issue. The modified code is as follows:

// Exclude test files including .js files inside of __tests__ or test folders
// and files with a suffix of .test or .spec (e.g. blocks.test.js),
// and deceitful source-like files, such as editor swap files.
const isSourceFile = ( filename ) => {
	return ! [/\/(__tests__|test)\/.+.js$/, /.\.(spec|test)\.js$/].some( regex => regex.test( filename ) ) && /.\.(js|scss)$/.test( filename );
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Good First Issue An issue that's suitable for someone looking to contribute for the first time [Type] Build Tooling Issues or PRs related to build tooling [Type] Enhancement A suggestion for improvement.
Projects
None yet
2 participants