From 34765ab2ce077f8b5ed26b91034f9e7a7042353d Mon Sep 17 00:00:00 2001 From: Simon Emanuel Schmid Date: Sat, 3 Aug 2019 19:48:54 +0200 Subject: [PATCH] Add failing test scenario for #1436 --- .../node_modules/@generated/bar/index.js | 0 .../node_modules/@generated/foo/index.js | 0 tests/files/package.json | 3 +- tests/src/rules/no-unresolved.js | 73 +++++++++++-------- 4 files changed, 43 insertions(+), 33 deletions(-) create mode 100644 tests/files/node_modules/@generated/bar/index.js create mode 100644 tests/files/node_modules/@generated/foo/index.js diff --git a/tests/files/node_modules/@generated/bar/index.js b/tests/files/node_modules/@generated/bar/index.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/files/node_modules/@generated/foo/index.js b/tests/files/node_modules/@generated/foo/index.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/files/package.json b/tests/files/package.json index 0a60f28d36..0ca8e77737 100644 --- a/tests/files/package.json +++ b/tests/files/package.json @@ -15,5 +15,6 @@ }, "optionalDependencies": { "lodash.isarray": "^4.0.0" - } + }, + "bundledDependencies": ["@generated/foo"] } diff --git a/tests/src/rules/no-unresolved.js b/tests/src/rules/no-unresolved.js index 124ac84830..54229e761d 100644 --- a/tests/src/rules/no-unresolved.js +++ b/tests/src/rules/no-unresolved.js @@ -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"' }), @@ -95,50 +95,50 @@ 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 @@ -146,7 +146,7 @@ function runResolverTests(resolver) { 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', }], }), @@ -154,7 +154,7 @@ function runResolverTests(resolver) { 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', }], }), @@ -164,7 +164,7 @@ 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', }], }), @@ -172,7 +172,7 @@ function runResolverTests(resolver) { 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', }], }), @@ -180,10 +180,10 @@ function runResolverTests(resolver) { 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', }], }), @@ -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: [ @@ -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() @@ -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'), @@ -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\'.' ], }), ], }) @@ -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\'.' ], }), ], }) @@ -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\'.' ], }), ], })