1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.TestPlugin = void 0;
|
4 | const fcli_command_core_1 = require("@midwayjs/fcli-command-core");
|
5 | const fs_1 = require("fs");
|
6 | const path_1 = require("path");
|
7 | const test_1 = require("./test");
|
8 | class TestPlugin extends fcli_command_core_1.BasePlugin {
|
9 | constructor() {
|
10 | super(...arguments);
|
11 | this.commands = {
|
12 | test: {
|
13 | usage: 'Test a Serverless service',
|
14 | lifecycleEvents: ['test'],
|
15 | options: {
|
16 | cov: {
|
17 | usage: 'get code coverage report',
|
18 | shortcut: 'c',
|
19 | },
|
20 | watch: {
|
21 | usage: 'watch',
|
22 | shortcut: 'w',
|
23 | },
|
24 | reporter: {
|
25 | usage: 'set mocha reporter',
|
26 | shortcut: 'r',
|
27 | },
|
28 | file: {
|
29 | usage: 'specify a test file',
|
30 | shortcut: 'f',
|
31 | },
|
32 | },
|
33 | },
|
34 | };
|
35 | this.hooks = {
|
36 | 'test:test': async () => {
|
37 | const servicePath = this.core.config.servicePath;
|
38 | let testFiles = [];
|
39 | if (this.options.f) {
|
40 | testFiles = [this.options.f];
|
41 | this.core.cli.log(`Testing ${this.options.f}`);
|
42 | }
|
43 | else {
|
44 | this.core.cli.log('Testing all *.test.js/ts...');
|
45 | }
|
46 | const options = this.options;
|
47 | const tester = new test_1.Test();
|
48 | await tester.run({
|
49 | cwd: servicePath,
|
50 | env: process.env,
|
51 | argv: Object.assign(process.argv, {
|
52 | _: testFiles,
|
53 | cov: this.options.cov,
|
54 | nyc: '--reporter=json --reporter=lcov --reporter=text',
|
55 | watch: options.watch,
|
56 | extension: 'ts,js',
|
57 | reporter: options.reporter,
|
58 | typescript: fs_1.existsSync(path_1.join(servicePath, 'tsconfig.json')),
|
59 | }),
|
60 | execArgv: process.execArgv,
|
61 | });
|
62 | },
|
63 | };
|
64 | }
|
65 | }
|
66 | exports.TestPlugin = TestPlugin;
|
67 |
|
\ | No newline at end of file |