Skip to content

Commit 8e15dc2

Browse files
committed
Watch test files (so they retrigger webpack)
This will not process them for now...
1 parent e7d71bd commit 8e15dc2

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
var glob = require('glob');
2+
var path = require('path');
3+
4+
function computeGlob(pattern, options) {
5+
return new Promise((resolve, reject) => {
6+
glob(pattern, options || {}, (err, matches) => {
7+
if (err) {
8+
return reject(err);
9+
}
10+
resolve(matches);
11+
});
12+
});
13+
}
14+
15+
function WatchTestFilesPlugin(testGlobs) {
16+
this.testGlobs = testGlobs || [];
17+
}
18+
19+
WatchTestFilesPlugin.prototype.apply = function(compiler) {
20+
compiler.plugin('emit', (compilation, callback) => {
21+
console.log()
22+
Promise.all(this.testGlobs.map(globPattern =>
23+
computeGlob(globPattern, {
24+
cwd: compiler.options.context,
25+
ignore: 'node_modules/**',
26+
})
27+
))
28+
.then(globLists => [].concat.apply([], globLists))
29+
.then(testFiles => {
30+
testFiles.forEach(testFile => {
31+
compilation.fileDependencies.push(path.join(compiler.options.context, testFile));
32+
});
33+
})
34+
.then(callback)
35+
.catch(console.error);
36+
});
37+
};
38+
39+
module.exports = WatchTestFilesPlugin;

packages/react-dev-utils/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@
2020
"openBrowser.js",
2121
"prompt.js",
2222
"WatchMissingNodeModulesPlugin.js",
23+
"WatchTestFilesPlugin.js",
2324
"webpackHotDevClient.js"
2425
],
2526
"dependencies": {
2627
"ansi-html": "0.0.5",
2728
"chalk": "1.1.3",
2829
"escape-string-regexp": "1.0.5",
30+
"glob": "^7.1.1",
2931
"html-entities": "1.2.0",
3032
"opn": "4.0.2",
3133
"sockjs-client": "1.0.3",

packages/react-scripts/config/webpack.config.dev.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ var HtmlWebpackPlugin = require('html-webpack-plugin');
1515
var CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
1616
var InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
1717
var WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin');
18+
var WatchTestFilesPlugin = require('react-dev-utils/WatchTestFilesPlugin');
1819
var getClientEnvironment = require('./env');
1920
var paths = require('./paths');
2021

@@ -226,7 +227,14 @@ module.exports = {
226227
// to restart the development server for Webpack to discover it. This plugin
227228
// makes the discovery automatic so you don't have to restart.
228229
// See https://github.com/facebookincubator/create-react-app/issues/186
229-
new WatchMissingNodeModulesPlugin(paths.appNodeModules)
230+
new WatchMissingNodeModulesPlugin(paths.appNodeModules),
231+
// Tests won't have any linting unless they go through webpack.
232+
// This plugin makes webpack aware of them without emitting them.
233+
// See https://github.com/facebookincubator/create-react-app/issues/1169
234+
new WatchTestFilesPlugin([
235+
'**/__tests__/**',
236+
'**/*.test.js',
237+
]),
230238
],
231239
// Some libraries import Node modules but don't use them in the browser.
232240
// Tell Webpack to provide empty mocks for them so importing them works.

0 commit comments

Comments
 (0)