From 8fc693e39630b99ba8ec47131abe5e6ce9ee94aa Mon Sep 17 00:00:00 2001 From: chris Date: Tue, 2 Nov 2021 23:28:14 -0700 Subject: [PATCH 1/2] add node 17.x --- .github/workflows/node.js.yml | 2 +- README.md | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 6c460186..594de6c1 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -16,7 +16,7 @@ jobs: strategy: matrix: - node-version: [12.x, 14.x, 16.x] + node-version: [12.x, 14.x, 16.x, 17.x] # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ steps: diff --git a/README.md b/README.md index 52453049..b099eb78 100644 --- a/README.md +++ b/README.md @@ -100,15 +100,17 @@ test('should mock modules and local files at same time', async t => { ### changelog + * 1.0.1 _Nov.02.2001_ + * add node v17.x to testing pipelin * 1.0.0 _Oct.27.2001_ * release version 1.0 * 0.4.2 _Oct.27.2021_ * export 'load' hook from moduleLoader, required by node v16.12.0+ * 0.4.1 _Oct.10.2021_ * version bump, increment devDependencies, - * major improvement to READE, thanks @swivelgames + * major improvement to README, thanks @swivelgames * 0.4.0 _Sep.07.2021_ - * do not runtime error when returuning type '[object Module]' default + * do not runtime error when returning type '[object Module]' default * 0.3.9 _May.05.2021_ * small change to README * added a test, update gitlab action to use node 16.x From 3e3b6902616470f471806f81efbaa311313fb447 Mon Sep 17 00:00:00 2001 From: chris Date: Tue, 2 Nov 2021 23:33:04 -0700 Subject: [PATCH 2/2] call load with getSource --- src/esmockLoader.mjs | 29 ++++------------------------- 1 file changed, 4 insertions(+), 25 deletions(-) diff --git a/src/esmockLoader.mjs b/src/esmockLoader.mjs index c43a1d6b..c20698be 100644 --- a/src/esmockLoader.mjs +++ b/src/esmockLoader.mjs @@ -40,30 +40,6 @@ export async function resolve (specifier, context, defaultResolve) { return resolved; } -// supported by node version less than 16.12 -export async function getSource (url, context, defaultGetSource) { - if (/#esmockModuleKeys/gi.test(url)) // parent of mocked modules - return defaultGetSource(url, context, defaultGetSource); - - [ url ] = url.split('?esmockGlobals='); - if (url.startsWith(urlDummy)) { - url = url.replace(/[^#]*#/, ''); - } - - const exportedNames = /exportNames=/.test(url) && - url.replace(/.*exportNames=(.*)/, '$1').split(','); - if (exportedNames) { - return { - source : exportedNames.map(name => name === 'default' - ? `export default global.esmockCacheGet("${url}").default` - : `export const ${name} = global.esmockCacheGet("${url}").${name}` - ).join('\n') - }; - } - - return defaultGetSource(url, context, defaultGetSource); -} - export async function load (url, context, defaultGetSource) { if (/#esmockModuleKeys/gi.test(url)) // parent of mocked modules return defaultGetSource(url, context, defaultGetSource); @@ -88,4 +64,7 @@ export async function load (url, context, defaultGetSource) { return defaultGetSource(url, context, defaultGetSource); } - +// supported by node version less than 16.12 +export async function getSource (url, context, defaultGetSource) { + return load(url, context, defaultGetSource); +}