11import { join } from 'node:path' ;
2+ import { afterEach , beforeEach , describe } from 'node:test' ;
23import { buildAndGetResults } from 'test-helper' ;
3- import { expect , test } from 'vitest' ;
4+ import { afterAll , beforeAll , expect , test , vi } from 'vitest' ;
45
56test ( 'tree shaking is enabled by default, bar and baz should be shaken' , async ( ) => {
67 const fixturePath = join ( __dirname , 'default' ) ;
@@ -31,40 +32,21 @@ test('tree shaking is disabled by the user, bar and baz should be kept', async (
3132
3233test ( 'minify is enabled by default in mf format, bar and baz should be minified' , async ( ) => {
3334 const fixturePath = join ( __dirname , 'mf/default' ) ;
35+ const nodeEnv = process . env . NODE_ENV ;
36+ process . env . NODE_ENV = 'production' ;
3437 const { mfExposeEntry } = await buildAndGetResults ( { fixturePath } ) ;
38+ process . env . NODE_ENV = nodeEnv ;
3539 // 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=()=>{}}}]);"` ) ;
3741} ) ;
3842
3943test ( 'minify is disabled by the user, bar and baz should not be minified' , async ( ) => {
4044 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 ;
6646 process . env . NODE_ENV = 'production' ;
6747 const { mfExposeEntry } = await buildAndGetResults ( { fixturePath } ) ;
48+ process . env . NODE_ENV = nodeEnv ;
49+
6850 expect ( mfExposeEntry ) . toMatchInlineSnapshot ( `
6951 ""use strict";
7052 (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
8466
8567 }]);"
8668 ` ) ;
87-
88- process . env . NODE_ENV = prevNodeEnv ;
8969} ) ;
0 commit comments