Skip to content

Instantly share code, notes, and snippets.

@benquarmby
Last active February 4, 2025 23:55
Show Gist options
  • Save benquarmby/84e249f679d895000b17973063b5d1b6 to your computer and use it in GitHub Desktop.
Save benquarmby/84e249f679d895000b17973063b5d1b6 to your computer and use it in GitHub Desktop.
Jest ESM named import repro
import {quote, parse} from "shell-quote";
export function quoteSample() {
return quote(["a", "b c d", "$f", "\"g\""]);
}
export function parseSample() {
return parse("a \"b c\" \\$def 'it\\'s great'");
}
import {quoteSample, parseSample} from "./index.js";
describe("jest with ESM", function () {
it("should quote the sample correctly", function () {
expect(quoteSample()).toBe("a 'b c d' \\$f '\"g\"'");
});
it("should parse the sample correctly", function () {
expect(parseSample()).toEqual(["a", "b c", "$def", "it\\s great"]);
});
});
import {quoteSample, parseSample} from "./index.js";
function main() {
const mode = process.argv[2];
if (mode === "parse") {
console.log(parseSample());
return;
}
console.log(quoteSample());
}
main();
{
"name": "jest-esm-repro",
"version": "1.0.0",
"private": true,
"license": "UNLICENSED",
"type": "module",
"scripts": {
"parse": "node ./main.js parse",
"quote": "node ./main.js quote",
"test": "NODE_OPTIONS=--experimental-vm-modules jest"
},
"dependencies": {
"shell-quote": "^1.8.2"
},
"devDependencies": {
"jest": "^29.7.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment