Skip to content
This repository has been archived by the owner on Jun 13, 2023. It is now read-only.

Run tests only when they are detected on the disk. Do not run tests when the test file pattern is invalid. Require to set KNAPSACK_PRO_TEST_FILE_PATTERN #11

Merged
merged 2 commits into from
Nov 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 35 additions & 54 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"knapsack-pro-jest": "lib/knapsack-pro-jest.js"
},
"dependencies": {
"@knapsack-pro/core": "^1.6.0",
"@knapsack-pro/core": "^1.6.1",
"glob": "^7.1.3",
"jest": "^24.8.0",
"minimatch": "^3.0.4",
Expand Down
17 changes: 15 additions & 2 deletions src/test-files-finder.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import glob = require('glob');
import minimatch = require('minimatch');

import { TestFile } from '@knapsack-pro/core';
import { KnapsackProLogger, TestFile } from '@knapsack-pro/core';
import { EnvConfig } from './env-config';

export class TestFilesFinder {
public static allTestFiles(): TestFile[] {
return glob
const testFiles = glob
.sync(EnvConfig.testFilePattern)
.filter((testFilePath: string) => {
if (EnvConfig.testFileExcludePattern) {
Expand All @@ -22,5 +22,18 @@ export class TestFilesFinder {
return !testFilePath.match(/node_modules/);
})
.map((testFilePath: string) => ({ path: testFilePath }));

if (testFiles.length === 0) {
const knapsackProLogger = new KnapsackProLogger();

const errorMessage =
// tslint:disable-next-line: max-line-length
'Test files cannot be found.\nPlease set KNAPSACK_PRO_TEST_FILE_PATTERN matching your test directory structure.\nLearn more: https://github.com/KnapsackPro/knapsack-pro-jest#how-to-run-tests-only-from-specific-directory';

knapsackProLogger.error(errorMessage);
throw errorMessage;
}

return testFiles;
}
}