-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusage.test.js
97 lines (86 loc) · 1.92 KB
/
usage.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import path from "node:path";
import { describe, it } from "node:test";
import assert from "node:assert";
import { transformSync } from "@swc/core";
const pluginPath = path.resolve("target/wasm32-wasip1/debug/swc_plugin_ignore_import.wasm");
describe('SWC Plugin Ignore Import', () => {
it('should remove specified imports', () => {
const input = `
import "@exact/package-name";
import "keep-this";
`;
const output = transformSync(input, {
jsc: {
experimental: {
plugins: [
[
pluginPath,
{
pattern: "@exact/package-name",
}
]
],
},
},
});
const expected = `
import "keep-this";
`.trim();
assert.strictEqual(output.code.trim(), expected);
});
it('should remove .scss imports', () => {
const input = `
import "styles.scss";
import "keep-this";
`;
const output = transformSync(input, {
jsc: {
experimental: {
plugins: [
[
pluginPath,
{
pattern: ".scss$",
}
]
],
},
},
});
const expected = `
import "keep-this";
`.trim();
assert.strictEqual(output.code.trim(), expected);
});
it('should remove same word starting imports', () => {
const input = `
import "jquery"; // Still needed
import "react";
import "react-dom";
import "other-router";
import "react-router";
import "react-router-dom";
import "keep-this";
`;
const output = transformSync(input, {
jsc: {
experimental: {
plugins: [
[
pluginPath,
{
pattern: "^react",
}
]
],
},
},
});
const expected = `
import "jquery"; // Still needed
import "other-router";
import "keep-this";
`.trim();
assert.strictEqual(output.code.trim(), expected);
});
});