jest icon indicating copy to clipboard operation
jest copied to clipboard

[Feature]: Allow esm https network imports

Open Pyrolistical opened this issue 3 years ago • 3 comments

🚀 Feature Proposal

Add https: support for esm imports.

Motivation

Experimental esm https network imports was added in node.js v17 https://nodejs.org/api/esm.html#https-and-http-imports

It is currently behind a --experimental-network-imports flag.

Code using this feature is not testable as of Jest v28.1.0.

Example

The following is not testable using Jest, but can be run in node.js with --experimental-network-imports

import capitalize from "https://cdn.skypack.dev/pin/[email protected]/mode=imports/unoptimized/capitalize.js";

console.log(
  capitalize(
    "this string should be capitalized using an https import of lodash.capitalize"
  )
);

Pitch

ESM imports is core functionality in node.js and https: imports just another feature of it.

Jest should support https: imports as tools like deno and vite are popularizing using esm https imports directly.

Implementing this feature should be fairly simple by adding another case to: https://github.com/facebook/jest/blob/811228d6ae73a6563a98b0ee36b73f453e644f2f/packages/jest-runtime/src/index.ts#L543

Pyrolistical avatar Jun 01 '22 20:06 Pyrolistical

For those already using vite and esm https imports, you can use deno test as a workaround. Deno natively supports esm https imports, so the test runner would as well.

Pyrolistical avatar Jun 02 '22 04:06 Pyrolistical

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

github-actions[bot] avatar Jul 02 '22 05:07 github-actions[bot]

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

github-actions[bot] avatar Aug 14 '22 13:08 github-actions[bot]