Releases: iambumblehead/esmock
detect null and undefined loader-returned sources
Detects null AND undefined loader-returned source definitions
diff --git a/src/esmockLoader.js b/src/esmockLoader.js
index 69dedd4..e835ec3 100644
--- a/src/esmockLoader.js
+++ b/src/esmockLoader.js
@@ -145,7 +145,8 @@ const load = async (url, context, nextLoad) => {
if (!/^(commonjs|module)$/.test(nextLoadRes.format))
return nextLoad(url, context)
- const source = nextLoadRes.source === null
+ // nextLoadRes.source sometimes 'undefined' and other times 'null' :(
+ const source = nextLoadRes.source === null || nextLoadRes.source === undefined
? String(await fs.readFile(new URL(url)))
: String(nextLoadRes.source)
const hbang = (source.match(hashbangRe) || [])[0] || ''
node v20.6 solutions
node v20.6 caused some issues. The primary issue was that the newest import.meta.resolve
defined by node has significantly and suddenly changed. The newer import.meta.resolve is less useful and no longer supports the parent param as in the call import.meta.resolve(moduleId, parent)
,
- remove usage of import.meta.resolve,
- only process 'module' and 'commonjs' at the loader
- remove esmockDummy
- resolve any other issues affecting node-v20.6
simplify loader detection
clerical changes to simplify loader detection,
- reuse moduleid regexp replacing separately created regexps
- remove esmockIsLoader.js export from esmockLoader.js instead
- simplify esmockIsLoader, per review @koshic
clerical changes fewer loc
Clerical changes to reduce lines of code and update some test files,
- normalize package.json url and reduce loc for loader verification
- small adjustments reducing lines of code
- clerical changes to some test folders
resolve global mock using mixed esm cjs import trees
resolve global mocking issues when using mixed esm cjs import trees
resolve error global-mocking commonjs
do not error when mocking commonjs global values, found by @tommy-mitchell
support hashbang #!/usr/bin/env node
this no-risk release adds support for files that use hashbang, eg #!/usr/bin/env node
- do not error when processing node hashbang scripts from @tommy-mitchell
- add note explaining why tsx does not work @tommy-mitchell
- pin node 18.16.x to ci test matrix, re nodejs/node#48948
restore ava to node20 test pipeline
This no-risk update restores ava to esmock's unit test pipeline and removes an ava warning from the README,
- restore ava unit-test process at node20 test pipeline
- investigate problems using tsx from @tommy-mitchell
- reported the issue at the tsx project, where tsx fails import moduleIds
improve README examples and descriptions
improve README examples and descriptions,
- improve README example for mocking global values
- use the word 'global' in the global values mocking example only, to improve clarity (hopefully)
feat: mock global vars
This release adds a new feature: support for mocking global values like fetch
, Date
, setTimeout
and others. The wiki will be updated with more details in the next day or so,
- add initial support for the solution to "globalThis" mocks,
- support injecting definitions into the mock import tree,
- demonstrate mock
setTimeout
,fetch
andDate
scenarious at unit-tests - remove node 19 test job, update remaining jobs to use node 20