Skip to content

Commit

Permalink
update readme. add node 16.x to test
Browse files Browse the repository at this point in the history
  • Loading branch information
bumblehead committed May 8, 2021
1 parent a320ff6 commit dd2f470
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

strategy:
matrix:
node-version: [12.x, 14.x, 15.x]
node-version: [12.x, 14.x, 16.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
Expand Down
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ esmock
"type": "module",
"scripts": {
"test-ava": "ava --node-arguments=\"--loader=esmock\"",
"test-mocha": "mocha --loader=esmock"
"test-mocha": "mocha --loader=esmock --no-warnings"
}
}
```
Expand Down Expand Up @@ -43,11 +43,33 @@ test('should do global instance mocks —third parameter', async t => {

t.is(getFile(), 'anywhere the instance uses fs readFileSync');
});

test('some mock definitions need a "default" namespace', async t => {
const { hello } = await esmock('../src/main.js', {}, {
'../src/hello.js' : {
default : {
world: () => 'world'
}
}
});

t.is(hello(), 'world');
});
```


### notes

Use `--loader=esmock --no-warnings` to suppress node's warning messages.

If your mock definition isn't appearing in tests, try nesting it inside a default definition.


### changelog

* 0.3.9 _May.05.2021_
* small change to README
* added a test, update gitlab action to use node 16.x
* 0.3.8 _Apr.21.2021_
* small change to README
* 0.3.7 _Apr.20.2021_
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "esmock",
"version": "0.3.8",
"version": "0.3.9",
"license": "MIT",
"readmeFilename": "README.md",
"description": "mock esm modules for unit-tests",
Expand Down
10 changes: 10 additions & 0 deletions spec/esmock.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,16 @@ test('should mock an mjs file, again', async t => {
t.is(main.verifyImportedMock(), 'second mocked');
});

test('should mock an exported constant values', async t => {
const main = await esmock('./local/usesmjsModule.js', {
'./local/env.js' : {
TESTCONSTANT : 'hello world'
}
});

t.is(main.verifyImportedConstant(), 'hello world');
});

test('should mock core module', async t => {
const usesCoreModule = await esmock('./local/usesCoreModule.js', {
fs : {
Expand Down
2 changes: 2 additions & 0 deletions spec/local/env.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

export const TESTCONSTANT = 'TESTCONSTANTVALUE';
5 changes: 5 additions & 0 deletions spec/local/usesmjsModule.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import scheduleFunction from './exampleMJS.mjs';
import { TESTCONSTANT } from './env.js';

export function verifyImportedMock () {
return scheduleFunction();
}

export function verifyImportedConstant () {
return TESTCONSTANT;
}

0 comments on commit dd2f470

Please sign in to comment.