Skip to content

Commit

Permalink
skip the test on older node versions without module.register
Browse files Browse the repository at this point in the history
  • Loading branch information
timfish committed May 23, 2024
1 parent 9b4237b commit 7910b64
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions test/process-module/test.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
import { register } from 'module'
import * as assert from 'assert'
import * as mod from 'module'

register('../../hook.mjs', import.meta.url)
const [major, minor] = process.versions.node.split('.').map(Number)

const rootExports = await import('../fixtures/re-export-star-external.mjs')
assert.equal(rootExports.foo, 'bar')
console.log('export * from \'some-external-module\'\n ✅ contains exports: foo')
if (!((major >= 21) || (major >= 18 && minor >= 19) || (major >= 20 && minor >= 6))) {
console.log('skipping test due to requiring Node.js >= v18.19.0 or v20.6.0')
process.exit(0)
}

const namedExports = await import('../fixtures/sub-directory/re-export-star-external.mjs')
assert.equal(namedExports.bar, 'baz')
console.log('export * from \'some-external-module/sub\'\n ✅ contains exports: bar')
mod.register('../../hook.mjs', import.meta.url)

import('../fixtures/re-export-star-external.mjs').then(exports => {
assert.equal(exports.foo, 'bar')
console.log('export * from \'some-external-module\'\n ✅ contains exports: foo')
})

import('../fixtures/sub-directory/re-export-star-external.mjs').then(exports => {
assert.equal(exports.bar, 'baz')
console.log('export * from \'some-external-module/sub\'\n ✅ contains exports: bar')
})

0 comments on commit 7910b64

Please sign in to comment.