Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update ignoredFiles test to use anymatch as it does in webpack as well
  • Loading branch information
Jørgen Sverre Lien Sellæg committed Jan 30, 2022
commit 027b95b713f3244842076a2efb46c25d4d50a2a6
24 changes: 17 additions & 7 deletions packages/react-dev-utils/__tests__/ignoredFiles.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,33 @@

const ignoredFiles = require('../ignoredFiles');

const anymatch = require('anymatch');

describe('ignore watch files regex', () => {
it('normal file', () => {
const appSrc = '/root/src/';
const isIgnored = ignoredFiles(appSrc).test('/foo');
const isIgnoredInSrc = ignoredFiles(appSrc).test('/root/src/foo');
const isIgnored = anymatch(ignoredFiles(appSrc), '/foo');
const isIgnoredInSrc = anymatch(ignoredFiles(appSrc), '/root/src/foo');

expect(isIgnored).toBe(false);
expect(isIgnoredInSrc).toBe(false);
});

it('node modules', () => {
const appSrc = '/root/src/';
const isIgnored = ignoredFiles(appSrc).test('/root/node_modules/foo');
const isIgnored = anymatch(ignoredFiles(appSrc), '/root/node_modules/foo');

expect(isIgnored).toBe(true);
});

it('node modules inside source directory', () => {
const appSrc = '/root/src/';
const isIgnored = ignoredFiles(appSrc).test('/root/src/node_modules/foo');
const isIgnoredMoreThanOneLevel = ignoredFiles(appSrc).test(
const isIgnored = anymatch(
ignoredFiles(appSrc),
'/root/src/node_modules/foo'
);
const isIgnoredMoreThanOneLevel = anymatch(
ignoredFiles(appSrc),
'/root/src/bar/node_modules/foo'
);

Expand All @@ -39,7 +45,8 @@ describe('ignore watch files regex', () => {

it('path contains source directory', () => {
const appSrc = '/root/src/';
const isIgnored = ignoredFiles(appSrc).test(
const isIgnored = anymatch(
ignoredFiles(appSrc),
'/bar/root/src/node_modules/foo'
);

Expand All @@ -48,7 +55,10 @@ describe('ignore watch files regex', () => {

it('path starts with source directory', () => {
const appSrc = '/root/src/';
const isIgnored = ignoredFiles(appSrc).test('/root/src2/node_modules/foo');
const isIgnored = anymatch(
ignoredFiles(appSrc),
'/root/src2/node_modules/foo'
);

expect(isIgnored).toBe(true);
});
Expand Down