Skip to content

Commit

Permalink
Merge pull request #302 from choheekim/file-path-filtering
Browse files Browse the repository at this point in the history
Throw an error when there are no matching tests with a given input by `file-path` and `module-path`
  • Loading branch information
choheekim authored Jun 25, 2019
2 parents 214fb4d + 2565daf commit ca2a29c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
7 changes: 6 additions & 1 deletion addon-test-support/-private/filter-test-modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function filterTestModules(modules, modulePath, filePath) {
// Generates an array with module filter value seperated by comma (,).
const moduleFilters = (filePath || modulePath).split(',').map( value => value.trim());

return moduleFilters.reduce((result, moduleFilter) => {
const filteredTestModules = moduleFilters.reduce((result, moduleFilter) => {
const modulePath = convertFilePathToModulePath(moduleFilter);
const modulePathRegex = getRegexFilter(modulePath);

Expand All @@ -84,6 +84,11 @@ function filterTestModules(modules, modulePath, filePath) {
return result.concat(stringFilter(modules, modulePath).filter( module => result.indexOf(module) === -1 ));
}
}, []);

if (filteredTestModules.length === 0) {
throw new Error(`No tests matched with the filter: ${modulePath || filePath}.`);
}
return filteredTestModules;
}

export {
Expand Down
9 changes: 6 additions & 3 deletions tests/unit/mocha/filter-test-modules-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ describe('Unit | filter-test-modules', () => {
});

it('should return an empty list when there is no match', () => {
expect(filterTestModules(this.modules, 'no-match')).to.deep.equal([]);
expect(() => {
filterTestModules(this.modules, 'no-match');
}).to.throw(/No tests matched with the filter:/);
});

it('should return a list of tests matched with a regular expression', () => {
Expand Down Expand Up @@ -119,8 +121,9 @@ describe('Unit | filter-test-modules', () => {
});

it('should return a list of tests matched with a regular expression', () => {
expect(filterTestModules(this.modules, null, 'no-match')).to.deep.equal([
]);
expect(() => {
filterTestModules(this.modules, null, 'no-match');
}).to.throw(/No tests matched with the filter:/);
});

it('should return a list of tests matches with a list of string options', () => {
Expand Down
10 changes: 6 additions & 4 deletions tests/unit/qunit/filter-test-modules-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ module('Unit | filter-test-modules', function(hooks) {
});

test('should return an empty list when there is no match', function(assert) {
assert.deepEqual(
[], filterTestModules(this.modules, 'no-match')
assert.throws(
() => filterTestModules(this.modules, 'no-match'),
/No tests matched with the filter:/
);
});

Expand Down Expand Up @@ -145,8 +146,9 @@ module('Unit | filter-test-modules', function(hooks) {
});

test('should return an empty list when there is no match', function(assert) {
assert.deepEqual(
[], filterTestModules(this.modules, null, 'no-match')
assert.throws(
() => filterTestModules(this.modules, null, 'no-match'),
/No tests matched with the filter:/
);
});

Expand Down

0 comments on commit ca2a29c

Please sign in to comment.