Skip to content

Commit 2806cd7

Browse files
committed
add test
1 parent 440d4a6 commit 2806cd7

File tree

4 files changed

+62
-1
lines changed

4 files changed

+62
-1
lines changed

packages/react-dev-utils/package.json

+6
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,11 @@
5353
"sockjs-client": "1.1.4",
5454
"strip-ansi": "3.0.1",
5555
"text-table": "0.2.0"
56+
},
57+
"devDependencies": {
58+
"jest": "20.0.4"
59+
},
60+
"scripts": {
61+
"test": "jest"
5662
}
5763
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
'use strict';
9+
10+
const ignoredFiles = require('../ignoredFiles');
11+
12+
describe('ignore watch files regex', () => {
13+
it('normal file', () => {
14+
const appSrc = '/root/src/';
15+
const isIgnored = ignoredFiles(appSrc).test('/foo');
16+
const isIgnoredInSrc = ignoredFiles(appSrc).test('/root/src/foo');
17+
18+
expect(isIgnored).toBe(false);
19+
expect(isIgnoredInSrc).toBe(false);
20+
});
21+
22+
it('node modules', () => {
23+
const appSrc = '/root/src/';
24+
const isIgnored = ignoredFiles(appSrc).test('/root/node_modules/foo');
25+
26+
expect(isIgnored).toBe(true);
27+
});
28+
29+
it('node modules inside source directory', () => {
30+
const appSrc = '/root/src/';
31+
const isIgnored = ignoredFiles(appSrc).test('/root/src/node_modules/foo');
32+
const isIgnoredMoreThanOneLevel = ignoredFiles(appSrc).test(
33+
'/root/src/bar/node_modules/foo'
34+
);
35+
36+
expect(isIgnored).toBe(false);
37+
expect(isIgnoredMoreThanOneLevel).toBe(false);
38+
});
39+
40+
it('path contains source directory', () => {
41+
const appSrc = '/root/src/';
42+
const isIgnored = ignoredFiles(appSrc).test(
43+
'/bar/root/src/node_modules/foo'
44+
);
45+
46+
expect(isIgnored).toBe(true);
47+
});
48+
49+
it('path starts with source directory', () => {
50+
const appSrc = '/root/src/';
51+
const isIgnored = ignoredFiles(appSrc).test('/root/src2/node_modules/foo');
52+
53+
expect(isIgnored).toBe(true);
54+
});
55+
});

packages/react-scripts/config/webpackDevServer.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
const errorOverlayMiddleware = require('react-dev-utils/errorOverlayMiddleware');
1212
const noopServiceWorkerMiddleware = require('react-dev-utils/noopServiceWorkerMiddleware');
13-
const ignoredFiles = require('react-dev-utils/ignoredFiles');
13+
const ignoredFiles = require('react-dev-utils/src/ignoredFiles');
1414
const config = require('./webpack.config.dev');
1515
const paths = require('./paths');
1616

0 commit comments

Comments
 (0)