UNPKG

@knapsack-pro/jest

Version:

Knapsack Pro Jest splits Jest tests across CI nodes and makes sure that tests will run in optimal time on each CI node.

29 lines (28 loc) 1.17 kB
import { glob } from 'glob'; import { minimatch } from 'minimatch'; import { KnapsackProLogger } from '@knapsack-pro/core'; import { EnvConfig } from './env-config.js'; import * as Urls from './urls.js'; export class TestFilesFinder { static allTestFiles() { const testFiles = glob .sync(EnvConfig.testFilePattern) .filter((testFilePath) => { if (EnvConfig.testFileExcludePattern) { return !minimatch(testFilePath, EnvConfig.testFileExcludePattern, { matchBase: true, }); } return true; }) .filter((testFilePath) => !testFilePath.match(/node_modules/)) .map((testFilePath) => ({ path: testFilePath })); if (testFiles.length === 0) { const knapsackProLogger = new KnapsackProLogger(); const errorMessage = `Test files cannot be found.\nPlease set KNAPSACK_PRO_TEST_FILE_PATTERN matching your test directory structure.\nLearn more: ${Urls.NO_TESTS_FOUND}`; knapsackProLogger.error(errorMessage); throw errorMessage; } return testFiles; } }