@knapsack-pro/cypress
Version:
Knapsack Pro Cypress splits Cypress.io tests across CI nodes and makes sure that tests will run in optimal time on each CI node.
28 lines (27 loc) • 1.18 kB
JavaScript
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;
})
.map((testFilePath) => ({ path: testFilePath }));
if (testFiles.length === 0) {
const knapsackProLogger = new KnapsackProLogger();
const errorMessage = `Test files cannot be found.\nPlease make sure that KNAPSACK_PRO_TEST_FILE_PATTERN and KNAPSACK_PRO_TEST_FILE_IGNORE_PATTERN allow for some files in your test directory structure to be matched.\nLearn more: ${Urls.NO_TESTS_FOUND}`;
knapsackProLogger.error(errorMessage);
throw errorMessage;
}
return testFiles;
}
}