Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: support node:test in node 18 (#62)
- Loading branch information
1 parent
c2eed03
commit 019fbf5
Showing
21 changed files
with
878 additions
and
412 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,56 @@ | ||
const fs = require('node:fs'); | ||
|
||
console.log( | ||
'loaded cjs-ext-cjs/index.cjs', | ||
JSON.stringify({ | ||
nodePrefix: Boolean(fs), | ||
hasDynamicImport: Boolean(import('fs')), | ||
dirname: typeof __dirname === 'string', | ||
...(() => { | ||
let nameInError; | ||
try { | ||
nameInError(); | ||
} catch (error) { | ||
return { | ||
nameInError: error.message.includes('nameInError'), | ||
sourceMap: error.stack.includes(':12:5'), | ||
}; | ||
} | ||
})(), | ||
}), | ||
async function test(description, testFunction) { | ||
try { | ||
const result = await testFunction(); | ||
if (!result) { throw result; } | ||
console.log(`✔ ${description}`); | ||
} catch (error) { | ||
console.log(`✖ ${description}: ${error.toString().split('\n').shift()}`); | ||
} | ||
} | ||
|
||
console.log('loaded cjs-ext-cjs/index.cjs'); | ||
|
||
test( | ||
'has CJS context', | ||
() => typeof require !== 'undefined' || typeof module !== 'undefined', | ||
); | ||
|
||
// esbuild uses import.meta as a signal for ESM | ||
// test( | ||
// 'import.meta.url', | ||
// () => Boolean(import.meta.url), | ||
// ); | ||
|
||
test( | ||
'name in error', | ||
() => { | ||
let nameInError; | ||
try { | ||
nameInError(); | ||
} catch (error) { | ||
return error.message.includes('nameInError'); | ||
} | ||
}, | ||
); | ||
|
||
test( | ||
'sourcemaps', | ||
() => new Error().stack.includes(':38:'), | ||
); | ||
|
||
test( | ||
'resolves optional node prefix', | ||
() => Boolean(require('node:fs')), | ||
); | ||
|
||
test( | ||
'resolves required node prefix', | ||
() => Boolean(require('node:test')), | ||
); | ||
|
||
test( | ||
'has dynamic import', | ||
() => import('fs').then(Boolean), | ||
); | ||
|
||
module.exports = 1234; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,59 @@ | ||
const fs = require('node:fs'); | ||
|
||
console.log( | ||
'loaded cjs-ext-js/index.js', | ||
JSON.stringify({ | ||
nodePrefix: Boolean(fs), | ||
hasDynamicImport: Boolean(import('fs')), | ||
dirname: typeof __dirname === 'string', | ||
...(() => { | ||
let nameInError; | ||
try { | ||
nameInError(); | ||
} catch (error) { | ||
return { | ||
nameInError: error.message.includes('nameInError'), | ||
sourceMap: error.stack.includes(':12:5'), | ||
}; | ||
} | ||
})(), | ||
}), | ||
async function test(description, testFunction) { | ||
try { | ||
const result = await testFunction(); | ||
if (!result) { throw result; } | ||
console.log(`✔ ${description}`); | ||
} catch (error) { | ||
console.log(`✖ ${description}: ${error.toString().split('\n').shift()}`); | ||
} | ||
} | ||
|
||
console.log('loaded cjs-ext-js/index.js'); | ||
|
||
test( | ||
'has CJS context', | ||
() => typeof require !== 'undefined' || typeof module !== 'undefined', | ||
); | ||
|
||
// esbuild uses import.meta as a signal for ESM | ||
// test( | ||
// 'import.meta.url', | ||
// () => Boolean(import.meta.url), | ||
// ); | ||
|
||
test( | ||
'name in error', | ||
() => { | ||
let nameInError; | ||
try { | ||
nameInError(); | ||
} catch (error) { | ||
return error.message.includes('nameInError'); | ||
} | ||
}, | ||
); | ||
|
||
test( | ||
'sourcemaps', | ||
() => new Error().stack.includes(':38:'), | ||
); | ||
|
||
module.exports = 1234; | ||
test( | ||
'resolves optional node prefix', | ||
() => Boolean(require('node:fs')), | ||
); | ||
|
||
test( | ||
'resolves required node prefix', | ||
() => Boolean(require('node:test')), | ||
); | ||
|
||
test( | ||
'has dynamic import', | ||
() => import('fs').then(Boolean), | ||
); | ||
|
||
test( | ||
'module exports', | ||
() => module.exports = 1234, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,55 @@ | ||
import fs from 'node:fs'; | ||
|
||
console.log( | ||
'loaded esm-ext-js/index.js', | ||
JSON.stringify({ | ||
nodePrefix: Boolean(fs), | ||
hasDynamicImport: Boolean(import('fs')), | ||
dirname: typeof __dirname === 'string', | ||
...(() => { | ||
let nameInError; | ||
try { | ||
nameInError(); | ||
} catch (error) { | ||
return { | ||
nameInError: error.message.includes('nameInError'), | ||
sourceMap: error.stack.includes(':12:5'), | ||
}; | ||
} | ||
})(), | ||
}), | ||
async function test(description, testFunction) { | ||
try { | ||
const result = await testFunction(); | ||
if (!result) { throw result; } | ||
console.log(`✔ ${description}`); | ||
} catch (error) { | ||
console.log(`✖ ${description}: ${error.toString().split('\n').shift()}`); | ||
} | ||
} | ||
|
||
console.log('loaded esm-ext-js/index.js'); | ||
|
||
test( | ||
'has CJS context', | ||
() => typeof require !== 'undefined' || typeof module !== 'undefined', | ||
); | ||
|
||
test( | ||
'import.meta.url', | ||
() => Boolean(import.meta.url), | ||
); | ||
|
||
test( | ||
'name in error', | ||
() => { | ||
let nameInError; | ||
try { | ||
nameInError(); | ||
} catch (error) { | ||
return error.message.includes('nameInError'); | ||
} | ||
}, | ||
); | ||
|
||
test( | ||
'sourcemaps', | ||
() => new Error().stack.includes(':37:'), | ||
); | ||
|
||
test( | ||
'has dynamic import', | ||
() => import('fs').then(Boolean), | ||
); | ||
|
||
test( | ||
'resolves optional node prefix', | ||
() => import('node:fs').then(Boolean), | ||
); | ||
|
||
test( | ||
'resolves required node prefix', | ||
() => import('node:test').then(Boolean), | ||
); | ||
|
||
export default 1234; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,55 @@ | ||
import fs from 'node:fs'; | ||
|
||
console.log( | ||
'loaded esm-ext-mjs/index.mjs', | ||
JSON.stringify({ | ||
nodePrefix: Boolean(fs), | ||
hasDynamicImport: Boolean(import('fs')), | ||
dirname: typeof __dirname === 'string', | ||
...(() => { | ||
let nameInError; | ||
try { | ||
nameInError(); | ||
} catch (error) { | ||
return { | ||
nameInError: error.message.includes('nameInError'), | ||
sourceMap: error.stack.includes(':12:5'), | ||
}; | ||
} | ||
})(), | ||
}), | ||
async function test(description, testFunction) { | ||
try { | ||
const result = await testFunction(); | ||
if (!result) { throw result; } | ||
console.log(`✔ ${description}`); | ||
} catch (error) { | ||
console.log(`✖ ${description}: ${error.toString().split('\n').shift()}`); | ||
} | ||
} | ||
|
||
console.log('loaded esm-ext-mjs/index.mjs'); | ||
|
||
test( | ||
'has CJS context', | ||
() => typeof require !== 'undefined' || typeof module !== 'undefined', | ||
); | ||
|
||
test( | ||
'import.meta.url', | ||
() => Boolean(import.meta.url), | ||
); | ||
|
||
test( | ||
'name in error', | ||
() => { | ||
let nameInError; | ||
try { | ||
nameInError(); | ||
} catch (error) { | ||
return error.message.includes('nameInError'); | ||
} | ||
}, | ||
); | ||
|
||
test( | ||
'sourcemaps', | ||
() => new Error().stack.includes(':37:'), | ||
); | ||
|
||
test( | ||
'has dynamic import', | ||
() => import('fs').then(Boolean), | ||
); | ||
|
||
test( | ||
'resolves optional node prefix', | ||
() => import('node:fs').then(Boolean), | ||
); | ||
|
||
test( | ||
'resolves required node prefix', | ||
() => import('node:test').then(Boolean), | ||
); | ||
|
||
export default 1234; |
Oops, something went wrong.