Skip to content

Commit

Permalink
Consider _test.{js|ts|gjs|gts} as test file. (#2157)
Browse files Browse the repository at this point in the history
  • Loading branch information
HEYGUL authored Jul 30, 2024
1 parent 55cd064 commit 12a8077
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lib/utils/ember.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,12 @@ function isModuleByFilePath(filePath, module) {
}

const validFileExtensions = ['js', 'ts', 'gjs', 'gts'];
const validTestFilePatterns = ['-test', '_test'];

function isTestFile(fileName) {
return validFileExtensions.some((ext) => fileName.endsWith(`-test.${ext}`));
return validFileExtensions.some((ext) =>
validTestFilePatterns.some((testFilePattern) => fileName.endsWith(`${testFilePattern}.${ext}`))
);
}

function isMirageDirectory(fileName) {
Expand Down
9 changes: 8 additions & 1 deletion tests/lib/utils/ember-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,20 @@ describe('isMirageConfig', () => {
});

describe('isTestFile', () => {
it('detects test files', () => {
it('detects test files ending with -test', () => {
expect(emberUtils.isTestFile('some-test.js')).toBeTruthy();
expect(emberUtils.isTestFile('some-test.ts')).toBeTruthy();
expect(emberUtils.isTestFile('some-test.gjs')).toBeTruthy();
expect(emberUtils.isTestFile('some-test.gts')).toBeTruthy();
});

it('detects test files ending with _test', () => {
expect(emberUtils.isTestFile('some_test.js')).toBeTruthy();
expect(emberUtils.isTestFile('some_test.ts')).toBeTruthy();
expect(emberUtils.isTestFile('some_test.gjs')).toBeTruthy();
expect(emberUtils.isTestFile('some_test.gts')).toBeTruthy();
});

it('does not detect other files', () => {
expect(emberUtils.isTestFile('some-component.js')).toBeFalsy();
expect(emberUtils.isTestFile('my-testing-component.js')).toBeFalsy();
Expand Down

0 comments on commit 12a8077

Please sign in to comment.