Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

Commit

Permalink
chore: add test for node: prefix (#698)
Browse files Browse the repository at this point in the history
* chore: add failing test

* chore: update package.json precinct to 8.2, too

consumers of this package should use ^8.2!

* chore: update test to reflect stream/web problems

* chore: adapt fixture to streams

* Update main.js

* Update main.js

* chore: revert change to `package.json`

Co-authored-by: Netlify Team Account 1 <netlify-team-account-1@users.noreply.github.com>
Co-authored-by: Netlify Team Account 1 <90322326+netlify-team-account-1@users.noreply.github.com>
  • Loading branch information
3 people committed Nov 8, 2021
1 parent 06f447b commit 6cc2b3a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tests/fixtures/node-force-builtin/function.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const stream = require('node:stream/web')

module.exports = () => {
return Boolean(stream.ReadableStream)
}
29 changes: 29 additions & 0 deletions tests/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2250,6 +2250,35 @@ testMany(
},
)

testMany(
'Handles built-in modules imported with the `node:` prefix',
['bundler_default', 'bundler_default_nft', 'bundler_nft', 'bundler_esbuild', 'bundler_esbuild_zisi'],
async (options, t) => {
t.plan(3)
const { tmpDir, files } = await zipFixture(t, 'node-force-builtin', {
opts: { config: { '*': { ...options } } },
})

await unzipFiles(files)

if (semver.satisfies(nodeVersion, '>=16')) {
const func = require(`${tmpDir}/function`)
t.true(func())
} else {
try {
require(`${tmpDir}/function`)
} catch (error) {
t.is(
error.message,
semver.satisfies(nodeVersion, '>10')
? 'No such built-in module: node:stream/web'
: "Cannot find module 'node:stream/web'",
)
}
}
},
)

testMany(
'Returns a `size` property with the size of each generated archive',
['bundler_default', 'bundler_esbuild', 'bundler_nft'],
Expand Down

1 comment on commit 6cc2b3a

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⏱ Benchmark results

largeDepsEsbuild: 6.7s

largeDepsNft: 43.8s

largeDepsZisi: 55.2s

Please sign in to comment.