Skip to content
This repository has been archived by the owner on Feb 27, 2022. It is now read-only.

Commit

Permalink
Merge 6a5d156 into 4a461e2
Browse files Browse the repository at this point in the history
  • Loading branch information
MZanggl committed Dec 25, 2019
2 parents 4a461e2 + 6a5d156 commit 68ea245
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 20 deletions.
15 changes: 1 addition & 14 deletions commands/RunTests.js
Expand Up @@ -156,20 +156,7 @@ class RunTests extends Command {
/**
* Getting all test files from the cli
*/
let testFiles = await this.cli.getTestFiles()

/**
* If there are specific files defined, then grep on
* them to pick only those files
*/
if (_.size(filesToPick)) {
testFiles = _.filter(testFiles, (file) => {
return !!_.find(filesToPick, (selectedFile) => {
return file.endsWith(selectedFile.trim())
})
})
debug('post --files filter %j', testFiles)
}
const testFiles = await this.cli.getTestFiles(filesToPick)

try {
/**
Expand Down
24 changes: 18 additions & 6 deletions src/Cli/index.js
Expand Up @@ -118,27 +118,39 @@ class Cli {
*
* @method getTestFiles
*
* @param {Array} filesToPick
* @return {Array}
*/
async getTestFiles () {
async getTestFiles (filesToPick = []) {
const includes = _.filter(this._testGroups, (test) => !!test)
const excludes = typeof (this._ignoreTests) === 'string' ? [this._ignoreTests] : this._ignoreTests

const files = await globby(this._getGlob(includes, excludes), {
let testFiles = await globby(this._getGlob(includes, excludes), {
realpath: true
})

/**
* If there is no filter callback, all files are returned
* Otherwise user is given a chance to filter test files.
*/
if (typeof (this._filterCallback) !== 'function') {
debug('test files %j', files)
return files
if (typeof (this._filterCallback) === 'function') {
testFiles = testFiles.filter(this._filterCallback)
}

/**
* If there are specific files defined, then grep on
* them to pick only those files
*/
if (_.size(filesToPick)) {
testFiles = _.filter(testFiles, (file) => {
return _.some(filesToPick, (selectedFile) => {
return file.includes(selectedFile.trim())
})
})
}

const testFiles = files.filter(this._filterCallback)
debug('test files %j', testFiles)

return testFiles
}
}
Expand Down
17 changes: 17 additions & 0 deletions test/unit/cli.spec.js
Expand Up @@ -152,4 +152,21 @@ test.group('Cli', (group) => {
const testsFiles = await this.cli.getTestFiles()
assert.deepEqual(testsFiles, [upath.normalize(functionalTestFile)])
})

test('filter for files', async (assert) => {
const unitTestFileOne = path.join(this.helpers.appRoot(), 'test/unit/sample-one.spec.js')
const unitTestFileTwo = path.join(this.helpers.appRoot(), 'test/unit/sample-two.spec.js')

await fs.ensureFile(unitTestFileOne)
await fs.ensureFile(unitTestFileTwo)

const testsFiles = await this.cli.getTestFiles(['sample-one'])
assert.deepEqual(testsFiles, [upath.normalize(unitTestFileOne)])

const testsFilesAll = await this.cli.getTestFiles(['sample'])
assert.deepEqual(testsFilesAll, [
upath.normalize(unitTestFileTwo),
upath.normalize(unitTestFileOne)
])
})
})

0 comments on commit 68ea245

Please sign in to comment.