diff --git a/lib/rules/no-test-import-export.js b/lib/rules/no-test-import-export.js index 625141cf06..e09ab1e105 100644 --- a/lib/rules/no-test-import-export.js +++ b/lib/rules/no-test-import-export.js @@ -4,6 +4,7 @@ 'use strict'; +const { dirname, resolve } = require('path'); const emberUtils = require('../utils/ember'); const NO_IMPORT_MESSAGE = @@ -45,7 +46,10 @@ module.exports = { ImportDeclaration(node) { const importSource = node.source.value; - if (importSource.endsWith('-test') && !isTestHelperImportSource(importSource)) { + if ( + importSource.endsWith('-test') && + !isTestHelperImportSource(resolve(dirname(context.getFilename()), importSource)) + ) { context.report({ message: NO_IMPORT_MESSAGE, node, diff --git a/tests/lib/rules/no-test-import-export.js b/tests/lib/rules/no-test-import-export.js index 582d146fc8..9638560355 100644 --- a/tests/lib/rules/no-test-import-export.js +++ b/tests/lib/rules/no-test-import-export.js @@ -40,10 +40,20 @@ ruleTester.run('no-test-file-importing', rule, { }, // Importing anything from tests/helpers is allowed. - "import setupApplicationTest from 'tests/helpers/setup-application-test.js';", + "import setupApplicationTest from 'tests/helpers/setup-application-test';", "import { setupApplicationTest } from 'tests/helpers';", - "import setupApplicationTest from 'my-app-name/tests/helpers/setup-application-test.js';", + "import setupApplicationTest from 'my-app-name/tests/helpers/setup-application-test';", "import { setupApplicationTest } from 'my-app-name/tests/helpers';", + + // Importing anything from test/helpers is allowed (using relative path) + { + filename: 'my-app-name/tests/helpers/foo.js', + code: "import setupApplicationTest from './setup-application-test';", + }, + { + filename: 'my-app-name/tests/helpers/nested/foo.js', + code: "import setupApplicationTest from '../setup-application-test';", + }, ], invalid: [ { @@ -91,6 +101,13 @@ ruleTester.run('no-test-file-importing', rule, { }, ], }, + { + // Importing from a test file outside test/helpers is disallowed. + filename: 'my-app-name/tests/helpers/foo.js', + code: "import testModule from '../../test-dir/another-test';", + output: null, + errors: [{ message: NO_IMPORT_MESSAGE }], + }, { filename: 'tests/some-test.js', code: `