Skip to content

Commit ad83c45

Browse files
authored
test: add cases for createIsIgnored function (#21)
1 parent 3e65a4a commit ad83c45

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/watch/inclusive-node-watch-file-system.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import type { WatchFileSystem } from './watch-file-system';
1414

1515
const BUILTIN_IGNORED_DIRS = ['.git'];
1616

17-
function createIsIgnored(
17+
export function createIsIgnored(
1818
ignored: string | RegExp | (string | RegExp)[] | undefined,
1919
excluded: string[]
2020
): (path: string) => boolean {
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { createIsIgnored } from '../../../src/watch/inclusive-node-watch-file-system';
2+
3+
describe('createIsIgnored', () => {
4+
const gitPath = '/path/to/.git/foo';
5+
const nodeModulesPath = '/path/to/node_modules/foo/dist/index.js';
6+
const distModulePath = '/path/to/dist/foo.js';
7+
const srcModulePath = '/path/to/src/foo.ts';
8+
9+
it('should allow to passing RegExp to the first argument', () => {
10+
const isIgnored = createIsIgnored([/[\\/](?:\.git|node_modules)[\\/]/], []);
11+
expect(isIgnored(gitPath)).toBe(true);
12+
expect(isIgnored(nodeModulesPath)).toBe(true);
13+
expect(isIgnored(distModulePath)).toBe(false);
14+
expect(isIgnored(srcModulePath)).toBe(false);
15+
});
16+
17+
it('should allow to passing string path to the first argument', () => {
18+
const isIgnored = createIsIgnored(['/path/to/.git'], []);
19+
expect(isIgnored(gitPath)).toBe(true);
20+
expect(isIgnored(nodeModulesPath)).toBe(false);
21+
expect(isIgnored(distModulePath)).toBe(false);
22+
expect(isIgnored(srcModulePath)).toBe(false);
23+
});
24+
25+
it('should allow to passing string path to the second argument', () => {
26+
const isIgnored = createIsIgnored([], ['/path/to/dist']);
27+
expect(isIgnored(gitPath)).toBe(true);
28+
expect(isIgnored(nodeModulesPath)).toBe(false);
29+
expect(isIgnored(distModulePath)).toBe(true);
30+
expect(isIgnored(srcModulePath)).toBe(false);
31+
});
32+
});

0 commit comments

Comments
 (0)