test: added `with { type: "json" }`

This commit is contained in:
alexander.akait 2023-05-19 20:26:55 +03:00
parent fe20b525d4
commit 456a8119f7
6 changed files with 35 additions and 5 deletions

View File

@ -11,7 +11,7 @@
"@webassemblyjs/wasm-edit": "^1.11.5",
"@webassemblyjs/wasm-parser": "^1.11.5",
"acorn": "^8.7.1",
"acorn-import-assertions": "^1.7.6",
"acorn-import-assertions": "^1.9.0",
"browserslist": "^4.14.5",
"chrome-trace-event": "^1.0.2",
"enhanced-resolve": "^5.14.0",

View File

@ -0,0 +1,3 @@
module.exports = [
[{ moduleName: /data.poison/, message: /Unexpected token .+ JSON/ }]
];

View File

@ -0,0 +1,3 @@
import poison from "../data/poison" with { type: "json" };
export default poison;

View File

@ -0,0 +1,21 @@
import c from "../data/c.json" with { type: "json" };
import unknownJson from "../data/unknown" with { type: "json" };
import unknownJs from "../data/unknown";
it("should be possible to import json data with import assertion", function () {
expect(c).toEqual([1, 2, 3, 4]);
});
it("should be possible to import json data without extension with import assertion", function () {
expect(unknownJson).toEqual([1, 2, 3, 4]);
});
it("should be possible to import js without extension without import assertion in the same file", function () {
expect(unknownJs).toEqual({});
});
it("should not be possible to import js with import assertion", function () {
expect(() => {
require("./import-poison.js");
}).toThrowError();
});

View File

@ -0,0 +1,3 @@
module.exports = [
/^Pack got invalid because of write to: Compilation\/modules|json.+json\/data\/poison$/
];

View File

@ -1406,10 +1406,10 @@ abbrev@1.0.x:
resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.0.9.tgz#91b4792588a7738c25f35dd6f63752a2f8776135"
integrity sha512-LEyx4aLEC3x6T0UguF6YILf+ntvmOaWsVfENmIW0E9H09vKlLDGelMjjSm0jkDHALj8A8quZ/HapKNigzwge+Q==
acorn-import-assertions@^1.7.6:
version "1.8.0"
resolved "https://registry.yarnpkg.com/acorn-import-assertions/-/acorn-import-assertions-1.8.0.tgz#ba2b5939ce62c238db6d93d81c9b111b29b855e9"
integrity sha512-m7VZ3jwz4eK6A4Vtt8Ew1/mNbP24u0FhdyfA7fSvnJR6LMdfOYnmuIrrJAgrYfYJ10F/otaHTtrtrtmHdMNzEw==
acorn-import-assertions@^1.9.0:
version "1.9.0"
resolved "https://registry.yarnpkg.com/acorn-import-assertions/-/acorn-import-assertions-1.9.0.tgz#507276249d684797c84e0734ef84860334cfb1ac"
integrity sha512-cmMwop9x+8KFhxvKrKfPYmN6/pKTYYHBqLa0DfvVZcKMJWNyWLnaqND7dx/qn66R7ewM1UX5XMaDVP5wlVTaVA==
acorn-jsx@^5.3.2:
version "5.3.2"