Skip to content

Commit

Permalink
Add failing test scenario for import-js#1436
Browse files Browse the repository at this point in the history
  • Loading branch information
schmidsi committed Aug 3, 2019
1 parent ebcf17c commit 34765ab
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 33 deletions.
Empty file.
Empty file.
3 changes: 2 additions & 1 deletion tests/files/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
},
"optionalDependencies": {
"lodash.isarray": "^4.0.0"
}
},
"bundledDependencies": ["@generated/foo"]
}
73 changes: 41 additions & 32 deletions tests/src/rules/no-unresolved.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ function runResolverTests(resolver) {
test({ code: 'import "./malformed.js"' }),

rest({ code: 'import foo from "./bar";' }),
rest({ code: "import bar from './bar.js';" }),
rest({ code: "import {someThing} from './test-module';" }),
rest({ code: "import fs from 'fs';" }),
rest({ code: "import('fs');"
rest({ code: 'import bar from \'./bar.js\';' }),
rest({ code: 'import {someThing} from \'./test-module\';' }),
rest({ code: 'import fs from \'fs\';' }),
rest({ code: 'import(\'fs\');'
, parser: require.resolve('babel-eslint') }),

rest({ code: 'import * as foo from "a"' }),
Expand Down Expand Up @@ -95,66 +95,66 @@ function runResolverTests(resolver) {


rest({
code: "import bar from './baz';",
errors: [{ message: "Unable to resolve path to module './baz'."
code: 'import bar from \'./baz\';',
errors: [{ message: 'Unable to resolve path to module \'./baz\'.'
, type: 'Literal' }],
}),
rest({ code: "import bar from './baz';"
, errors: [{ message: "Unable to resolve path to module './baz'."
rest({ code: 'import bar from \'./baz\';'
, errors: [{ message: 'Unable to resolve path to module \'./baz\'.'
, type: 'Literal',
}] }),
rest({
code: "import bar from './empty-folder';",
errors: [{ message: "Unable to resolve path to module './empty-folder'."
code: 'import bar from \'./empty-folder\';',
errors: [{ message: 'Unable to resolve path to module \'./empty-folder\'.'
, type: 'Literal',
}]}),

// sanity check that this module is _not_ found without proper settings
rest({
code: "import { DEEP } from 'in-alternate-root';",
code: 'import { DEEP } from \'in-alternate-root\';',
errors: [{ message: 'Unable to resolve path to ' +
"module 'in-alternate-root'."
'module \'in-alternate-root\'.'
, type: 'Literal',
}]}),
rest({
code: "import('in-alternate-root').then(function({DEEP}){});",
code: 'import(\'in-alternate-root\').then(function({DEEP}){});',
errors: [{ message: 'Unable to resolve path to ' +
"module 'in-alternate-root'."
'module \'in-alternate-root\'.'
, type: 'Literal',
}],
parser: require.resolve('babel-eslint')}),

rest({ code: 'export { foo } from "./does-not-exist"'
, errors: ["Unable to resolve path to module './does-not-exist'."] }),
, errors: ['Unable to resolve path to module \'./does-not-exist\'.'] }),
rest({
code: 'export * from "./does-not-exist"',
errors: ["Unable to resolve path to module './does-not-exist'."],
errors: ['Unable to resolve path to module \'./does-not-exist\'.'],
}),

// export symmetry proposal
rest({ code: 'export * as bar from "./does-not-exist"'
, parser: require.resolve('babel-eslint')
, errors: ["Unable to resolve path to module './does-not-exist'."],
, errors: ['Unable to resolve path to module \'./does-not-exist\'.'],
}),
rest({ code: 'export bar from "./does-not-exist"'
, parser: require.resolve('babel-eslint')
, errors: ["Unable to resolve path to module './does-not-exist'."],
, errors: ['Unable to resolve path to module \'./does-not-exist\'.'],
}),

// commonjs setting
rest({
code: 'var bar = require("./baz")',
options: [{ commonjs: true }],
errors: [{
message: "Unable to resolve path to module './baz'.",
message: 'Unable to resolve path to module \'./baz\'.',
type: 'Literal',
}],
}),
rest({
code: 'require("./baz")',
options: [{ commonjs: true }],
errors: [{
message: "Unable to resolve path to module './baz'.",
message: 'Unable to resolve path to module \'./baz\'.',
type: 'Literal',
}],
}),
Expand All @@ -164,26 +164,26 @@ function runResolverTests(resolver) {
code: 'require(["./baz"], function (bar) {})',
options: [{ amd: true }],
errors: [{
message: "Unable to resolve path to module './baz'.",
message: 'Unable to resolve path to module \'./baz\'.',
type: 'Literal',
}],
}),
rest({
code: 'define(["./baz"], function (bar) {})',
options: [{ amd: true }],
errors: [{
message: "Unable to resolve path to module './baz'.",
message: 'Unable to resolve path to module \'./baz\'.',
type: 'Literal',
}],
}),
rest({
code: 'define(["./baz", "./bar", "./does-not-exist"], function (bar) {})',
options: [{ amd: true }],
errors: [{
message: "Unable to resolve path to module './baz'.",
message: 'Unable to resolve path to module \'./baz\'.',
type: 'Literal',
},{
message: "Unable to resolve path to module './does-not-exist'.",
message: 'Unable to resolve path to module \'./does-not-exist\'.',
type: 'Literal',
}],
}),
Expand All @@ -206,11 +206,20 @@ function runResolverTests(resolver) {
invalid: [
rest({
code: 'import bar from "./foo.json"',
errors: ["Unable to resolve path to module './foo.json'."],
errors: ['Unable to resolve path to module \'./foo.json\'.'],
}),
],
})

ruleTester.run('issue #1436: bundledDependencies', rule, {
valid: [
rest({ code: 'import foo from "@generated/foo'}),
],
invalid: [
rest({ code: 'import foo from "@generated/bar'}),
],
})

if (!CASE_SENSITIVE_FS) {
ruleTester.run('case sensitivity', rule, {
valid: [
Expand Down Expand Up @@ -241,7 +250,7 @@ function runResolverTests(resolver) {
ruleTester.run('no-unresolved (import/resolve legacy)', rule, {
valid: [
test({
code: "import { DEEP } from 'in-alternate-root';",
code: 'import { DEEP } from \'in-alternate-root\';',
settings: {
'import/resolve': {
'paths': [path.join( process.cwd()
Expand All @@ -251,8 +260,8 @@ ruleTester.run('no-unresolved (import/resolve legacy)', rule, {
}),

test({
code: "import { DEEP } from 'in-alternate-root'; " +
"import { bar } from 'src-bar';",
code: 'import { DEEP } from \'in-alternate-root\'; ' +
'import { bar } from \'src-bar\';',
settings: {'import/resolve': { 'paths': [
path.join('tests', 'files', 'src-root'),
path.join('tests', 'files', 'alternate-root'),
Expand All @@ -267,7 +276,7 @@ ruleTester.run('no-unresolved (import/resolve legacy)', rule, {
invalid: [
test({
code: 'import * as foo from "jsx-module/foo"',
errors: [ "Unable to resolve path to module 'jsx-module/foo'." ],
errors: [ 'Unable to resolve path to module \'jsx-module/foo\'.' ],
}),
],
})
Expand All @@ -292,7 +301,7 @@ ruleTester.run('no-unresolved (webpack-specific)', rule, {
settings: {
'import/resolver': { 'webpack': { 'config': 'webpack.empty.config.js' } },
},
errors: [ "Unable to resolve path to module 'jsx-module/foo'." ],
errors: [ 'Unable to resolve path to module \'jsx-module/foo\'.' ],
}),
],
})
Expand Down Expand Up @@ -324,13 +333,13 @@ ruleTester.run('no-unresolved ignore list', rule, {
test({
code: 'import "./test.gif"',
options: [{ ignore: ['\.png$']}],
errors: [ "Unable to resolve path to module './test.gif'." ],
errors: [ 'Unable to resolve path to module \'./test.gif\'.' ],
}),

test({
code: 'import "./test.png"',
options: [{ ignore: ['\.gif$']}],
errors: [ "Unable to resolve path to module './test.png'." ],
errors: [ 'Unable to resolve path to module \'./test.png\'.' ],
}),
],
})
Expand Down

0 comments on commit 34765ab

Please sign in to comment.