1 | #!/usr/bin/env node
|
2 | (function (factory) {
|
3 | if (typeof module === "object" && typeof module.exports === "object") {
|
4 | var v = factory(require, exports);
|
5 | if (v !== undefined) module.exports = v;
|
6 | }
|
7 | else if (typeof define === "function" && define.amd) {
|
8 | define(["require", "exports", "tslib", "child_process", "@theintern/common", "../lib/node/util", "../lib/common/util", "../index", "../lib/common/console"], factory);
|
9 | }
|
10 | })(function (require, exports) {
|
11 | "use strict";
|
12 | Object.defineProperty(exports, "__esModule", { value: true });
|
13 | var tslib_1 = require("tslib");
|
14 | var child_process_1 = require("child_process");
|
15 | var common_1 = require("@theintern/common");
|
16 | var util_1 = require("../lib/node/util");
|
17 | var util_2 = require("../lib/common/util");
|
18 | var index_1 = tslib_1.__importDefault(require("../index"));
|
19 | var console = tslib_1.__importStar(require("../lib/common/console"));
|
20 | util_1.getConfig()
|
21 | .then(function (_a) {
|
22 | var config = _a.config, file = _a.file;
|
23 | if (config.help) {
|
24 | printHelp(config, file);
|
25 | }
|
26 | else if (config.showConfigs) {
|
27 | console.log(util_2.getConfigDescription(config));
|
28 | }
|
29 | else {
|
30 | if (!file) {
|
31 | console.warn('No config file was loaded');
|
32 | }
|
33 | index_1.default.configure({ reporters: 'runner' });
|
34 | index_1.default.configure(config);
|
35 | if (index_1.default.environment === 'browser' &&
|
36 | ((index_1.default.config.suites &&
|
37 | index_1.default.config.suites.some(function (pattern) { return pattern.endsWith('.ts'); })) ||
|
38 | (index_1.default.config.plugins &&
|
39 | index_1.default.config.plugins.some(function (plugin) {
|
40 | return plugin.script.endsWith('.ts');
|
41 | })))) {
|
42 | throw new Error('Loading TypeScript files is not supported in the browser');
|
43 | }
|
44 | return index_1.default.run();
|
45 | }
|
46 | })
|
47 | .catch(function (error) {
|
48 | if (!error.reported) {
|
49 | try {
|
50 | console.error(index_1.default.formatError(error));
|
51 | }
|
52 | catch (e) {
|
53 | console.error(error);
|
54 | }
|
55 | }
|
56 | common_1.global.process.exitCode = 1;
|
57 | });
|
58 | function printHelp(config, file) {
|
59 | var $ = function (cmd) { return child_process_1.execSync(cmd, { encoding: 'utf8' }).trim(); };
|
60 | var pkg = require('../package.json');
|
61 | var npmVersion = $('npm -v');
|
62 | var nodeVersion = $('node -v');
|
63 | console.log("intern version " + pkg.version);
|
64 | console.log("npm version " + npmVersion);
|
65 | console.log("node version " + nodeVersion);
|
66 | console.log();
|
67 | console.log('Usage: intern [config=<file>] [showConfig|showConfigs] [options]');
|
68 | console.log();
|
69 | console.log(' config - path to a config file');
|
70 | console.log(' showConfig - show the resolved config');
|
71 | console.log(' showConfigs - show information about configFile');
|
72 | console.log();
|
73 | console.log("Options (set with 'option=value' or 'option'):\n");
|
74 | var internConfig = index_1.default._config;
|
75 | var opts = Object.keys(internConfig)
|
76 | .map(function (key) {
|
77 | return { name: key, value: JSON.stringify(internConfig[key]) };
|
78 | })
|
79 | .sort(function (a, b) {
|
80 | if (a.name < b.name) {
|
81 | return -1;
|
82 | }
|
83 | if (a.name > b.name) {
|
84 | return 1;
|
85 | }
|
86 | return 0;
|
87 | });
|
88 | var width = opts.reduce(function (max, opt) { return Math.max(opt.name.length, max); }, 0);
|
89 | for (var _i = 0, opts_1 = opts; _i < opts_1.length; _i++) {
|
90 | var _a = opts_1[_i], name_1 = _a.name, value = _a.value;
|
91 | var pad = Array(width - name_1.length + 1).join(' ');
|
92 | console.log(" " + name_1 + pad + " - " + value);
|
93 | }
|
94 | if (file) {
|
95 | console.log();
|
96 | var description = util_2.getConfigDescription(config, ' ');
|
97 | if (description) {
|
98 | console.log("Using config file '" + file + "':\n");
|
99 | console.log(description);
|
100 | }
|
101 | else {
|
102 | console.log("Using config file '" + file + "'");
|
103 | }
|
104 | }
|
105 | }
|
106 | });
|
107 |
|
\ | No newline at end of file |