1
1
import { join } from 'node:path' ;
2
+ import { afterEach , beforeEach , describe } from 'node:test' ;
2
3
import { buildAndGetResults } from 'test-helper' ;
3
- import { expect , test } from 'vitest' ;
4
+ import { afterAll , beforeAll , expect , test , vi } from 'vitest' ;
4
5
5
6
test ( 'tree shaking is enabled by default, bar and baz should be shaken' , async ( ) => {
6
7
const fixturePath = join ( __dirname , 'default' ) ;
@@ -31,40 +32,21 @@ test('tree shaking is disabled by the user, bar and baz should be kept', async (
31
32
32
33
test ( 'minify is enabled by default in mf format, bar and baz should be minified' , async ( ) => {
33
34
const fixturePath = join ( __dirname , 'mf/default' ) ;
35
+ const nodeEnv = process . env . NODE_ENV ;
36
+ process . env . NODE_ENV = 'production' ;
34
37
const { mfExposeEntry } = await buildAndGetResults ( { fixturePath } ) ;
38
+ process . env . NODE_ENV = nodeEnv ;
35
39
// biome-ignore format: snapshot
36
- expect ( mfExposeEntry ) . toMatchInlineSnapshot ( `""use strict";(globalThis["default_minify"]=globalThis["default_minify"]||[]).push([["249"],{"../../__fixtures__/src/index.ts" :function(__unused_webpack_module,__webpack_exports__,__webpack_require__){__webpack_require__.r(__webpack_exports__);__webpack_require__.d(__webpack_exports__,{foo:function(){return foo}});const foo=()=>{}}}]);"` ) ;
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=()=>{}}}]);"` ) ;
37
41
} ) ;
38
42
39
43
test ( 'minify is disabled by the user, bar and baz should not be minified' , async ( ) => {
40
44
const fixturePath = join ( __dirname , 'mf/config' ) ;
41
- const { mfExposeEntry } = await buildAndGetResults ( { fixturePath } ) ;
42
- expect ( mfExposeEntry ) . toMatchInlineSnapshot ( `
43
- ""use strict";
44
- (globalThis['disable_minify'] = globalThis['disable_minify'] || []).push([["249"], {
45
- "../../__fixtures__/src/index.ts": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
46
- __webpack_require__.r(__webpack_exports__);
47
- __webpack_require__.d(__webpack_exports__, {
48
- foo: function() { return foo; }
49
- });
50
- const foo = ()=>{};
51
- const bar = ()=>{};
52
- const baz = ()=>{
53
- return bar();
54
- };
55
-
56
-
57
- }),
58
-
59
- }]);"
60
- ` ) ;
61
- } ) ;
62
-
63
- test ( 'enable minify and set NODE_ENV to production, the moduleIds should be the deterministic' , async ( ) => {
64
- const fixturePath = join ( __dirname , 'mf/config' ) ;
65
- const prevNodeEnv = process . env . NODE_ENV ;
45
+ const nodeEnv = process . env . NODE_ENV ;
66
46
process . env . NODE_ENV = 'production' ;
67
47
const { mfExposeEntry } = await buildAndGetResults ( { fixturePath } ) ;
48
+ process . env . NODE_ENV = nodeEnv ;
49
+
68
50
expect ( mfExposeEntry ) . toMatchInlineSnapshot ( `
69
51
""use strict";
70
52
(globalThis['disable_minify'] = globalThis['disable_minify'] || []).push([["249"], {
@@ -84,6 +66,4 @@ test('enable minify and set NODE_ENV to production, the moduleIds should be the
84
66
85
67
}]);"
86
68
` ) ;
87
-
88
- process . env . NODE_ENV = prevNodeEnv ;
89
69
} ) ;
0 commit comments