1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | Object.defineProperty(exports, "__esModule", { value: true });
|
6 | exports.getLocalWhistleServer = exports.launchSync = exports.launch = void 0;
|
7 | const fs_1 = __importDefault(require("fs"));
|
8 | const matman_core_1 = require("matman-core");
|
9 | const lodash_1 = __importDefault(require("lodash"));
|
10 | const PageDriverSync_1 = __importDefault(require("./model/PageDriverSync"));
|
11 | const PageDriverAsync_1 = __importDefault(require("./model/PageDriverAsync"));
|
12 | const caller_1 = require("./util/caller");
|
13 | const whistle_1 = require("./util/whistle");
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | function getPageDriverOpts(opts) {
|
20 | const pageDriverOpts = lodash_1.default.merge({}, opts);
|
21 | let { caseModuleFilePath } = pageDriverOpts;
|
22 |
|
23 | if (!caseModuleFilePath || !fs_1.default.existsSync(caseModuleFilePath)) {
|
24 |
|
25 |
|
26 | caseModuleFilePath = caller_1.getCallerPath();
|
27 |
|
28 | if (!caseModuleFilePath || !fs_1.default.existsSync(caseModuleFilePath)) {
|
29 | throw new Error(`Could not find caseModuleFilePath!`);
|
30 | }
|
31 |
|
32 | pageDriverOpts.caseModuleFilePath = caseModuleFilePath;
|
33 | }
|
34 |
|
35 |
|
36 |
|
37 | if (!pageDriverOpts.tag) {
|
38 | pageDriverOpts.tag = caller_1.getCallerPath(caseModuleFilePath);
|
39 | }
|
40 |
|
41 | if (pageDriverOpts.tag === caseModuleFilePath) {
|
42 | pageDriverOpts.tag = '';
|
43 | }
|
44 | return pageDriverOpts;
|
45 | }
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 | function launch(browserRunner, pageDriverOpts, matmanConfigOpts) {
|
54 |
|
55 | const newPageDriverOpts = getPageDriverOpts(pageDriverOpts);
|
56 |
|
57 | const matmanConfig = matman_core_1.findMatmanConfig(newPageDriverOpts.caseModuleFilePath, matmanConfigOpts);
|
58 |
|
59 | if (!matmanConfig) {
|
60 | throw new Error(`Could not find ${matman_core_1.MATMAN_CONFIG_FILE} or matman config setting!`);
|
61 | }
|
62 |
|
63 |
|
64 | return new PageDriverAsync_1.default(browserRunner, matmanConfig, newPageDriverOpts);
|
65 | }
|
66 | exports.launch = launch;
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 | function launchSync(browserRunner, pageDriverOpts, matmanConfigOpts) {
|
75 |
|
76 | const newPageDriverOpts = getPageDriverOpts(pageDriverOpts);
|
77 |
|
78 | const matmanConfig = matman_core_1.findMatmanConfig(newPageDriverOpts.caseModuleFilePath, matmanConfigOpts);
|
79 |
|
80 | if (!matmanConfig) {
|
81 | throw new Error(`Could not find ${matman_core_1.MATMAN_CONFIG_FILE} or matman config setting!`);
|
82 | }
|
83 |
|
84 |
|
85 | return new PageDriverSync_1.default(browserRunner, matmanConfig, newPageDriverOpts);
|
86 | }
|
87 | exports.launchSync = launchSync;
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 | async function getLocalWhistleServer(port, doNotAutoCheckStartedPort) {
|
95 |
|
96 | if (process.env.WHISTLE_PORT) {
|
97 | return `127.0.0.1:${process.env.WHISTLE_PORT}`;
|
98 | }
|
99 | let whisltePort;
|
100 | if (!doNotAutoCheckStartedPort) {
|
101 | try {
|
102 | whisltePort = await whistle_1.checkIfWhistleStarted();
|
103 | }
|
104 | catch (e) {
|
105 | if (process.env.IS_DEV === '1') {
|
106 | console.log('checkIfWhistleStarted() catch', e);
|
107 | }
|
108 | }
|
109 | }
|
110 | if (!whisltePort) {
|
111 |
|
112 | whisltePort = port || 8899;
|
113 | }
|
114 | return `127.0.0.1:${whisltePort}`;
|
115 | }
|
116 | exports.getLocalWhistleServer = getLocalWhistleServer;
|