Last active
February 4, 2025 23:55
-
-
Save benquarmby/84e249f679d895000b17973063b5d1b6 to your computer and use it in GitHub Desktop.
Jest ESM named import repro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22.11.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"]); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {quoteSample, parseSample} from "./index.js"; | |
function main() { | |
const mode = process.argv[2]; | |
if (mode === "parse") { | |
console.log(parseSample()); | |
return; | |
} | |
console.log(quoteSample()); | |
} | |
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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