diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 88c28765..f4cf4a13 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -1,6 +1,3 @@ -# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node -# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions - name: coverage on: diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index d8fb5d80..2157b7f6 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -1,6 +1,3 @@ -# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created -# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages - name: npm package on: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 41ee3d40..dcc8a502 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,6 +1,3 @@ -# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node -# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions - name: tests on: diff --git a/CHANGELOG.md b/CHANGELOG.md index 82fb563f..8d51cfce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,8 @@ # changelog - * tbd + * 2.3.7 _Aug.11.2023_ * [normalize package.json url](https://github.com/iambumblehead/esmock/pull/225) and [reduce loc for loader verification](https://github.com/iambumblehead/esmock/pull/226) + * [small adjustments](https://github.com/iambumblehead/esmock/pull/228) reducing lines of code * 2.3.6 _Aug.07.2023_ * [resolve global mocking issues](https://github.com/iambumblehead/esmock/pull/224) when using mixed esm cjs import trees * 2.3.4 _Jul.30.2023_ diff --git a/src/esmockErr.js b/src/esmockErr.js index a43a590c..7ba66ac2 100644 --- a/src/esmockErr.js +++ b/src/esmockErr.js @@ -9,7 +9,7 @@ const errMissingLoader = () => + 'start the process using --loader=esmock.') const errModuleIdNoDefs = (moduleId, parent) => - new Error(`no mocks provided for module: "${moduleId}" (used by ${parent}`) + new Error(`no mocks provided for module: "${moduleId}" (used by ${parent})`) export default { errModuleIdNotFound, diff --git a/src/esmockIsLoader.js b/src/esmockIsLoader.js index 3aa07def..c4175b03 100644 --- a/src/esmockIsLoader.js +++ b/src/esmockIsLoader.js @@ -1,4 +1,3 @@ import { loaderIsVerified } from './esmockLoader.js' -export default (c => async () => - (c = c || loaderIsVerified(import.meta.url)))() +export default (c => () => (c = c || loaderIsVerified(import.meta.url)))() diff --git a/src/esmockModule.js b/src/esmockModule.js index 53e87e9a..1e863c99 100644 --- a/src/esmockModule.js +++ b/src/esmockModule.js @@ -17,7 +17,8 @@ const isDefaultIn = o => isObj(o) && 'default' in o const isDirPathRe = /^\.?\.?([a-zA-Z]:)?(\/|\\)/ const isMetaResolve = typeof import.meta.resolve === 'function' const nextId = ((id = 0) => () => ++id)() -const asFileURL = p => p.startsWith('file://') ? p : url.pathToFileURL(p) +const fileurlre = /^file:\/\// +const asFileURL = p => fileurlre.test(p) ? p : url.pathToFileURL(p) const objProto = Object.getPrototypeOf({}) const isPlainObj = o => Object.getPrototypeOf(o) === objProto @@ -147,9 +148,8 @@ const esmockModule = async (moduleId, parent, defs, gdefs, opt) => { const gkeys = gdefs ? Object.keys(gdefs) : [] const dkeys = defs ? Object.keys(defs) : [] - if (opt.strict === 3 && !gkeys.length && !dkeys.length) { + if (opt.strict === 3 && !gkeys.length && !dkeys.length) throw esmockErr.errModuleIdNoDefs(moduleId, parent) - } const treeid = typeof opt.id === 'number' ? opt.id : nextId() const treeidspec = `${moduleFileURL}?key=${treeid}&strict=${opt.strict}?` + [