source: trip-planner-front/node_modules/@angular-devkit/build-angular/src/karma/find-tests.js@ 571e0df

Last change on this file since 571e0df was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 3.0 KB
Line 
1"use strict";
2/**
3 * @license
4 * Copyright Google LLC All Rights Reserved.
5 *
6 * Use of this source code is governed by an MIT-style license that can be
7 * found in the LICENSE file at https://angular.io/license
8 */
9var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10 if (k2 === undefined) k2 = k;
11 Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
12}) : (function(o, m, k, k2) {
13 if (k2 === undefined) k2 = k;
14 o[k2] = m[k];
15}));
16var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17 Object.defineProperty(o, "default", { enumerable: true, value: v });
18}) : function(o, v) {
19 o["default"] = v;
20});
21var __importStar = (this && this.__importStar) || function (mod) {
22 if (mod && mod.__esModule) return mod;
23 var result = {};
24 if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
25 __setModuleDefault(result, mod);
26 return result;
27};
28Object.defineProperty(exports, "__esModule", { value: true });
29exports.findTests = void 0;
30const fs_1 = require("fs");
31const glob = __importStar(require("glob"));
32const path_1 = require("path");
33const is_directory_1 = require("../utils/is-directory");
34// go through all patterns and find unique list of files
35function findTests(patterns, cwd, workspaceRoot) {
36 return patterns.reduce((files, pattern) => {
37 const relativePathToMain = cwd.replace(workspaceRoot, '').substr(1); // remove leading slash
38 const tests = findMatchingTests(pattern, cwd, relativePathToMain);
39 tests.forEach((file) => {
40 if (!files.includes(file)) {
41 files.push(file);
42 }
43 });
44 return files;
45 }, []);
46}
47exports.findTests = findTests;
48function findMatchingTests(pattern, cwd, relativePathToMain) {
49 // normalize pattern, glob lib only accepts forward slashes
50 pattern = pattern.replace(/\\/g, '/');
51 relativePathToMain = relativePathToMain.replace(/\\/g, '/');
52 // remove relativePathToMain to support relative paths from root
53 // such paths are easy to get when running scripts via IDEs
54 if (pattern.startsWith(relativePathToMain + '/')) {
55 pattern = pattern.substr(relativePathToMain.length + 1); // +1 to include slash
56 }
57 // special logic when pattern does not look like a glob
58 if (!glob.hasMagic(pattern)) {
59 if (is_directory_1.isDirectory(path_1.join(cwd, pattern))) {
60 pattern = `${pattern}/**/*.spec.@(ts|tsx)`;
61 }
62 else {
63 // see if matching spec file exists
64 const extension = path_1.extname(pattern);
65 const matchingSpec = `${path_1.basename(pattern, extension)}.spec${extension}`;
66 if (fs_1.existsSync(path_1.join(cwd, path_1.dirname(pattern), matchingSpec))) {
67 pattern = path_1.join(path_1.dirname(pattern), matchingSpec).replace(/\\/g, '/');
68 }
69 }
70 }
71 const files = glob.sync(pattern, {
72 cwd,
73 });
74 return files;
75}
Note: See TracBrowser for help on using the repository browser.