Skip to content

Commit 0415007

Browse files
authored
Merge pull request webpack#17230 from webpack/test-support-with-json
test: added `with { type: "json" }`
2 parents aeb1912 + 456a811 commit 0415007

File tree

6 files changed

+35
-5
lines changed

6 files changed

+35
-5
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"@webassemblyjs/wasm-edit": "^1.11.5",
1212
"@webassemblyjs/wasm-parser": "^1.11.5",
1313
"acorn": "^8.7.1",
14-
"acorn-import-assertions": "^1.7.6",
14+
"acorn-import-assertions": "^1.9.0",
1515
"browserslist": "^4.14.5",
1616
"chrome-trace-event": "^1.0.2",
1717
"enhanced-resolve": "^5.14.0",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = [
2+
[{ moduleName: /data.poison/, message: /Unexpected token .+ JSON/ }]
3+
];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import poison from "../data/poison" with { type: "json" };
2+
3+
export default poison;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import c from "../data/c.json" with { type: "json" };
2+
import unknownJson from "../data/unknown" with { type: "json" };
3+
import unknownJs from "../data/unknown";
4+
5+
it("should be possible to import json data with import assertion", function () {
6+
expect(c).toEqual([1, 2, 3, 4]);
7+
});
8+
9+
it("should be possible to import json data without extension with import assertion", function () {
10+
expect(unknownJson).toEqual([1, 2, 3, 4]);
11+
});
12+
13+
it("should be possible to import js without extension without import assertion in the same file", function () {
14+
expect(unknownJs).toEqual({});
15+
});
16+
17+
it("should not be possible to import js with import assertion", function () {
18+
expect(() => {
19+
require("./import-poison.js");
20+
}).toThrowError();
21+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = [
2+
/^Pack got invalid because of write to: Compilation\/modules|json.+json\/data\/poison$/
3+
];

yarn.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -1406,10 +1406,10 @@ abbrev@1.0.x:
14061406
resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.0.9.tgz#91b4792588a7738c25f35dd6f63752a2f8776135"
14071407
integrity sha512-LEyx4aLEC3x6T0UguF6YILf+ntvmOaWsVfENmIW0E9H09vKlLDGelMjjSm0jkDHALj8A8quZ/HapKNigzwge+Q==
14081408

1409-
acorn-import-assertions@^1.7.6:
1410-
version "1.8.0"
1411-
resolved "https://registry.yarnpkg.com/acorn-import-assertions/-/acorn-import-assertions-1.8.0.tgz#ba2b5939ce62c238db6d93d81c9b111b29b855e9"
1412-
integrity sha512-m7VZ3jwz4eK6A4Vtt8Ew1/mNbP24u0FhdyfA7fSvnJR6LMdfOYnmuIrrJAgrYfYJ10F/otaHTtrtrtmHdMNzEw==
1409+
acorn-import-assertions@^1.9.0:
1410+
version "1.9.0"
1411+
resolved "https://registry.yarnpkg.com/acorn-import-assertions/-/acorn-import-assertions-1.9.0.tgz#507276249d684797c84e0734ef84860334cfb1ac"
1412+
integrity sha512-cmMwop9x+8KFhxvKrKfPYmN6/pKTYYHBqLa0DfvVZcKMJWNyWLnaqND7dx/qn66R7ewM1UX5XMaDVP5wlVTaVA==
14131413

14141414
acorn-jsx@^5.3.2:
14151415
version "5.3.2"

0 commit comments

Comments
 (0)