Skip to content

Commit

Permalink
some more "exports" tests
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Mar 8, 2021
1 parent 2450512 commit cd381fa
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
44 changes: 44 additions & 0 deletions internal/bundler/bundler_packagejson_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1569,3 +1569,47 @@ func TestPackageJsonExportsNeutral(t *testing.T) {
},
})
}

func TestPackageJsonExportsOrderIndependent(t *testing.T) {
packagejson_suite.expectBundled(t, bundled{
files: map[string]string{
"/Users/user/project/src/entry.js": `
import 'pkg1/foo/bar.js'
import 'pkg2/foo/bar.js'
`,
"/Users/user/project/node_modules/pkg1/package.json": `
{
"exports": {
"./": "./1/",
"./foo/": "./2/"
}
}
`,
"/Users/user/project/node_modules/pkg1/1/foo/bar.js": `
console.log('FAILURE')
`,
"/Users/user/project/node_modules/pkg1/2/bar.js": `
console.log('SUCCESS')
`,
"/Users/user/project/node_modules/pkg2/package.json": `
{
"exports": {
"./foo/": "./1/",
"./": "./2/"
}
}
`,
"/Users/user/project/node_modules/pkg2/1/bar.js": `
console.log('SUCCESS')
`,
"/Users/user/project/node_modules/pkg2/2/foo/bar.js": `
console.log('FAILURE')
`,
},
entryPaths: []string{"/Users/user/project/src/entry.js"},
options: config.Options{
Mode: config.ModeBundle,
AbsOutputFile: "/Users/user/project/out.js",
},
})
}
9 changes: 9 additions & 0 deletions internal/bundler/snapshots/snapshots_packagejson.txt
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,15 @@ TestPackageJsonExportsNode
// Users/user/project/node_modules/pkg/node.js
console.log("SUCCESS");

================================================================================
TestPackageJsonExportsOrderIndependent
---------- /Users/user/project/out.js ----------
// Users/user/project/node_modules/pkg1/2/bar.js
console.log("SUCCESS");

// Users/user/project/node_modules/pkg2/1/bar.js
console.log("SUCCESS");

================================================================================
TestPackageJsonExportsRequireOverImport
---------- /Users/user/project/out.js ----------
Expand Down
28 changes: 28 additions & 0 deletions scripts/end-to-end-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -2808,6 +2808,34 @@
}
}`,
}),
test(['in.js', '--outfile=node.js', '--format=esm'].concat(flags), {
'in.js': `import abc from 'pkg/foo'; if (abc !== 123) throw 'fail'`,
'package.json': `{ "type": "module" }`,
'node_modules/pkg/yes.js': `export default 123`,
'node_modules/pkg/package.json': `{
"type": "module",
"exports": {
"./foo": [
{ "unused": "./no.js" },
"./yes.js"
]
}
}`,
}),
test(['in.js', '--outfile=node.js', '--format=esm'].concat(flags), {
'in.js': `import abc from 'pkg/foo'; if (abc !== 123) throw 'fail'`,
'package.json': `{ "type": "module" }`,
'node_modules/pkg/yes.js': `export default 123`,
'node_modules/pkg/package.json': `{
"type": "module",
"exports": {
"./foo": [
{ "default": "./yes.js" },
"./no.js"
]
}
}`,
}),
)
}

Expand Down

0 comments on commit cd381fa

Please sign in to comment.