JSPM

  • Created
  • Published
  • Downloads 34447
  • Score
    100M100P100Q155633F
  • License MIT

esmock

Package Exports

  • esmock

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (esmock) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

esmock

(c)Bumblehead

npm version Build Status

This package must be used with node's experimental --loader,

ava --node-arguments="--loader=esmock"
mocha --loader=esmock

Add the command to your package.json,

{
  "name": "my-module",
  "type": "module",
  "scripts" : {
    "unit-test": "ava --node-arguments=\"--loader=esmock\""
  }
}

And use it

import test from 'ava';
import esmock from 'esmock';

test('should mock module and local file at the same time', async t => {
  const main = await esmock('./local/main.js', {
    'astringifierpackage' : o => JSON.stringify(o),
    './local/util.js' : {
      exportedFunction : () => 'foobar'
    }
  });

  t.is(main(), 'foobar, ' + JSON.stringify({ test: 'object' }));
});

changelog

  • 0.1.0 Apr.10.2021
    • adds support for native es modules