@swc/plugin-jest 6.3.1 → 7.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
Binary file
|
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { transform, type Options } from "@swc/core";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import url from "node:url";
|
|
5
|
+
|
|
6
|
+
const options: Options = {
|
|
7
|
+
jsc: {
|
|
8
|
+
parser: {
|
|
9
|
+
syntax: "ecmascript",
|
|
10
|
+
jsx: true,
|
|
11
|
+
},
|
|
12
|
+
experimental: {
|
|
13
|
+
plugins: [
|
|
14
|
+
[
|
|
15
|
+
path.join(
|
|
16
|
+
path.dirname(url.fileURLToPath(import.meta.url)),
|
|
17
|
+
"..",
|
|
18
|
+
"swc_plugin_jest.wasm",
|
|
19
|
+
),
|
|
20
|
+
{},
|
|
21
|
+
],
|
|
22
|
+
],
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
describe("jest swc plugin", () => {
|
|
28
|
+
it("should hoist jest.mock calls", async () => {
|
|
29
|
+
const input = `
|
|
30
|
+
console.log('before mock');
|
|
31
|
+
jest.mock('./some-module');
|
|
32
|
+
console.log('after mock');
|
|
33
|
+
`;
|
|
34
|
+
|
|
35
|
+
const output = await transform(input, options);
|
|
36
|
+
|
|
37
|
+
// Remove whitespace and newlines for comparison
|
|
38
|
+
const normalizedOutput = output.code.replace(/\s+/g, "");
|
|
39
|
+
const expectedOutput = `
|
|
40
|
+
jest.mock('./some-module');
|
|
41
|
+
console.log('before mock');
|
|
42
|
+
console.log('after mock');
|
|
43
|
+
`.replace(/\s+/g, "");
|
|
44
|
+
|
|
45
|
+
expect(normalizedOutput).toBe(expectedOutput);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("should hoist multiple jest method calls", async () => {
|
|
49
|
+
const input = `
|
|
50
|
+
console.log('start');
|
|
51
|
+
jest.unmock('./module-a');
|
|
52
|
+
var something = true;
|
|
53
|
+
jest.mock('./module-b');
|
|
54
|
+
jest.enableAutomock();
|
|
55
|
+
console.log('end');
|
|
56
|
+
`;
|
|
57
|
+
|
|
58
|
+
const output = await transform(input, options);
|
|
59
|
+
|
|
60
|
+
// Remove whitespace and newlines for comparison
|
|
61
|
+
const normalizedOutput = output.code.replace(/\s+/g, "");
|
|
62
|
+
const expectedOutput = `
|
|
63
|
+
jest.unmock('./module-a');
|
|
64
|
+
jest.mock('./module-b');
|
|
65
|
+
jest.enableAutomock();
|
|
66
|
+
console.log('start');
|
|
67
|
+
var something = true;
|
|
68
|
+
console.log('end');
|
|
69
|
+
`.replace(/\s+/g, "");
|
|
70
|
+
|
|
71
|
+
expect(normalizedOutput).toBe(expectedOutput);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("should not hoist non-hoistable jest methods", async () => {
|
|
75
|
+
const input = `
|
|
76
|
+
console.log('start');
|
|
77
|
+
jest.spyOn(something, 'method');
|
|
78
|
+
jest.mock('./module');
|
|
79
|
+
console.log('end');
|
|
80
|
+
`;
|
|
81
|
+
|
|
82
|
+
const output = await transform(input, options);
|
|
83
|
+
|
|
84
|
+
// Remove whitespace and newlines for comparison
|
|
85
|
+
const normalizedOutput = output.code.replace(/\s+/g, "");
|
|
86
|
+
const expectedOutput = `
|
|
87
|
+
jest.mock('./module');
|
|
88
|
+
console.log('start');
|
|
89
|
+
jest.spyOn(something, 'method');
|
|
90
|
+
console.log('end');
|
|
91
|
+
`.replace(/\s+/g, "");
|
|
92
|
+
|
|
93
|
+
expect(normalizedOutput).toBe(expectedOutput);
|
|
94
|
+
});
|
|
95
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@swc/plugin-jest",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.1",
|
|
4
4
|
"description": "SWC plugin for jest",
|
|
5
5
|
"main": "swc_plugin_jest.wasm",
|
|
6
6
|
"homepage": "https://swc.rs",
|
|
@@ -19,5 +19,9 @@
|
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@swc/counter": "^0.1.3"
|
|
21
21
|
},
|
|
22
|
-
"scripts": {
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "cargo build --release -p swc_plugin_jest --target wasm32-wasi && cp ../../target/wasm32-wasi/release/swc_plugin_jest.wasm .",
|
|
24
|
+
"build:debug": "cargo build -p swc_plugin_jest --target wasm32-wasi && cp ../../target/wasm32-wasi/debug/swc_plugin_jest.wasm .",
|
|
25
|
+
"test": "npm run build:debug && vitest run"
|
|
26
|
+
}
|
|
23
27
|
}
|
package/swc_plugin_jest.wasm
CHANGED
|
Binary file
|