Comparing version 0.0.1 to 0.1.0
{ | ||
"name": "esmock", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"license": "MIT", | ||
@@ -8,7 +8,5 @@ "readmeFilename": "README.md", | ||
"author": "Chris <chris@bumblehead.com>", | ||
"main": "src/esmock.js", | ||
"module": "src/esmock.js", | ||
"files": [ | ||
"src/esmock.js" | ||
], | ||
"main": "src/esmockLoader.mjs", | ||
"module": "src/esmockLoader.mjs", | ||
"type": "module", | ||
"repository": { | ||
@@ -19,2 +17,3 @@ "type": "git", | ||
"keywords": [ | ||
"esm", | ||
"esmock", | ||
@@ -39,23 +38,15 @@ "es6", | ||
"dependencies": { | ||
"async-mutex": "^0.2.6", | ||
"resolvewithplus": "^0.1.1" | ||
"resolvewithplus": "^0.2.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "^3.15.0", | ||
"ava": "^4.0.0-alpha.2", | ||
"babel-eslint": "^10.1.0", | ||
"eslint": "^7.17.0", | ||
"esm": "^3.2.25", | ||
"form-urlencoded": "^4.2.1", | ||
"sinon": "^9.2.3" | ||
"sinon": "^10.0.0" | ||
}, | ||
"ava": { | ||
"timeout": "2m", | ||
"require": [ | ||
"esm" | ||
] | ||
}, | ||
"scripts": { | ||
"test": "ava", | ||
"test": "ava --node-arguments=\"--loader=./src/esmockLoader.mjs\"", | ||
"lint": "eslint src/*js spec/*js" | ||
} | ||
} |
@@ -5,4 +5,26 @@ esmock | ||
[![Build Status](https://travis-ci.org/iambumblehead/esmock.svg?branch=master)](https://travis-ci.org/iambumblehead/esmock) | ||
[![npm version](https://badge.fury.io/js/esmock.svg)](https://badge.fury.io/js/esmock) [![Build Status](https://travis-ci.org/iambumblehead/esmock.svg?branch=master)](https://travis-ci.org/iambumblehead/esmock) | ||
This package **must be used with node's experimental --loader,** | ||
``` bash | ||
ava --node-arguments="--loader=esmock" | ||
mocha --loader=esmock | ||
``` | ||
Add the command to your package.json, | ||
``` json | ||
{ | ||
"name": "my-module", | ||
"type": "module", | ||
"scripts" : { | ||
"unit-test": "ava --node-arguments=\"--loader=esmock\"" | ||
} | ||
} | ||
``` | ||
And use it | ||
``` javascript | ||
@@ -25,2 +47,8 @@ import test from 'ava'; | ||
### changelog | ||
* 0.1.0 _Apr.10.2021_ | ||
* adds support for native es modules | ||
[0]: http://www.bumblehead.com "bumblehead" |
@@ -1,3 +0,1 @@ | ||
import { Mutex } from 'async-mutex'; | ||
import { | ||
@@ -9,26 +7,17 @@ esmockPathCallee | ||
esmockAddMocked, | ||
esmockImportedModulePurge, | ||
esmockImportedModuleSanitize | ||
} from './esmockModule.js'; | ||
import { | ||
esmockCachePurge | ||
} from './esmockCache.js'; | ||
const mutex = new Mutex(); | ||
const esmock = async (modulePath, mockDefs = {}) => { | ||
export default async (modulePath, mockDefs = {}) => { | ||
const calleePath = esmockPathCallee(); | ||
const modulePathKey = await esmockAddMocked( | ||
calleePath, modulePath, mockDefs); | ||
return await mutex.runExclusive(async () => { | ||
const modulePathKey = esmockAddMocked( | ||
calleePath, modulePath, mockDefs, esmockCachePurge); | ||
const importedModule = await import(modulePathKey); | ||
// if any modules exist in module._cache when import occurs, | ||
// they are returned regardless of what occurs in module._load | ||
const importedModule = await import(modulePathKey); | ||
return esmockImportedModuleSanitize(importedModule); | ||
}); | ||
esmockImportedModulePurge(modulePathKey); | ||
// return importedModule; | ||
return esmockImportedModuleSanitize(importedModule); | ||
}; | ||
export default esmock; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19326
1
5
16
466
53
Yes
1
1
+ Addedresolvewithplus@0.2.0(transitive)
- Removedasync-mutex@^0.2.6
- Removedasync-mutex@0.2.6(transitive)
- Removedresolvewithplus@0.1.2(transitive)
- Removedtslib@2.8.1(transitive)
Updatedresolvewithplus@^0.2.0