Skip to content

Commit

Permalink
[Tests] no-unresolved: add tests for import()
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbonnet authored and ljharb committed Mar 24, 2021
1 parent 96ed3c7 commit ad2a619
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
- [Docs] [`no-named-as-default`]: add semicolon ([#1897], thanks [@bicstone])
- [Docs] `no-extraneous-dependencies`: correct peerDependencies option default to `true` ([#1993], thanks [@dwardu])
- [Docs] `order`: Document options required to match ordering example ([#1992], thanks [@silviogutierrez])
- [Tests] `no-unresolved`: add tests for `import()` ([#2012], thanks [@davidbonnet])

## [2.22.1] - 2020-09-27
### Fixed
Expand Down Expand Up @@ -769,6 +770,7 @@ for info on changes for earlier releases.
[#2026]: https://github.com/benmosher/eslint-plugin-import/pull/2026
[#2022]: https://github.com/benmosher/eslint-plugin-import/pull/2022
[#2021]: https://github.com/benmosher/eslint-plugin-import/pull/2021
[#2012]: https://github.com/benmosher/eslint-plugin-import/pull/2012
[#1997]: https://github.com/benmosher/eslint-plugin-import/pull/1997
[#1993]: https://github.com/benmosher/eslint-plugin-import/pull/1993
[#1985]: https://github.com/benmosher/eslint-plugin-import/pull/1985
Expand Down Expand Up @@ -1360,3 +1362,4 @@ for info on changes for earlier releases.
[@lilling]: https://github.com/lilling
[@silviogutierrez]: https://github.com/silviogutierrez
[@aladdin-add]: https://github.com/aladdin-add
[@davidbonnet]: https://github.com/davidbonnet
30 changes: 23 additions & 7 deletions tests/src/rules/no-unresolved.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function runResolverTests(resolver) {
}

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

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

// check with eslint parser
testVersion('>= 7', () => rest({
code: "import('fs');",
parserOptions: { ecmaVersion: 2021 },
})) || [],

rest({ code: 'import * as foo from "a"' }),

rest({ code: 'export { foo } from "./bar"' }),
Expand Down Expand Up @@ -83,9 +89,9 @@ function runResolverTests(resolver) {
options: [{ commonjs: true }] }),
rest({ code: 'require(foo)',
options: [{ commonjs: true }] }),
],
),

invalid: [
invalid: [].concat(
rest({
code: 'import reallyfake from "./reallyfake/module"',
settings: { 'import/ignore': ['^\\./fake/'] },
Expand Down Expand Up @@ -117,9 +123,9 @@ function runResolverTests(resolver) {
}] }),
rest({
code: "import('in-alternate-root').then(function({DEEP}){});",
errors: [{ message: 'Unable to resolve path to ' +
"module 'in-alternate-root'.",
type: 'Literal',
errors: [{
message: 'Unable to resolve path to module \'in-alternate-root\'.',
type: 'Literal',
}],
parser: require.resolve('babel-eslint') }),

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

// check with eslint parser
testVersion('>= 7', () => rest({
code: "import('in-alternate-root').then(function({DEEP}){});",
errors: [{
message: 'Unable to resolve path to module \'in-alternate-root\'.',
type: 'Literal',
}],
parserOptions: { ecmaVersion: 2021 },
})) || [],

// export symmetry proposal
rest({ code: 'export * as bar from "./does-not-exist"',
parser: require.resolve('babel-eslint'),
Expand Down Expand Up @@ -186,7 +202,7 @@ function runResolverTests(resolver) {
type: 'Literal',
}],
}),
],
),
});

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

0 comments on commit ad2a619

Please sign in to comment.