Skip to content

Commit a167a89

Browse files
committed
chore: fix test
1 parent 2925523 commit a167a89

File tree

1 file changed

+37
-33
lines changed

1 file changed

+37
-33
lines changed
Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { join } from 'node:path';
2-
import { afterEach, beforeEach, describe } from 'node:test';
32
import { buildAndGetResults } from 'test-helper';
4-
import { afterAll, beforeAll, expect, test, vi } from 'vitest';
3+
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';
54

65
test('tree shaking is enabled by default, bar and baz should be shaken', async () => {
76
const fixturePath = join(__dirname, 'default');
@@ -30,40 +29,45 @@ test('tree shaking is disabled by the user, bar and baz should be kept', async (
3029
`);
3130
});
3231

33-
test('minify is enabled by default in mf format, bar and baz should be minified', async () => {
34-
const fixturePath = join(__dirname, 'mf/default');
35-
const nodeEnv = process.env.NODE_ENV;
36-
process.env.NODE_ENV = 'production';
37-
const { mfExposeEntry } = await buildAndGetResults({ fixturePath });
38-
process.env.NODE_ENV = nodeEnv;
39-
// biome-ignore format: snapshot
40-
expect(mfExposeEntry).toMatchInlineSnapshot(`""use strict";(globalThis["default_minify"]=globalThis["default_minify"]||[]).push([["249"],{163:function(__unused_webpack_module,__webpack_exports__,__webpack_require__){__webpack_require__.r(__webpack_exports__);__webpack_require__.d(__webpack_exports__,{foo:function(){return foo}});const foo=()=>{}}}]);"`);
41-
});
32+
describe('tree shaking is disabled by the user, bar and baz should be kept', () => {
33+
beforeEach(() => {
34+
// 使用 vi.stubEnv 来模拟环境变量
35+
vi.stubEnv('NODE_ENV', 'production');
36+
});
4237

43-
test('minify is disabled by the user, bar and baz should not be minified', async () => {
44-
const fixturePath = join(__dirname, 'mf/config');
45-
const nodeEnv = process.env.NODE_ENV;
46-
process.env.NODE_ENV = 'production';
47-
const { mfExposeEntry } = await buildAndGetResults({ fixturePath });
48-
process.env.NODE_ENV = nodeEnv;
38+
afterEach(() => {
39+
// 清理环境变量
40+
vi.unstubAllEnvs();
41+
});
4942

50-
expect(mfExposeEntry).toMatchInlineSnapshot(`
51-
""use strict";
52-
(globalThis['disable_minify'] = globalThis['disable_minify'] || []).push([["249"], {
53-
"163": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
54-
__webpack_require__.r(__webpack_exports__);
55-
__webpack_require__.d(__webpack_exports__, {
56-
foo: function() { return foo; }
57-
});
58-
const foo = ()=>{};
59-
const bar = ()=>{};
60-
const baz = ()=>{
61-
return bar();
62-
};
43+
test('minify is enabled by default in mf format, bar and baz should be minified', async () => {
44+
const fixturePath = join(__dirname, 'mf/default');
45+
const { mfExposeEntry } = await buildAndGetResults({ fixturePath });
46+
// biome-ignore format: snapshot
47+
expect(mfExposeEntry).toMatchInlineSnapshot(`""use strict";(globalThis["default_minify"]=globalThis["default_minify"]||[]).push([["249"],{163:function(__unused_webpack_module,__webpack_exports__,__webpack_require__){__webpack_require__.r(__webpack_exports__);__webpack_require__.d(__webpack_exports__,{foo:function(){return foo}});const foo=()=>{}}}]);"`);
48+
});
6349

50+
test('minify is disabled by the user, bar and baz should not be minified', async () => {
51+
const fixturePath = join(__dirname, 'mf/config');
52+
const { mfExposeEntry } = await buildAndGetResults({ fixturePath });
6453

65-
}),
54+
console.log(333, mfExposeEntry);
55+
expect(mfExposeEntry).toMatchInlineSnapshot(`""use strict";
56+
(globalThis['disable_minify'] = globalThis['disable_minify'] || []).push([["249"], {
57+
"163": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
58+
__webpack_require__.r(__webpack_exports__);
59+
__webpack_require__.d(__webpack_exports__, {
60+
foo: function() { return foo; }
61+
});
62+
const foo = ()=>{};
63+
const bar = ()=>{};
64+
const baz = ()=>{
65+
return bar();
66+
};
6667
67-
}]);"
68-
`);
68+
69+
}),
70+
71+
}]);"`);
72+
});
6973
});

0 commit comments

Comments
 (0)