diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 6a4505a5..6c460186 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -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: diff --git a/README.md b/README.md index e7a7e768..8e158cfb 100644 --- a/README.md +++ b/README.md @@ -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" } } ``` @@ -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 => { @@ -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_ diff --git a/package.json b/package.json index ee57a32e..e98d4472 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/spec/esmock.spec.js b/spec/esmock.spec.js index db0ab1bd..2988cbd4 100644 --- a/spec/esmock.spec.js +++ b/spec/esmock.spec.js @@ -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 : { diff --git a/spec/local/env.js b/spec/local/env.js new file mode 100644 index 00000000..67caa0cc --- /dev/null +++ b/spec/local/env.js @@ -0,0 +1,2 @@ + +export const TESTCONSTANT = 'TESTCONSTANTVALUE'; diff --git a/spec/local/usesmjsModule.js b/spec/local/usesmjsModule.js index 18b3bd91..2caba241 100644 --- a/spec/local/usesmjsModule.js +++ b/spec/local/usesmjsModule.js @@ -1,5 +1,10 @@ import scheduleFunction from './exampleMJS.mjs'; +import { TESTCONSTANT } from './env.js'; export function verifyImportedMock () { return scheduleFunction(); } + +export function verifyImportedConstant () { + return TESTCONSTANT; +}