source: trip-planner-front/node_modules/@angular-devkit/build-angular/src/webpack/plugins/single-test-transform.js

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

initial commit

  • Property mode set to 100644
File size: 1.9 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 */
9Object.defineProperty(exports, "__esModule", { value: true });
10exports.SingleTestTransformLoader = void 0;
11const core_1 = require("@angular-devkit/core");
12const path_1 = require("path");
13exports.SingleTestTransformLoader = __filename;
14/**
15 * This loader transforms the default test file to only run tests
16 * for some specs instead of all specs.
17 * It works by replacing the known content of the auto-generated test file:
18 * const context = require.context('./', true, /\.spec\.ts$/);
19 * context.keys().map(context);
20 * with:
21 * const context = { keys: () => ({ map: (_a) => { } }) };
22 * context.keys().map(context);
23 * So that it does nothing.
24 * Then it adds import statements for each file in the files options
25 * array to import them directly, and thus run the tests there.
26 */
27// eslint-disable-next-line @typescript-eslint/no-explicit-any
28function loader(source) {
29 const { files = [], logger = console } = this.getOptions();
30 // signal the user that expected content is not present.
31 if (!source.includes('require.context(')) {
32 logger.error(core_1.tags.stripIndent `The 'include' option requires that the 'main' file for tests includes the below line:
33 const context = require.context('./', true, /\.spec\.ts$/);
34 Arguments passed to require.context are not strict and can be changed.`);
35 return source;
36 }
37 const targettedImports = files
38 .map((path) => `require('./${path.replace('.' + path_1.extname(path), '')}');`)
39 .join('\n');
40 const mockedRequireContext = 'Object.assign(() => { }, { keys: () => [], resolve: () => undefined });\n';
41 source = source.replace(/require\.context\(.*/, mockedRequireContext + targettedImports);
42 return source;
43}
44exports.default = loader;
Note: See TracBrowser for help on using the repository browser.