1 | (function (factory) {
|
2 | if (typeof module === "object" && typeof module.exports === "object") {
|
3 | var v = factory(require, exports);
|
4 | if (v !== undefined) module.exports = v;
|
5 | }
|
6 | else if (typeof define === "function" && define.amd) {
|
7 | define(["require", "exports", "tslib", "url", "path", "querystring", "@theintern/common", "./Suite", "./common/util", "./Deferred"], factory);
|
8 | }
|
9 | })(function (require, exports) {
|
10 | "use strict";
|
11 | Object.defineProperty(exports, "__esModule", { value: true });
|
12 | var tslib_1 = require("tslib");
|
13 | var url_1 = require("url");
|
14 | var path_1 = require("path");
|
15 | var querystring_1 = require("querystring");
|
16 | var common_1 = require("@theintern/common");
|
17 | var Suite_1 = require("./Suite");
|
18 | var util_1 = require("./common/util");
|
19 | var Deferred_1 = require("./Deferred");
|
20 | var RemoteSuite = (function (_super) {
|
21 | tslib_1.__extends(RemoteSuite, _super);
|
22 | function RemoteSuite(options) {
|
23 | var _this = this;
|
24 | options = options || {};
|
25 | if (options.name == null) {
|
26 | options.name = 'remote unit tests';
|
27 | }
|
28 | _this = _super.call(this, options) || this;
|
29 | if (_this.timeout == null) {
|
30 | _this.timeout = Infinity;
|
31 | }
|
32 | return _this;
|
33 | }
|
34 | Object.defineProperty(RemoteSuite.prototype, "id", {
|
35 | get: function () {
|
36 | var name = [];
|
37 | var suite = this.parent;
|
38 | do {
|
39 | suite.name != null && name.unshift(suite.name);
|
40 | } while ((suite = suite.parent));
|
41 | return name.join(' - ');
|
42 | },
|
43 | enumerable: true,
|
44 | configurable: true
|
45 | });
|
46 | RemoteSuite.prototype.run = function () {
|
47 | var _this = this;
|
48 | var remote = this.remote;
|
49 | var sessionId = remote.session.sessionId;
|
50 | var server = this.executor.server;
|
51 | var listenerHandle;
|
52 | var connectTimer;
|
53 | return new common_1.Task(function (resolve, reject) {
|
54 | var handleError = function (error) {
|
55 | _this.error = error;
|
56 | reject(error);
|
57 | };
|
58 | var config = _this.executor.config;
|
59 | var pendingConnection = new Deferred_1.default();
|
60 | var connectTimeout = config.connectTimeout;
|
61 | connectTimer = global.setTimeout(function () {
|
62 | var error = new Error('Timed out waiting for remote to connect');
|
63 | error.name = 'TimeoutError';
|
64 | pendingConnection.reject(error);
|
65 | }, connectTimeout);
|
66 | listenerHandle = server.subscribe(sessionId, function (eventName, data) {
|
67 | var _a;
|
68 | var name = eventName;
|
69 | var suite;
|
70 | switch (name) {
|
71 | case 'remoteStatus':
|
72 | if (data === 'initialized') {
|
73 | clearTimeout(connectTimer);
|
74 | pendingConnection.resolve();
|
75 | }
|
76 | break;
|
77 | case 'suiteStart':
|
78 | suite = data;
|
79 | if (!suite.hasParent) {
|
80 | (_a = _this.tests).push.apply(_a, suite.tests);
|
81 | return _this.executor.emit('suiteStart', _this);
|
82 | }
|
83 | else {
|
84 | return _this.executor.emit(name, data);
|
85 | }
|
86 | case 'suiteEnd':
|
87 | suite = data;
|
88 | _this.skipped = suite.skipped;
|
89 | if (!suite.hasParent) {
|
90 | suite.tests.forEach(function (test, index) {
|
91 | _this.tests[index] = test;
|
92 | });
|
93 | if (suite.error) {
|
94 | handleError(suite.error);
|
95 | }
|
96 | }
|
97 | else {
|
98 | return _this.executor.emit(name, data);
|
99 | }
|
100 | break;
|
101 | case 'beforeRun':
|
102 | case 'afterRun':
|
103 | case 'runStart':
|
104 | break;
|
105 | case 'runEnd':
|
106 | var promise = remote.setHeartbeatInterval(0);
|
107 | if (_this.executor.hasCoveredFiles) {
|
108 | promise = promise.get('about:blank');
|
109 | }
|
110 | return promise.then(resolve, reject);
|
111 | case 'error':
|
112 | if (!/One or more suite errors/.test(data.message)) {
|
113 | handleError(data);
|
114 | }
|
115 | break;
|
116 | default:
|
117 | return _this.executor.emit(name, data);
|
118 | }
|
119 | });
|
120 | var serverUrl = url_1.parse(config.serverUrl);
|
121 | var timeout = config.heartbeatInterval;
|
122 | if (timeout >= 1 && timeout < Infinity) {
|
123 | remote.setHeartbeatInterval((timeout - 1) * 1000);
|
124 | }
|
125 | var queryOptions = {
|
126 | basePath: serverUrl.pathname,
|
127 | runInSync: config.runInSync || false,
|
128 | serverUrl: serverUrl.href,
|
129 | sessionId: sessionId,
|
130 | socketPort: server.socketPort
|
131 | };
|
132 | var queryParams = {};
|
133 | Object.keys(queryOptions)
|
134 | .filter(function (option) {
|
135 | var key = option;
|
136 | return queryOptions[key] != null;
|
137 | })
|
138 | .forEach(function (option) {
|
139 | var key = option;
|
140 | var value = queryOptions[key];
|
141 | if (typeof value === 'object') {
|
142 | value = JSON.stringify(value);
|
143 | }
|
144 | queryParams[key] = value;
|
145 | });
|
146 | var query = querystring_1.stringify(queryParams);
|
147 | var harness = config.serverUrl + "__intern/browser/remote.html";
|
148 | var internPath = path_1.relative(config.basePath, config.internPath);
|
149 | var disableDomUpdates = config.remoteOptions && config.remoteOptions.disableDomUpdates;
|
150 | var remoteReporters = disableDomUpdates ? [] : [{ name: 'dom' }];
|
151 | var remoteConfig = {
|
152 | debug: config.debug,
|
153 | internPath: "" + serverUrl.pathname + internPath,
|
154 | name: _this.id,
|
155 | reporters: remoteReporters
|
156 | };
|
157 | var excludeKeys = {
|
158 | basePath: true,
|
159 | internPath: true,
|
160 | name: true,
|
161 | reporters: true,
|
162 | serverUrl: true,
|
163 | sessionId: true,
|
164 | socketPort: true
|
165 | };
|
166 | Object.keys(config)
|
167 | .filter(function (key) { return !excludeKeys[key]; })
|
168 | .forEach(function (property) {
|
169 | var key = property;
|
170 | remoteConfig[key] = config[key];
|
171 | });
|
172 | _this.executor.log('Configuring remote "', _this.name, '" with', remoteConfig);
|
173 | remote
|
174 | .get(harness + "?" + query)
|
175 | .then(function () { return pendingConnection.promise; })
|
176 | .execute(function (configString) {
|
177 | var options = JSON.parse(configString);
|
178 | intern.configure(options);
|
179 | intern.run().catch(function (_error) { });
|
180 | }, [util_1.stringify(remoteConfig)])
|
181 | .catch(function (error) {
|
182 | return remote.setHeartbeatInterval(0).finally(function () { return handleError(error); });
|
183 | });
|
184 | }, function () { return remote.setHeartbeatInterval(0); })
|
185 | .catch(function (error) {
|
186 | if (!_this.error) {
|
187 | _this.error = error;
|
188 | }
|
189 | throw error;
|
190 | })
|
191 | .finally(function () {
|
192 | if (connectTimer) {
|
193 | clearTimeout(connectTimer);
|
194 | }
|
195 | listenerHandle.destroy();
|
196 | })
|
197 | .finally(function () { return _this.executor.emit('suiteEnd', _this); });
|
198 | };
|
199 | return RemoteSuite;
|
200 | }(Suite_1.default));
|
201 | exports.default = RemoteSuite;
|
202 | });
|
203 |
|
\ | No newline at end of file |