Skip to content

Commit

Permalink
Merge pull request #19 from iambumblehead/make-warning-go-away
Browse files Browse the repository at this point in the history
try to null getSource export
  • Loading branch information
iambumblehead authored Nov 6, 2021
2 parents 3304bf5 + 42d940a commit 246cafd
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ 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
* add node v17.x to testing pipeline
* add, make warning message go away for node 16.12.0+
* 1.0.0 _Oct.27.2001_
* release version 1.0
* 0.4.2 _Oct.27.2021_
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "esmock",
"version": "1.0.0",
"version": "1.0.1",
"license": "MIT",
"readmeFilename": "README.md",
"description": "mock esm modules for unit-tests",
Expand Down Expand Up @@ -57,6 +57,7 @@
},
"scripts": {
"test": "ava --node-arguments=\"--loader=./src/esmockLoader.mjs\"",
"test-no-warn": "ava --node-arguments=\"--loader=./src/esmockLoader.mjs --no-warnings\"",
"lint": "eslint src/*js spec/*js"
}
}
11 changes: 10 additions & 1 deletion src/esmockLoader.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ export async function load (url, context, defaultGetSource) {
}

// supported by node version less than 16.12
export async function getSource (url, context, defaultGetSource) {
const [ nodeMjr, nodeMnr ] = process.versions.node.split('.').map(Number);
const nodelt1612 = nodeMjr < 16 || (nodeMjr === 16 && nodeMnr < 12);

async function getSource (url, context, defaultGetSource) {
return load(url, context, defaultGetSource);
}

// make this null node versions after 16.11 so taht warning message
// is not printed
if (!nodelt1612) getSource = null;

export { getSource };

0 comments on commit 246cafd

Please sign in to comment.