Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update no-test-import-export rule to allow importing from anything under tests/helpers path #895

Merged
merged 1 commit into from Jul 20, 2020
Merged

Update no-test-import-export rule to allow importing from anything under tests/helpers path #895

merged 1 commit into from Jul 20, 2020

Conversation

bmish
Copy link
Member

@bmish bmish commented Jul 19, 2020

Fixes #889.

CC: @mongoose700 @raido

@bmish bmish added the Bug label Jul 19, 2020
@bmish bmish requested a review from rwjblue July 19, 2020 18:27
importSource.startsWith('tests/helpers/') ||
importSource.includes('/tests/helpers/') ||
importSource.endsWith('/tests/helpers') ||
importSource === 'tests/helpers'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it valid for tests/helpers to be a single file instead of a directory?

Copy link
Member Author

@bmish bmish Jul 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure. I suppose this line would handle either a file named tests/helpers.js or a file named tests/helpers/index.js.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it valid for tests/helpers to be a single file instead of a directory?

Yes, it is definitely possible (and allowed) to use a single tests/helpers.js file or a tests/helpers/index.js file.

@@ -42,7 +45,7 @@ module.exports = {
ImportDeclaration(node) {
const importSource = node.source.value;

if (importSource.endsWith('-test')) {
if (importSource.endsWith('-test') && !isTestHelperImportSource(importSource)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I'm not 100% sure this is correct. We shouldn't be importing from tests/helpers/something-test.js (e.g. I think the first condition was fine, any file ending with -test is itself a test file not a helper file).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see why it was done. If you literally write a module like tests/helpers/some-verb-test.js it would still error.

@bmish bmish merged commit 7701b2b into ember-cli:master Jul 20, 2020
},

// Importing anything from tests/helpers is allowed.
"import setupApplicationTest from 'tests/helpers/setup-application-test.js';",
Copy link
Contributor

@raido raido Aug 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are missing relative path test case, for example:

../../helpers/setup-application-test.js

--

I upgraded eslint-plugin-ember to v8.10.1 and my ESLint still complains about imports from helpers folder, because relative import paths are being used.

I can workaround by changing to absolute path (TypeScript app), like myapp/tests/helpers/.

It seems plugin should resolve real path on disk with path.resolve or something to determine truthiness in isTestHelperFilename method.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should fix it: #911

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

no-test-import-export rule should allowed importing from tests/helpers folder
4 participants