Skip to content

Commit

Permalink
add test for inject + define
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Jan 22, 2023
1 parent 6c25c9e commit 1f99267
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
34 changes: 34 additions & 0 deletions internal/bundler_tests/bundler_default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4841,6 +4841,40 @@ inject.js: NOTE: The symbol "test" was exported from "inject.js" here:
})
}

func TestInjectWithDefine(t *testing.T) {
default_suite.expectBundled(t, bundled{
files: map[string]string{
"/entry.js": `
console.log(
// define wins over inject
both === 'define',
// define forwards to inject
first === 'second',
)
`,
"/inject.js": `
export let both = 'inject'
export let first = 'TEST FAILED!'
export let second = 'second'
`,
},
entryPaths: []string{"/entry.js"},
options: config.Options{
Mode: config.ModeBundle,
AbsOutputFile: "/out.js",
InjectPaths: []string{
"/inject.js",
},
Defines: &config.ProcessedDefines{
IdentifierDefines: map[string]config.DefineData{
"both": {DefineExpr: &config.DefineExpr{Constant: &js_ast.EString{Value: helpers.StringToUTF16("define")}}},
"first": {DefineExpr: &config.DefineExpr{Parts: []string{"second"}}},
},
},
},
})
}

func TestOutbase(t *testing.T) {
default_suite.expectBundled(t, bundled{
files: map[string]string{
Expand Down
14 changes: 14 additions & 0 deletions internal/bundler_tests/snapshots/snapshots_default.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1995,6 +1995,20 @@ console.log(replace.test);
console.log(collide);
console.log(re_export);

================================================================================
TestInjectWithDefine
---------- /out.js ----------
// inject.js
var second = "second";

// entry.js
console.log(
// define wins over inject
true,
// define forwards to inject
second === "second"
);

================================================================================
TestJSXAutomaticImportsCommonJS
---------- /out.js ----------
Expand Down

0 comments on commit 1f99267

Please sign in to comment.