Releases: iambumblehead/esmock
huge esmock.d.ts upgrade
This release dramatically improves the esmock.d.ts file, thanks to @jsejcksn,
- huge simplifications to typescript types file, much smaller and more readable, credit @jsejcksn
- added ts linting and updated test ts files to pass ts lint rules
- esmock npm package is smaller --only 18.9kB
install size down to 20.3kB
Numerous micro-optimisations in this release,
- Simplified esmock.d.ts file, mostly this was done by reducing documentation and using shorter param names,
- Simplified args normalization and dropped support for
opts.parent
. Affected source files are more readable. - A single regexp replaces multiple regexp-replacements that were used to extract fileURL from an error stack.
- "moduleId" and "parent" params are now used everywhere in the same order, following node's import.meta.resolve eg
fn(moduleId, parent)
- Updated resolvewithplus to the latest version to resolve an issue related to handling of parent fileURL param
- Total install size for esmock is down to 20.3kB (perfect)
add jest using ts test example
This release mostly adds a typescript with jest test example (using jest-light-runner). Thank you for your help here nicolo-ribaudo/jest-light-runner#1 Also, a few simplifications were made and behaviour is unchanged,
- simplifications, slightly reducing install size
- update jest and jest-light-runner versions used in unit-tests
- add jest+ts-node test example, credit @liuxingbaoyu @cspotcode
minor changes, slightly smaller
Low-risk release mostly fixing a json syntax error found in the README,
- uses newer, smaller resolvewithplus, see esmock size here,
- uses a shared "moduleId not found" error message,
- removes lines not covered by tests,
- fixes a README json syntax error, updates the descriptions for some test and renames the internally-used variable
modulePath
tomoduleId
, - removes a few chars from README
use partial mocking by default
This 2.0.0 release includes changes incompatible with previous releases. A migration guide is included just below this small changelog list,
- exports a "strict mocking" version of esmock
- uses "partial mocking" behaviour with default export and updates the readme,
- resolves error when partial mocking modules not found on filesystem
- renames option
isPackageNotFoundError
toisModuleNotFoundError
- see the release announcement for details and
migration guide v1.9.8 => v2.0.0
- change
esmock.px(...args)
toesmock(...args)
. "px" or "partial mocking" behaviour is the default behaviour in the new version - change
{ isPackageNotFoundError: false }
to{ isModuleNotFoundError: false }
this option is renamed to be more accurate - to use "partial mocking" automatically, continue using
esmock(...args)
- to avoid "partial mocking" and to continue using "strict mocking" (explained below), use one of the following changes,
- change
import esmock from 'esmock'
toimport { strict as esmock } from 'esmock'
, or - change
esmock(...args)
toesmock.strict(...args)
- change
The new version of esmock uses "partial mocking" by default which merges mock definitions with original module definitions. Previous versions used "strict mocking", where mock definitions are not modified or merged with original module definitions. Strict mocking is still available through esmock.strict
and import { strict } from 'esmock'
.
To demonstrate the difference, a target module and its usage with esmock,
import p from 'path'
console.log(p.dirname('/dog.png'), p.basename('./dog.png'))
import esmock, { strict } from 'esmock'
esmock('./logpath.js', { path: { basename: () => 'cat.png' } })
// "/ cat.png"
strict('./logpath.js', { path: { basename: () => 'cat.png' } })
// Error "The requested module 'path' does not provide an export named 'dirname'"
Examples of both default and strict mocking use "path" definitions that define "basename" only and not "dirname". The regular, "partial mocking" behaviour merges the mocked "path" definition with the core "path" definition, including "path.dirname". The "strict mocking" behaviour does not modify the mock definition and "dirname" is never defined, resulting in a runtime error.
maintenance and stability updates
This release consolidates many small contributions and changes accumulated over the previous three to four weeks. Some new features are yet to be documented, such as parenturl and isPackageNotFoundError,
- use latest node v18 for ci-tests, a bug in the ava package prevented this
- use latest resolvewithplus and remove many lines of code needed for the older variant
- use one regexp to detect --loader esmock and make unit-testing around this easier
- update the first example in the README to be smaller and more interesting
- support multiple --loader calls, --loader esmock and --loader=esmock. added unit-tests
- update typescript types file to include
parent
andisPackageNotFoundError
options - give credit to @cawa-93 for showing me how to mock specifiers that aren't found in the filesystem
support mocking modules not found in filesystem
support mocking specifiers that aren't found in filesystem re #126,
use isPackageNotFoundError: false
to enable this. For example,
const component = await esmock(`../local/vueComponent.js`, {
vue: { // vue was not downloaded and is not found in the filesystem
h: (...args) => args
}
}, {}, {
isPackageNotFoundError: false
})
the interface for this may change in the near future
much improved support for esm design language patterns
This release greatly improves esmock's parsing of esm design language patterns
- adds support for calling esmock with a parent url param, so that esmock can be used with sourcemaps, credit @jakebailey
- adds support for mocking import subpaths, eg
import: { '#sub': './path.js' }
- drops support for node 12 and remove node 12 ci pipeline
support packages defining package.main dir only, cjs
support cjs packges that define main relative directory only
support node: prefixed core modules
support core modules w/ node: prefix, credit @gmahomarf