Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

esmock

Package Overview
Dependencies
Maintainers
1
Versions
107
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

esmock - npm Package Compare versions

Comparing version 0.0.1 to 0.1.0

.eslintrc.json

27

package.json
{
"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;
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc