Skip to content

Commit 9a9a46d

Browse files
author
Dimitar Tachev
authored
Merge pull request #236 from NativeScript/tachev/debug-tests
feat: add Test configurations allowing unit tests debugging
2 parents 15a77f2 + a48f783 commit 9a9a46d

File tree

5 files changed

+49
-10
lines changed

5 files changed

+49
-10
lines changed

package.json

+34-1
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,20 @@
143143
"sourceMaps": true,
144144
"watch": true
145145
},
146+
{
147+
"name": "Test on iOS",
148+
"type": "nativescript",
149+
"request": "launch",
150+
"platform": "ios",
151+
"appRoot": "${workspaceRoot}",
152+
"sourceMaps": true,
153+
"watch": false,
154+
"stopOnEntry": true,
155+
"launchTests": true,
156+
"tnsArgs": [
157+
"--justlaunch"
158+
]
159+
},
146160
{
147161
"name": "Attach on iOS",
148162
"type": "nativescript",
@@ -161,6 +175,20 @@
161175
"sourceMaps": true,
162176
"watch": true
163177
},
178+
{
179+
"name": "Test on Android",
180+
"type": "nativescript",
181+
"request": "launch",
182+
"platform": "android",
183+
"appRoot": "${workspaceRoot}",
184+
"sourceMaps": true,
185+
"watch": false,
186+
"stopOnEntry": true,
187+
"launchTests": true,
188+
"tnsArgs": [
189+
"--justlaunch"
190+
]
191+
},
164192
{
165193
"name": "Attach on Android",
166194
"type": "nativescript",
@@ -281,6 +309,11 @@
281309
"type": "object",
282310
"description": "A set of mappings for rewriting the locations of source files from what the sourcemap says, to their locations on the disk.",
283311
"default": null
312+
},
313+
"launchTests": {
314+
"type": "boolean",
315+
"description": "If true, the launch request will run the unit tests instead of the app itself.",
316+
"default": false
284317
}
285318
}
286319
},
@@ -336,4 +369,4 @@
336369
}
337370
]
338371
}
339-
}
372+
}

src/project/androidProject.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,15 @@ export class AndroidProject extends Project {
3131
return { tnsProcess: debugProcess, tnsOutputEventEmitter };
3232
}
3333

34-
public debug(options: { stopOnEntry: boolean, watch: boolean }, tnsArgs?: string[]): IDebugResult {
34+
public debug(options: { stopOnEntry: boolean, watch: boolean, launchTests: boolean }, tnsArgs?: string[]): IDebugResult {
3535
let args: string[] = [];
3636

3737
args.push(options.watch ? '--watch' : '--no-watch');
3838
if (options.stopOnEntry) { args.push('--debug-brk'); }
3939
args = args.concat(tnsArgs);
4040

41-
const debugProcess: ChildProcess = super.executeDebugCommand(args);
41+
const debugProcess: ChildProcess = options.launchTests ?
42+
super.executeTestCommand(args) : super.executeDebugCommand(args);
4243
const tnsOutputEventEmitter: EventEmitter = new EventEmitter();
4344
const shouldWaitAfterRestartMessage = semver.lt(semver.coerce(this.cliVersion), '5.1.0');
4445
const waitForRestartMessage = shouldWaitAfterRestartMessage || args.indexOf('--debug-brk') > -1;

src/project/iosProject.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,15 @@ export class IosProject extends Project {
3232
return { tnsProcess: debugProcess, tnsOutputEventEmitter };
3333
}
3434

35-
public debug(options: { stopOnEntry: boolean, watch: boolean }, tnsArgs?: string[]): IDebugResult {
35+
public debug(options: { stopOnEntry: boolean, watch: boolean, launchTests: boolean }, tnsArgs?: string[]): IDebugResult {
3636
let args: string[] = [];
3737

3838
args.push(options.watch ? '--watch' : '--no-watch');
3939
if (options.stopOnEntry) { args.push('--debug-brk'); }
4040
args = args.concat(tnsArgs);
41+
const debugProcess: ChildProcess = options.launchTests ?
42+
super.executeTestCommand(args) : super.executeDebugCommand(args);
4143

42-
const debugProcess: ChildProcess = super.executeDebugCommand(args);
4344
const tnsOutputEventEmitter: EventEmitter = new EventEmitter();
4445

4546
this.configureReadyEvent(debugProcess.stdout, tnsOutputEventEmitter);

src/project/project.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export abstract class Project {
2727

2828
public abstract attach(tnsArgs?: string[]): IDebugResult;
2929

30-
public abstract debug(options: { stopOnEntry: boolean, watch: boolean }, tnsArgs?: string[]): IDebugResult;
30+
public abstract debug(options: { stopOnEntry: boolean, watch: boolean, launchTests: boolean }, tnsArgs?: string[]): IDebugResult;
3131

3232
protected configureReadyEvent(readableStream: stream.Readable, eventEmitter: EventEmitter): void {
3333
new scanner.StringMatchingScanner(readableStream).onEveryMatch('TypeScript compiler failed', () => {
@@ -42,4 +42,8 @@ export abstract class Project {
4242
protected executeDebugCommand(args: string[]): ChildProcess {
4343
return this._cli.execute(['debug', this.platformName()].concat(args), this._appRoot);
4444
}
45+
46+
protected executeTestCommand(args: string[]): ChildProcess {
47+
return this._cli.execute(['test', this.platformName()].concat(args), this._appRoot);
48+
}
4549
}

src/services/buildService.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ export class BuildService {
5656
}
5757
}
5858

59-
cliCommand = project.debug({ stopOnEntry: args.stopOnEntry, watch: args.watch }, tnsArgs);
59+
cliCommand = project.debug({ stopOnEntry: args.stopOnEntry, watch: args.watch, launchTests: args.launchTests }, tnsArgs);
6060
} else if (args.request === 'attach') {
6161
cliCommand = project.attach(args.tnsArgs);
6262
}
6363

64-
return new Promise<string | number> ((res, rej) => {
64+
return new Promise<string | number>((res, rej) => {
6565
if (cliCommand.tnsProcess) {
6666
this._tnsProcess = cliCommand.tnsProcess;
6767
cliCommand.tnsProcess.stdout.on('data', (data) => { this._logger.log(data.toString()); });
@@ -109,7 +109,7 @@ export class BuildService {
109109
const teamIdArgIndex = tnsArgs.indexOf('--teamId');
110110

111111
if (teamIdArgIndex > 0 && teamIdArgIndex + 1 < tnsArgs.length) {
112-
return tnsArgs[ teamIdArgIndex + 1 ];
112+
return tnsArgs[teamIdArgIndex + 1];
113113
}
114114
}
115115

@@ -128,7 +128,7 @@ export class BuildService {
128128
const xcconfigFile = path.join(appRoot, 'App_Resources/iOS/build.xcconfig');
129129

130130
if (fs.existsSync(xcconfigFile)) {
131-
const text = fs.readFileSync(xcconfigFile, { encoding: 'utf8'});
131+
const text = fs.readFileSync(xcconfigFile, { encoding: 'utf8' });
132132
let teamId: string;
133133

134134
text.split(/\r?\n/).forEach((line) => {

0 commit comments

Comments
 (0)