1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | var __importStar = (this && this.__importStar) || function (mod) {
|
6 | if (mod && mod.__esModule) return mod;
|
7 | var result = {};
|
8 | if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
9 | result["default"] = mod;
|
10 | return result;
|
11 | };
|
12 | Object.defineProperty(exports, "__esModule", { value: true });
|
13 | const chalk_1 = __importDefault(require("chalk"));
|
14 | const path_1 = __importDefault(require("path"));
|
15 | const constants_1 = require("../internal/constants");
|
16 | const config_env_1 = require("../internal/core/config/config-env");
|
17 | const typescript_support_1 = require("../internal/core/typescript-support");
|
18 | const glob_1 = require("../internal/util/glob");
|
19 | const strings_1 = require("../internal/util/strings");
|
20 | const task_names_1 = require("./task-names");
|
21 | function default_1() {
|
22 | config_env_1.internalTask(task_names_1.TASK_TEST_GET_TEST_FILES)
|
23 | .addOptionalVariadicPositionalParam("testFiles", "An optional list of files to test", [])
|
24 | .setAction(async ({ testFiles }, { config }) => {
|
25 | if (testFiles.length !== 0) {
|
26 | return testFiles;
|
27 | }
|
28 | const jsFiles = await glob_1.glob(path_1.default.join(config.paths.tests, "**/*.js"));
|
29 | if (!typescript_support_1.isTypescriptSupported()) {
|
30 | return jsFiles;
|
31 | }
|
32 | const tsFiles = await glob_1.glob(path_1.default.join(config.paths.tests, "**/*.ts"));
|
33 | return [...jsFiles, ...tsFiles];
|
34 | });
|
35 | config_env_1.internalTask(task_names_1.TASK_TEST_SETUP_TEST_ENVIRONMENT, async () => { });
|
36 | config_env_1.internalTask(task_names_1.TASK_TEST_RUN_MOCHA_TESTS)
|
37 | .addOptionalVariadicPositionalParam("testFiles", "An optional list of files to test", [])
|
38 | .setAction(async ({ testFiles }, { config }) => {
|
39 | const { default: Mocha } = await Promise.resolve().then(() => __importStar(require("mocha")));
|
40 | const mocha = new Mocha(config.mocha);
|
41 | testFiles.forEach((file) => mocha.addFile(file));
|
42 | const runPromise = new Promise((resolve, _) => {
|
43 | mocha.run(resolve);
|
44 | });
|
45 | process.exitCode = await runPromise;
|
46 | });
|
47 | config_env_1.task(task_names_1.TASK_TEST, "Runs mocha tests")
|
48 | .addOptionalVariadicPositionalParam("testFiles", "An optional list of files to test", [])
|
49 | .addFlag("noCompile", "Don't compile before running this task")
|
50 | .setAction(async ({ testFiles, noCompile, }, { run, network }) => {
|
51 | if (!noCompile) {
|
52 | await run(task_names_1.TASK_COMPILE);
|
53 | }
|
54 | const files = await run(task_names_1.TASK_TEST_GET_TEST_FILES, { testFiles });
|
55 | await run(task_names_1.TASK_TEST_SETUP_TEST_ENVIRONMENT);
|
56 | await run(task_names_1.TASK_TEST_RUN_MOCHA_TESTS, { testFiles: files });
|
57 | if (network.name !== constants_1.BUIDLEREVM_NETWORK_NAME) {
|
58 | return;
|
59 | }
|
60 | const failures = await network.provider.send("buidler_getStackTraceFailuresCount");
|
61 | if (failures === 0) {
|
62 | return;
|
63 | }
|
64 | console.warn(chalk_1.default.yellow(`Failed to generate ${failures} ${strings_1.pluralize(failures, "stack trace")}. Run Buidler with --verbose to learn more.`));
|
65 | });
|
66 | }
|
67 | exports.default = default_1;
|
68 |
|
\ | No newline at end of file |