Skip to content

Commit

Permalink
Add test for #238: browser field and native node modules
Browse files Browse the repository at this point in the history
  • Loading branch information
SamyPesse authored and evanw committed Jul 8, 2020
1 parent bb8bf54 commit 95de9bd
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions internal/bundler/bundler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1970,6 +1970,53 @@ console.log(demo_pkg.default());
})
}

func TestPackageJsonBrowserMapNativeModuleDisabled(t *testing.T) {
expectBundled(t, bundled{
files: map[string]string{
"/Users/user/project/src/entry.js": `
import fn from 'demo-pkg'
console.log(fn())
`,
"/Users/user/project/node_modules/demo-pkg/package.json": `
{
"browser": {
"fs": false
}
}
`,
"/Users/user/project/node_modules/demo-pkg/index.js": `
const fs = require('fs')
module.exports = function() {
return fs.readFile()
}
`,
},
entryPaths: []string{"/Users/user/project/src/entry.js"},
options: config.Options{
IsBundling: true,
AbsOutputFile: "/Users/user/project/out.js",
},
expected: map[string]string{
"/Users/user/project/out.js": `// disabled:fs
var require_disabled_fs = __commonJS(() => {
});
// /Users/user/project/node_modules/demo-pkg/index.js
var require_demo_pkg = __commonJS((exports, module) => {
const fs = require_disabled_fs();
module.exports = function() {
return fs.readFile();
};
});
// /Users/user/project/src/entry.js
const demo_pkg = __toModule(require_demo_pkg());
console.log(demo_pkg.default());
`,
},
})
}

func TestPackageJsonBrowserMapAvoidMissing(t *testing.T) {
expectBundled(t, bundled{
files: map[string]string{
Expand Down

0 comments on commit 95de9bd

Please sign in to comment.