Skip to content

Commit 3e131bc

Browse files
committed
* report require-time errors back to Karma
* support for --debug-transport
1 parent dad28e9 commit 3e131bc

File tree

2 files changed

+42
-26
lines changed

2 files changed

+42
-26
lines changed

main-view-model.ts

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import stopProcess = require('./stop-process');
1212
interface IHostConfiguration {
1313
port: number;
1414
ips: string[];
15+
debug: boolean;
1516
}
1617

1718
interface INetworkConfiguration extends IHostConfiguration {
@@ -28,13 +29,15 @@ interface IScriptInfo {
2829
contents?: string;
2930
}
3031

31-
//function enableSocketIoDebugging() {
32-
// global.localStorage = {
33-
// debug: "*"
34-
// };
32+
function enableSocketIoDebugging() {
33+
console.log('enabling socket.io debugging');
3534

36-
// global.window = global;
37-
//}
35+
global.localStorage = {
36+
debug: "*"
37+
};
38+
39+
global.window = global;
40+
}
3841

3942
var config: INetworkConfiguration = require('./config');
4043

@@ -65,7 +68,9 @@ export class TestBrokerViewModel extends observable.Observable {
6568

6669
global.__karma__ = this;
6770

68-
//enableSocketIoDebugging();
71+
if (config.debug) {
72+
enableSocketIoDebugging();
73+
}
6974
//debugger;
7075

7176
this.testResults = new observableArray.ObservableArray();
@@ -240,29 +245,33 @@ export class TestBrokerViewModel extends observable.Observable {
240245
testScripts
241246
.filter(script => this.isTestScript(script.url))
242247
.forEach(script => {
243-
if (script.localPath) {
244-
console.log('NSUTR: require script ' + script.url + ' from ' + script.localPath);
245-
require(script.localPath);
246-
} else {
247-
console.log('NSUTR: eval script ' + script.url);
248-
this.loadShim(script.url);
249-
//call eval indirectly to execute the scripts in the global scope
250-
var geval = eval;
251-
geval(script.contents);
252-
this.completeLoading(script.url);
253-
}
254-
});
255-
256-
console.log('beginning test run');
257-
this.start(this.config);
248+
try {
249+
if (script.localPath) {
250+
console.log('NSUTR: require script ' + script.url + ' from ' + script.localPath);
251+
require(script.localPath);
252+
} else {
253+
console.log('NSUTR: eval script ' + script.url);
254+
this.loadShim(script.url);
255+
//call eval indirectly to execute the scripts in the global scope
256+
var geval = eval;
257+
geval(script.contents);
258+
this.completeLoading(script.url);
259+
}
260+
} catch (err) {
261+
this.error(err.toString(), script.localPath || script.url, err.lineNumber || 0);
262+
}
263+
});
264+
if (!this.hasError) {
265+
console.log('NSUTR: beginning test run');
266+
this.start(this.config);
267+
}
258268
}
259269

260270
private isTestScript(url: string): boolean {
261271
return url.startsWith('/base/app/tests/') || !url.startsWith('/base/app/');
262272
}
263273

264274
public updateBrowsersInfo(browsers) {
265-
//console.dir(browsers);
266275
}
267276

268277
public start(cfg: any) {
@@ -316,7 +325,14 @@ export class TestBrokerViewModel extends observable.Observable {
316325
this.hasError = true;
317326
var fullMsg = url ? msg + '\nat ' + url + (line ? ':' + line : '') : msg;
318327
console.log("NSUTR: this.error: " + fullMsg);
319-
this.socketEmit('error', fullMsg);
328+
this.result({
329+
id: url,
330+
description: `${url} at line ${line}` || "",
331+
log: [msg],
332+
time: 0,
333+
success: false,
334+
suite: [],
335+
})
320336
this.complete();
321337
return false;
322338
}
@@ -363,6 +379,6 @@ export class TestBrokerViewModel extends observable.Observable {
363379
export var mainViewModel = new TestBrokerViewModel();
364380

365381
require('application').onUncaughtError = error => {
366-
console.log("!!!!!!!!!!!!!!!!!!!!!!!error!!!!!!!!!!!!!!!!!!!!!!!!!!!");
382+
console.log("NSUTR: uncaught error");
367383
mainViewModel.error(error.message);
368384
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nativescript-unit-test-runner",
3-
"version": "0.2.0",
3+
"version": "0.2.4",
44
"description": "NativeScript unit test runner component.",
55
"main": "app.js",
66
"scripts": {

0 commit comments

Comments
 (0)