Skip to content

Commit

Permalink
Merge pull request #10 from iambumblehead/exported-constants-redefine
Browse files Browse the repository at this point in the history
update readme. add node 16.x to test
  • Loading branch information
iambumblehead authored May 8, 2021
2 parents a320ff6 + 315635f commit e3b3dbd
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 4 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
10 changes: 8 additions & 2 deletions 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 All @@ -24,12 +24,15 @@ import esmock from 'esmock';
test('should mock modules and local files at same time', async t => {
const main = await esmock('../src/main.js', {
stringifierpackage : o => JSON.stringify(o),
'../src/hello.js' : {
default : () => 'world'
},
'../src/util.js' : {
exportedFunction : () => 'foobar'
}
});

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

test('should do global instance mocks —third parameter', async t => {
Expand All @@ -48,6 +51,9 @@ test('should do global instance mocks —third parameter', async t => {

### 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 e3b3dbd

Please sign in to comment.