From ce43fc44deb2598ce71f5fe0df5304ba2b26ac40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Tue, 7 Jul 2020 12:18:27 +0200 Subject: [PATCH] Test adding a integration test --- internal/bundler/bundler_test.go | 47 ++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/internal/bundler/bundler_test.go b/internal/bundler/bundler_test.go index a0fbd5d583a..93b85839047 100644 --- a/internal/bundler/bundler_test.go +++ b/internal/bundler/bundler_test.go @@ -1963,6 +1963,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": `// /Users/user/project/node_modules/node-pkg/index.js +var require_fs = __commonJS(() => { +}); + +// /Users/user/project/node_modules/demo-pkg/index.js +var require_demo_pkg = __commonJS((exports, module) => { + const fn2 = require_fs(); + module.exports = function() { + return fn2.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{