Skip to content
This repository was archived by the owner on Jan 16, 2025. It is now read-only.

Commit f7adf6f

Browse files
committed
Revert "fix: --ignore and --only arguments (#90)"
This reverts commit 4713508.
1 parent dc7044a commit f7adf6f

File tree

6 files changed

+182
-256
lines changed

6 files changed

+182
-256
lines changed

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
"dependencies": {
4848
"commander": "^7.1.0",
4949
"fast-glob": "^3.2.5",
50-
"micromatch": "^4.0.4",
5150
"slash": "3.0.0",
5251
"source-map": "^0.7.3"
5352
},
@@ -56,7 +55,6 @@
5655
"@swc/core": "^1.2.66",
5756
"@swc/jest": "^0.1.2",
5857
"@types/jest": "^26.0.23",
59-
"@types/micromatch": "^4.0.2",
6058
"@types/node": "^12.19.16",
6159
"chokidar": "^3.5.1",
6260
"deepmerge": "^4.2.2",

src/swc/__tests__/sources.test.ts

Lines changed: 37 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,126 +1,86 @@
11
import { globSources, slitCompilableAndCopyable } from "../sources";
2-
import fs from 'fs'
2+
import fs from "fs";
33
import glob from "fast-glob";
44

5-
jest.mock('fs');
6-
jest.mock('fast-glob');
5+
jest.mock("fs");
6+
jest.mock("fast-glob");
77

8-
describe('globSources', () => {
8+
describe("globSources", () => {
99
beforeEach(() => {
1010
(fs as any).resetMockStats();
1111
});
1212

1313
it("exclude dotfiles sources when includeDotfiles=false", async () => {
14-
const files = await globSources([".dotfile"], { includeDotfiles: false });
14+
const files = await globSources([".dotfile"], false);
1515

1616
expect([...files]).toEqual([]);
1717
});
1818

1919
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);
2222

2323
expect([...files]).toEqual([".dotfile"]);
2424
});
2525

26-
2726
it("include multiple file sources", async () => {
2827
(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);
3130

32-
expect([...files]).toEqual(['.dotfile', "file"]);
31+
expect([...files]).toEqual([".dotfile", "file"]);
3332
});
3433

3534
it("exclude files that errors on stats", async () => {
3635
(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);
3938

40-
expect([...files]).toEqual(['.dotfile']);
39+
expect([...files]).toEqual([".dotfile"]);
4140
});
4241

4342
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 } });
4645

4746
(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);
4948

50-
expect([...files]).toEqual([
51-
"file",
52-
"fileDir1",
53-
"fileDir2"
54-
]);
49+
expect([...files]).toEqual(["file", "fileDir1", "fileDir2"]);
5550
});
5651

5752
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 } });
6055

6156
(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);
9858

99-
expect([...files]).toEqual([
100-
"src/index.spec.js",
101-
]);
59+
expect([...files]).toEqual(["file"]);
10260
});
10361
});
10462

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+
);
11372

11473
expect(compilable).toEqual(["test.ts"]);
11574
expect(copyable).toEqual(["test.txt"]);
11675
});
11776

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+
);
12484

12585
expect(compilable).toEqual(["test.ts"]);
12686
expect(copyable).toEqual([]);

0 commit comments

Comments
 (0)