1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
10 | if (k2 === undefined) k2 = k;
|
11 | var desc = Object.getOwnPropertyDescriptor(m, k);
|
12 | if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
13 | desc = { enumerable: true, get: function() { return m[k]; } };
|
14 | }
|
15 | Object.defineProperty(o, k2, desc);
|
16 | }) : (function(o, m, k, k2) {
|
17 | if (k2 === undefined) k2 = k;
|
18 | o[k2] = m[k];
|
19 | }));
|
20 | var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
21 | Object.defineProperty(o, "default", { enumerable: true, value: v });
|
22 | }) : function(o, v) {
|
23 | o["default"] = v;
|
24 | });
|
25 | var __importStar = (this && this.__importStar) || function (mod) {
|
26 | if (mod && mod.__esModule) return mod;
|
27 | var result = {};
|
28 | if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
29 | __setModuleDefault(result, mod);
|
30 | return result;
|
31 | };
|
32 | Object.defineProperty(exports, "__esModule", { value: true });
|
33 | exports.findTests = void 0;
|
34 | const fs_1 = require("fs");
|
35 | const glob = __importStar(require("glob"));
|
36 | const path_1 = require("path");
|
37 | const is_directory_1 = require("../../utils/is-directory");
|
38 |
|
39 | function findTests(patterns, cwd, workspaceRoot) {
|
40 | return patterns.reduce((files, pattern) => {
|
41 | const relativePathToMain = cwd.replace(workspaceRoot, '').substr(1);
|
42 | const tests = findMatchingTests(pattern, cwd, relativePathToMain);
|
43 | tests.forEach((file) => {
|
44 | if (!files.includes(file)) {
|
45 | files.push(file);
|
46 | }
|
47 | });
|
48 | return files;
|
49 | }, []);
|
50 | }
|
51 | exports.findTests = findTests;
|
52 | function findMatchingTests(pattern, cwd, relativePathToMain) {
|
53 |
|
54 | pattern = pattern.replace(/\\/g, '/');
|
55 | relativePathToMain = relativePathToMain.replace(/\\/g, '/');
|
56 |
|
57 |
|
58 | if (pattern.startsWith(relativePathToMain + '/')) {
|
59 | pattern = pattern.substr(relativePathToMain.length + 1);
|
60 | }
|
61 |
|
62 | if (!glob.hasMagic(pattern)) {
|
63 | if ((0, is_directory_1.isDirectory)((0, path_1.join)(cwd, pattern))) {
|
64 | pattern = `${pattern}/**/*.spec.@(ts|tsx)`;
|
65 | }
|
66 | else {
|
67 |
|
68 | const extension = (0, path_1.extname)(pattern);
|
69 | const matchingSpec = `${(0, path_1.basename)(pattern, extension)}.spec${extension}`;
|
70 | if ((0, fs_1.existsSync)((0, path_1.join)(cwd, (0, path_1.dirname)(pattern), matchingSpec))) {
|
71 | pattern = (0, path_1.join)((0, path_1.dirname)(pattern), matchingSpec).replace(/\\/g, '/');
|
72 | }
|
73 | }
|
74 | }
|
75 | const files = glob.sync(pattern, {
|
76 | cwd,
|
77 | });
|
78 | return files;
|
79 | }
|