|
1 | 1 | import { globSources, slitCompilableAndCopyable } from "../sources"; |
2 | | -import fs from 'fs' |
| 2 | +import fs from "fs"; |
3 | 3 | import glob from "fast-glob"; |
4 | 4 |
|
5 | | -jest.mock('fs'); |
6 | | -jest.mock('fast-glob'); |
| 5 | +jest.mock("fs"); |
| 6 | +jest.mock("fast-glob"); |
7 | 7 |
|
8 | | -describe('globSources', () => { |
| 8 | +describe("globSources", () => { |
9 | 9 | beforeEach(() => { |
10 | 10 | (fs as any).resetMockStats(); |
11 | 11 | }); |
12 | 12 |
|
13 | 13 | it("exclude dotfiles sources when includeDotfiles=false", async () => { |
14 | | - const files = await globSources([".dotfile"], { includeDotfiles: false }); |
| 14 | + const files = await globSources([".dotfile"], false); |
15 | 15 |
|
16 | 16 | expect([...files]).toEqual([]); |
17 | 17 | }); |
18 | 18 |
|
19 | 19 | it("include dotfiles sources when includeDotfiles=true", async () => { |
20 | | - (fs as any).setMockStats({ ".dotfile": { isDirectory: () => false } }) |
21 | | - const files = await globSources([".dotfile"], { includeDotfiles: true }); |
| 20 | + (fs as any).setMockStats({ ".dotfile": { isDirectory: () => false } }); |
| 21 | + const files = await globSources([".dotfile"], true); |
22 | 22 |
|
23 | 23 | expect([...files]).toEqual([".dotfile"]); |
24 | 24 | }); |
25 | 25 |
|
26 | | - |
27 | 26 | it("include multiple file sources", async () => { |
28 | 27 | (fs as any).setMockStats({ ".dotfile": { isDirectory: () => false } }); |
29 | | - (fs as any).setMockStats({ "file": { isDirectory: () => false } }); |
30 | | - const files = await globSources([".dotfile", "file"], { includeDotfiles: true }); |
| 28 | + (fs as any).setMockStats({ file: { isDirectory: () => false } }); |
| 29 | + const files = await globSources([".dotfile", "file"], true); |
31 | 30 |
|
32 | | - expect([...files]).toEqual(['.dotfile', "file"]); |
| 31 | + expect([...files]).toEqual([".dotfile", "file"]); |
33 | 32 | }); |
34 | 33 |
|
35 | 34 | it("exclude files that errors on stats", async () => { |
36 | 35 | (fs as any).setMockStats({ ".dotfile": { isDirectory: () => false } }); |
37 | | - (fs as any).setMockStats({ "file": new Error('Failed stat') }); |
38 | | - const files = await globSources([".dotfile", "file"], { includeDotfiles: true }); |
| 36 | + (fs as any).setMockStats({ file: new Error("Failed stat") }); |
| 37 | + const files = await globSources([".dotfile", "file"], true); |
39 | 38 |
|
40 | | - expect([...files]).toEqual(['.dotfile']); |
| 39 | + expect([...files]).toEqual([".dotfile"]); |
41 | 40 | }); |
42 | 41 |
|
43 | 42 | it("includes all files from directory", async () => { |
44 | | - (fs as any).setMockStats({ "directory": { isDirectory: () => true } }); |
45 | | - (fs as any).setMockStats({ "file": { isDirectory: () => false } }); |
| 43 | + (fs as any).setMockStats({ directory: { isDirectory: () => true } }); |
| 44 | + (fs as any).setMockStats({ file: { isDirectory: () => false } }); |
46 | 45 |
|
47 | 46 | (glob as unknown as jest.Mock).mockResolvedValue(["fileDir1", "fileDir2"]); |
48 | | - const files = await globSources(["file", "directory"], { includeDotfiles: true }); |
| 47 | + const files = await globSources(["file", "directory"], true); |
49 | 48 |
|
50 | | - expect([...files]).toEqual([ |
51 | | - "file", |
52 | | - "fileDir1", |
53 | | - "fileDir2" |
54 | | - ]); |
| 49 | + expect([...files]).toEqual(["file", "fileDir1", "fileDir2"]); |
55 | 50 | }); |
56 | 51 |
|
57 | 52 | it("exclude files from directory that fail to glob", async () => { |
58 | | - (fs as any).setMockStats({ "directory": { isDirectory: () => true } }); |
59 | | - (fs as any).setMockStats({ "file": { isDirectory: () => false } }); |
| 53 | + (fs as any).setMockStats({ directory: { isDirectory: () => true } }); |
| 54 | + (fs as any).setMockStats({ file: { isDirectory: () => false } }); |
60 | 55 |
|
61 | 56 | (glob as unknown as jest.Mock).mockRejectedValue(new Error("Failed")); |
62 | | - const files = await globSources(["file", "directory"], { includeDotfiles: true }); |
63 | | - |
64 | | - expect([...files]).toEqual([ |
65 | | - "file", |
66 | | - ]); |
67 | | - }); |
68 | | - |
69 | | - it("ignore file by glob", async () => { |
70 | | - (fs as any).setMockStats({ "index.js": { isDirectory: () => false } }); |
71 | | - (fs as any).setMockStats({ "index.spec.js": { isDirectory: () => false } }); |
72 | | - |
73 | | - const files = await globSources(["index.js", "index.spec.js"], { ignorePatterns: ["**/*.spec.js"] }); |
74 | | - |
75 | | - expect([...files]).toEqual([ |
76 | | - "index.js", |
77 | | - ]); |
78 | | - }); |
79 | | - |
80 | | - it("inclide file by glob", async () => { |
81 | | - (fs as any).setMockStats({ "index.js": { isDirectory: () => false } }); |
82 | | - (fs as any).setMockStats({ "index.spec.js": { isDirectory: () => false } }); |
83 | | - |
84 | | - const files = await globSources(["index.js", "index.spec.js"], { onlyPatterns: ["**/*.spec.js"] }); |
85 | | - |
86 | | - expect([...files]).toEqual([ |
87 | | - "index.spec.js", |
88 | | - ]); |
89 | | - }); |
90 | | - |
91 | | - it("inclide files from dir by glob", async () => { |
92 | | - (fs as any).setMockStats({ "src": { isDirectory: () => true } }); |
93 | | - (fs as any).setMockStats({ "src/index.js": { isDirectory: () => false } }); |
94 | | - (fs as any).setMockStats({ "src/index.spec.js": { isDirectory: () => false } }); |
95 | | - |
96 | | - (glob as unknown as jest.Mock).mockResolvedValue(["src/index.js", "src/index.spec.js"]); |
97 | | - const files = await globSources(["src"], { onlyPatterns: ["**/*.spec.js"] }); |
| 57 | + const files = await globSources(["file", "directory"], true); |
98 | 58 |
|
99 | | - expect([...files]).toEqual([ |
100 | | - "src/index.spec.js", |
101 | | - ]); |
| 59 | + expect([...files]).toEqual(["file"]); |
102 | 60 | }); |
103 | 61 | }); |
104 | 62 |
|
105 | | -describe('slitCompilableAndCopyable', () => { |
106 | | - const extensions = [".ts"] |
107 | | - it('separate compilable and copyable when copyFiles=true', () => { |
108 | | - const files = [ |
109 | | - "test.ts", |
110 | | - "test.txt" |
111 | | - ]; |
112 | | - const [compilable, copyable] = slitCompilableAndCopyable(files, extensions, true); |
| 63 | +describe("slitCompilableAndCopyable", () => { |
| 64 | + const extensions = [".ts"]; |
| 65 | + it("separate compilable and copyable when copyFiles=true", () => { |
| 66 | + const files = ["test.ts", "test.txt"]; |
| 67 | + const [compilable, copyable] = slitCompilableAndCopyable( |
| 68 | + files, |
| 69 | + extensions, |
| 70 | + true |
| 71 | + ); |
113 | 72 |
|
114 | 73 | expect(compilable).toEqual(["test.ts"]); |
115 | 74 | expect(copyable).toEqual(["test.txt"]); |
116 | 75 | }); |
117 | 76 |
|
118 | | - it('separate compilable and copyable when copyFiles=false', () => { |
119 | | - const files = [ |
120 | | - "test.ts", |
121 | | - "test.txt" |
122 | | - ]; |
123 | | - const [compilable, copyable] = slitCompilableAndCopyable(files, extensions, false); |
| 77 | + it("separate compilable and copyable when copyFiles=false", () => { |
| 78 | + const files = ["test.ts", "test.txt"]; |
| 79 | + const [compilable, copyable] = slitCompilableAndCopyable( |
| 80 | + files, |
| 81 | + extensions, |
| 82 | + false |
| 83 | + ); |
124 | 84 |
|
125 | 85 | expect(compilable).toEqual(["test.ts"]); |
126 | 86 | expect(copyable).toEqual([]); |
|
0 commit comments