Skip to content

Commit

Permalink
populate the output directory in unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Feb 6, 2025
1 parent 41ec65a commit 19868de
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
10 changes: 8 additions & 2 deletions internal/bundler_tests/bundler_loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1299,7 +1299,8 @@ func TestWithTypeJSONOverrideLoader(t *testing.T) {
},
entryPaths: []string{"/entry.js"},
options: config.Options{
Mode: config.ModeBundle,
Mode: config.ModeBundle,
AbsOutputFile: "/out.js",
},
})
}
Expand All @@ -1314,7 +1315,8 @@ func TestWithTypeJSONOverrideLoaderGlob(t *testing.T) {
},
entryPaths: []string{"/entry.js"},
options: config.Options{
Mode: config.ModeBundle,
Mode: config.ModeBundle,
AbsOutputFile: "/out.js",
},
})
}
Expand Down Expand Up @@ -1383,6 +1385,7 @@ func TestEmptyLoaderJS(t *testing.T) {
".js": config.LoaderJS,
".empty": config.LoaderEmpty,
},
AbsOutputFile: "/out.js",
},
expectedCompileLog: `entry.js: WARNING: Import "named" will always be undefined because the file "d.empty" has no exports
`,
Expand All @@ -1408,6 +1411,7 @@ func TestEmptyLoaderCSS(t *testing.T) {
".css": config.LoaderCSS,
".empty": config.LoaderEmpty,
},
AbsOutputFile: "/out.js",
},
})
}
Expand All @@ -1427,6 +1431,7 @@ func TestExtensionlessLoaderJS(t *testing.T) {
".js": config.LoaderJS,
"": config.LoaderJS,
},
AbsOutputFile: "/out.js",
},
})
}
Expand All @@ -1446,6 +1451,7 @@ func TestExtensionlessLoaderCSS(t *testing.T) {
".css": config.LoaderCSS,
"": config.LoaderCSS,
},
AbsOutputFile: "/out.js",
},
})
}
Expand Down
3 changes: 3 additions & 0 deletions internal/bundler_tests/bundler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ func (s *suite) __expectBundledImpl(t *testing.T, args bundled, fsKind fs.MockKi
if args.absWorkingDir == "" {
args.absWorkingDir = "/"
}
if args.options.AbsOutputDir == "" {
args.options.AbsOutputDir = args.absWorkingDir // Match the behavior of the API in this case
}

// Handle conversion to Windows-style paths
if fsKind == fs.MockWindows {
Expand Down
24 changes: 12 additions & 12 deletions internal/bundler_tests/snapshots/snapshots_loader.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ console.log(require_test());

================================================================================
TestEmptyLoaderCSS
---------- entry.css.map ----------
---------- /out.js.map ----------
{
"version": 3,
"sources": ["entry.css"],
Expand All @@ -21,7 +21,7 @@ TestEmptyLoaderCSS
"names": []
}

---------- entry.css ----------
---------- /out.js ----------
/* entry.css */
a {
background: url();
Expand Down Expand Up @@ -54,13 +54,13 @@ a {
}
},
"outputs": {
"entry.css.map": {
"out.js.map": {
"imports": [],
"exports": [],
"inputs": {},
"bytes": 203
},
"entry.css": {
"out.js": {
"imports": [
{
"path": "",
Expand All @@ -81,7 +81,7 @@ a {

================================================================================
TestEmptyLoaderJS
---------- entry.js.map ----------
---------- /out.js.map ----------
{
"version": 3,
"sources": ["entry.js"],
Expand All @@ -90,7 +90,7 @@ TestEmptyLoaderJS
"names": ["def"]
}

---------- entry.js ----------
---------- /out.js ----------
// b.empty
var require_b = __commonJS({
"b.empty"() {
Expand Down Expand Up @@ -154,13 +154,13 @@ console.log(ns, import_c.default, void 0);
}
},
"outputs": {
"entry.js.map": {
"out.js.map": {
"imports": [],
"exports": [],
"inputs": {},
"bytes": 377
},
"entry.js": {
"out.js": {
"imports": [],
"exports": [],
"entryPoint": "entry.js",
Expand All @@ -182,7 +182,7 @@ console.log(ns, import_c.default, void 0);

================================================================================
TestExtensionlessLoaderCSS
---------- entry.css ----------
---------- /out.js ----------
/* what */
.foo {
color: red;
Expand All @@ -192,7 +192,7 @@ TestExtensionlessLoaderCSS

================================================================================
TestExtensionlessLoaderJS
---------- entry.js ----------
---------- /out.js ----------
// what
foo();

Expand Down Expand Up @@ -1115,7 +1115,7 @@ console.log(require_test());

================================================================================
TestWithTypeJSONOverrideLoader
---------- entry.js ----------
---------- /out.js ----------
// foo.js
var foo_default = { "this is json not js": true };

Expand All @@ -1124,7 +1124,7 @@ console.log(foo_default);

================================================================================
TestWithTypeJSONOverrideLoaderGlob
---------- entry.js ----------
---------- /out.js ----------
// foo.js
var foo_exports = {};
__export(foo_exports, {
Expand Down

0 comments on commit 19868de

Please sign in to comment.