Skip to content

Commit

Permalink
Add tests for import assertions
Browse files Browse the repository at this point in the history
Closes #90. I thought new code was needed to support them, but it turns
out no changes were needed.
  • Loading branch information
lydell committed Mar 26, 2022
1 parent 80a8e61 commit e0b3e26
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 1 deletion.
5 changes: 4 additions & 1 deletion babel.config.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"plugins": ["@babel/plugin-transform-flow-strip-types"]
"plugins": [
"@babel/plugin-syntax-import-assertions",
"@babel/plugin-transform-flow-strip-types"
]
}
25 changes: 25 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
},
"devDependencies": {
"@babel/eslint-parser": "7.17.0",
"@babel/plugin-syntax-import-assertions": "7.16.7",
"@babel/plugin-transform-flow-strip-types": "7.16.7",
"@typescript-eslint/parser": "5.16.0",
"eslint": "8.12.0",
Expand Down
56 changes: 56 additions & 0 deletions test/imports.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1576,6 +1576,7 @@ const flowTests = {
`import type a, {b} from "a"`,
`import type {} from "a"`,
`import type { } from "a"`,
`import json from "./foo.json" assert { type: "json" };`,

// typeof
`import typeof a from "a"`,
Expand Down Expand Up @@ -1672,6 +1673,33 @@ const flowTests = {
errors: 1,
},

// Import assertions.
{
code: input`
|import json from "./foo.json" assert { type: "json" };
|import {b, a} from "./bar.json" assert {
| // json
| type: "json",
| a: "b",
|} /* bar */ /* end
| comment */
|;[].forEach()
`,
output: (actual) => {
expect(actual).toMatchInlineSnapshot(`
|import {a,b} from "./bar.json" assert {
| // json
| type: "json",
| a: "b",
|} /* bar */
|import json from "./foo.json" assert { type: "json" };/* end
| comment */
|;[].forEach()
`);
},
errors: 1,
},

// https://github.com/graphql/graphql-js/blob/64b194c6c9b9aaa1c139f1b7c3692a6ef851928e/src/execution/execute.js#L10-L69
{
code: input`
Expand Down Expand Up @@ -1812,6 +1840,7 @@ const typescriptTests = {
`import type {a} from "a"`,
`import type {} from "a"`,
`import type { } from "a"`,
`import json from "./foo.json" assert { type: "json" };`,

// type specifiers.
`import { type b, type c, a } from "a"`,
Expand Down Expand Up @@ -1939,6 +1968,33 @@ const typescriptTests = {
},
errors: 1,
},

// Import assertions.
{
code: input`
|import json from "./foo.json" assert { type: "json" };
|import {b, a} from "./bar.json" assert {
| // json
| type: "json",
| a: "b",
|} /* bar */ /* end
| comment */
|;[].forEach()
`,
output: (actual) => {
expect(actual).toMatchInlineSnapshot(`
|import {a,b} from "./bar.json" assert {
| // json
| type: "json",
| a: "b",
|} /* bar */
|import json from "./foo.json" assert { type: "json" };/* end
| comment */
|;[].forEach()
`);
},
errors: 1,
},
],
};

Expand Down

0 comments on commit e0b3e26

Please sign in to comment.