Skip to content

Commit 9d4a107

Browse files
davidbonnetljharb
authored andcommitted
[Tests] no-unresolved: add tests for import()
1 parent 96ed3c7 commit 9d4a107

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

Diff for: CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
3636
- [Docs] [`no-named-as-default`]: add semicolon ([#1897], thanks [@bicstone])
3737
- [Docs] `no-extraneous-dependencies`: correct peerDependencies option default to `true` ([#1993], thanks [@dwardu])
3838
- [Docs] `order`: Document options required to match ordering example ([#1992], thanks [@silviogutierrez])
39+
- [Tests] `no-unresolved`: add tests for `import()` ([#2012], thanks [@davidbonnet])
3940

4041
## [2.22.1] - 2020-09-27
4142
### Fixed
@@ -769,6 +770,7 @@ for info on changes for earlier releases.
769770
[#2026]: https://github.com/benmosher/eslint-plugin-import/pull/2026
770771
[#2022]: https://github.com/benmosher/eslint-plugin-import/pull/2022
771772
[#2021]: https://github.com/benmosher/eslint-plugin-import/pull/2021
773+
[#2012]: https://github.com/benmosher/eslint-plugin-import/pull/2012
772774
[#1997]: https://github.com/benmosher/eslint-plugin-import/pull/1997
773775
[#1993]: https://github.com/benmosher/eslint-plugin-import/pull/1993
774776
[#1985]: https://github.com/benmosher/eslint-plugin-import/pull/1985
@@ -1360,3 +1362,4 @@ for info on changes for earlier releases.
13601362
[@lilling]: https://github.com/lilling
13611363
[@silviogutierrez]: https://github.com/silviogutierrez
13621364
[@aladdin-add]: https://github.com/aladdin-add
1365+
[@davidbonnet]: https://github.com/davidbonnet

Diff for: tests/src/rules/no-unresolved.js

+23-7
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function runResolverTests(resolver) {
2222
}
2323

2424
ruleTester.run(`no-unresolved (${resolver})`, rule, {
25-
valid: [
25+
valid: [].concat(
2626
test({ code: 'import "./malformed.js"' }),
2727

2828
rest({ code: 'import foo from "./bar";' }),
@@ -32,6 +32,12 @@ function runResolverTests(resolver) {
3232
rest({ code: "import('fs');",
3333
parser: require.resolve('babel-eslint') }),
3434

35+
// check with eslint parser
36+
testVersion('>= 6', () => rest({
37+
code: "import('fs');",
38+
parserOptions: { ecmaVersion: 2021 },
39+
})) || [],
40+
3541
rest({ code: 'import * as foo from "a"' }),
3642

3743
rest({ code: 'export { foo } from "./bar"' }),
@@ -83,9 +89,9 @@ function runResolverTests(resolver) {
8389
options: [{ commonjs: true }] }),
8490
rest({ code: 'require(foo)',
8591
options: [{ commonjs: true }] }),
86-
],
92+
),
8793

88-
invalid: [
94+
invalid: [].concat(
8995
rest({
9096
code: 'import reallyfake from "./reallyfake/module"',
9197
settings: { 'import/ignore': ['^\\./fake/'] },
@@ -117,9 +123,9 @@ function runResolverTests(resolver) {
117123
}] }),
118124
rest({
119125
code: "import('in-alternate-root').then(function({DEEP}){});",
120-
errors: [{ message: 'Unable to resolve path to ' +
121-
"module 'in-alternate-root'.",
122-
type: 'Literal',
126+
errors: [{
127+
message: 'Unable to resolve path to module \'in-alternate-root\'.',
128+
type: 'Literal',
123129
}],
124130
parser: require.resolve('babel-eslint') }),
125131

@@ -130,6 +136,16 @@ function runResolverTests(resolver) {
130136
errors: ["Unable to resolve path to module './does-not-exist'."],
131137
}),
132138

139+
// check with eslint parser
140+
testVersion('>= 6', () => rest({
141+
code: "import('in-alternate-root').then(function({DEEP}){});",
142+
errors: [{
143+
message: 'Unable to resolve path to module \'in-alternate-root\'.',
144+
type: 'Literal',
145+
}],
146+
parserOptions: { ecmaVersion: 2021 },
147+
})) || [],
148+
133149
// export symmetry proposal
134150
rest({ code: 'export * as bar from "./does-not-exist"',
135151
parser: require.resolve('babel-eslint'),
@@ -186,7 +202,7 @@ function runResolverTests(resolver) {
186202
type: 'Literal',
187203
}],
188204
}),
189-
],
205+
),
190206
});
191207

192208
ruleTester.run(`issue #333 (${resolver})`, rule, {

0 commit comments

Comments
 (0)