Skip to content

Commit

Permalink
fix: all tests cases
Browse files Browse the repository at this point in the history
  • Loading branch information
fi3ework committed Sep 20, 2024
1 parent 96fe32b commit 14d8fa8
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 52 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
import { value as v1 } from "./module1";
const v2 = require("./module2")
const module3Inc = require("./module3")
import { value as value1 } from './module1'
const value2 = require('./module2')
const value3 = require('./module3')

const index_value = 10;
let value = 42;
let value = 42
let src_value = 43
let src_src_value = 44

function inc() {
value++;
}

it("single inlined module should not be wrapped in IIFE", () => {
expect(value).toBe(42);
expect(v1).toBe(undefined);
expect(v2).toBe(undefined);
expect(module3Inc).toBe(undefined);
inc();
expect(value).toBe(43);
expect(index_value).toBe(10);
});
it('inlined module should not leak to non-inlined modules', () => {
expect(value1).toBe(undefined)
expect(value).toBe(42)
expect(src_value).toBe(43)
expect(src_src_value).toBe(44)
expect(value2).toBe("undefined") // should not touch leaked `value` variable
expect(value3).toBe("undefined") // should not touch leaked `src_value` variable
})
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
let value;
let value

export { value };
export { value }
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
let value

module.exports = value
module.exports = typeof value
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
let inc

module.exports = inc
module.exports = typeof src_value
2 changes: 1 addition & 1 deletion test/configCases/output-module/iife-innter-strict/foo.cjs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = 'foo'
module.exports = 42;
15 changes: 14 additions & 1 deletion test/configCases/output-module/iife-innter-strict/index.mjs
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
import foo from './foo.cjs'
import foo from './foo.cjs';

let answer

try {
delete Object.prototype; // will throw error in strict mode
answer = 'no';
} catch {
answer = 'yes';
}

it("multiple inlined modules should be wrapped in IIFE to isolate from other inlined modules and chunk modules", () => {
expect(answer).toBe("yes"); // the code should throw in strict mode
});

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

it("multiple inlined modules should be wrapped in IIFE to isolate from other inlined modules and chunk modules", () => {
expect(typeof value).toBe("undefined"); // `value` in index2 should not leak to index1
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var value = 42

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @type {import("../../../../").Configuration[]} */
module.exports = [
{
entry: ["./index-1.js", "./index-2.js"],
entry: ["./index1.js", "./index2.js"],
output: {
module: true
},
Expand Down

0 comments on commit 14d8fa8

Please sign in to comment.