Skip to content

Releases: jespertheend/fake-imports

v0.3.0

28 Mar 20:32
Compare
Choose a tag to compare
v0.3.0 Pre-release
Pre-release

Better error messages when a network error occurs

When an import fails, previously Deno would only show a generic message that made it difficult to pin down which request failed exactly.
If your script imports from a non existent file on disk for example, it would show

error: Uncaught (in promise) TypeError: NetworkError when attempting to fetch resource.

In this update, the dynamic import() will reject with an error that contains the url that caused the import to fail.
This way it is also possible to catch the promise, whereas previously it would throw the error from async code which was uncatchable.

BREAKING: Importing a resource that responds with a non-ok status code throws.

Previously the importer would create a blob from any import, regardless of it's status code. This would likely already cause syntax errors since it is pretty rare for pages with 404 errors to respond with valid JavaScript, but after this update the status code is actually checked, and the dynamic import is rejected in a similar fashion as with failing disk imports.

New redirectModule() method

You can now directly point a module to another file. This is useful if you wish to replace the content of a file with another file, while maintaining the relative import paths from the new file content.

For example, say you have the following files:

// /foo.js
import {bar} from "./bar.js";

// /long/path/to/fakeFoo.js
import {fakeBar} from "./fakeBar.js";

You can point /foo.js to the new path using

importer.redirectModule("/foo.js", "/long/path/to/fakeFoo.js");

Any imports that your fakeFoo.js file contains will remain relative to /long/path/to/, so the fakeBar.js import won't fail in this case.

v0.2.0

22 Mar 23:44
Compare
Choose a tag to compare
v0.2.0 Pre-release
Pre-release

Better error handling for circular imports

While it is not possible to add support for circular imports (see the caveats section in the readme), this update adds better error messages when circular imports occur.

Previously if you tried to import a file that would result in circular imports, the import promise would remain pending forever. This behaviour was difficult to debug because you're not sure where the circular imports are occurring. When using this in Deno tests this would even result in the rather unhelpful message:

error: Promise resolution is still pending but the event loop has already resolved.

Now imports reject immediately once a circular import is detected and it shows the import path that resulted in a circular import:

Error: Circular imports are not supported:
fileA.js -> fileB.js -> fileA.js

Now you can easily remove the circular import from your actual code, or you can fake the imported module and remove the circular import that way.

BREAKING: Generating coverage maps require a new option

Previously coverage maps would always be generated. But this is a pretty expensive operation. So if you're not collecting coverage data, importing large modules was unnecessarily slow. That's why collecting coverage data via the api is now opt-in. When creating a new importer, specify that you want to generate a coverage map with generateCoverageMap: true like so:

const importer = new Importer(import.meta.url, {
  generateCoverageMap: true,
});

Enabling coverage map generation using the --fi-coverage-map flag still enables coverage map generation regardless of the generateCoverageMap option.

v0.1.1

19 Feb 22:46
Compare
Choose a tag to compare
v0.1.1 Pre-release
Pre-release

This release fixes an issue where imports inside comments would get fetched as well.
Import statements inside comments are now ignored.

v0.1.0

30 Jan 14:51
Compare
Choose a tag to compare
v0.1.0 Pre-release
Pre-release

This release adds support for modifying coverage data from Deno so that it matches that of your real files.
You can generate coverage maps via --fi-coverage-map on the command line, or use the api:

const importer = new Importer(import.meta.url);
importer.onCoverageMapEntryAdded((entry) => {
  // do stuff with entry here
});
// or after importing your modules:
const coverageMap = importer.getCoverageMap();

Learn all about it in the readme.

v0.0.6

16 Jan 23:41
Compare
Choose a tag to compare
v0.0.6 Pre-release
Pre-release
  • fakeModule() now takes hooks, this allows you to get the original content of a file and make modifications to it.
importer.fakeModule("./original.js", (original) => {
  return original.fullContent.replace("foo", "bar");
});

v0.0.5

24 Dec 16:34
Compare
Choose a tag to compare
v0.0.5 Pre-release
Pre-release
Add some documentation to the main class

v0.0.4

24 Dec 15:25
Compare
Choose a tag to compare
v0.0.4 Pre-release
Pre-release
Format

v0.0.3

24 Dec 15:23
Compare
Choose a tag to compare
v0.0.3 Pre-release
Pre-release
Add readme

v0.0.2

24 Dec 13:58
Compare
Choose a tag to compare
v0.0.2 Pre-release
Pre-release
Add readme

v0.0.1

24 Dec 12:56
Compare
Choose a tag to compare
v0.0.1 Pre-release
Pre-release
Add basic integration test