Skip to content

Commit 2d6047e

Browse files
committed
feat: add Test configurations allowing the unit tests debugging
1 parent 551fa25 commit 2d6047e

File tree

5 files changed

+49
-11
lines changed

5 files changed

+49
-11
lines changed

package.json

Lines changed: 34 additions & 1 deletion
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

Lines changed: 3 additions & 2 deletions
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

Lines changed: 3 additions & 2 deletions
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

Lines changed: 5 additions & 1 deletion
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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ export class BuildService {
3636
this._logger.log('[NSDebugAdapter] Running tns command...\n');
3737

3838
let cliCommand: IDebugResult;
39-
4039
if (args.request === 'launch') {
4140
let tnsArgs = args.tnsArgs;
4241

@@ -56,12 +55,12 @@ export class BuildService {
5655
}
5756
}
5857

59-
cliCommand = project.debug({ stopOnEntry: args.stopOnEntry, watch: args.watch }, tnsArgs);
58+
cliCommand = project.debug({ stopOnEntry: args.stopOnEntry, watch: args.watch, launchTests: args.launchTests }, tnsArgs);
6059
} else if (args.request === 'attach') {
6160
cliCommand = project.attach(args.tnsArgs);
6261
}
6362

64-
return new Promise<string | number> ((res, rej) => {
63+
return new Promise<string | number>((res, rej) => {
6564
if (cliCommand.tnsProcess) {
6665
this._tnsProcess = cliCommand.tnsProcess;
6766
cliCommand.tnsProcess.stdout.on('data', (data) => { this._logger.log(data.toString()); });
@@ -109,7 +108,7 @@ export class BuildService {
109108
const teamIdArgIndex = tnsArgs.indexOf('--teamId');
110109

111110
if (teamIdArgIndex > 0 && teamIdArgIndex + 1 < tnsArgs.length) {
112-
return tnsArgs[ teamIdArgIndex + 1 ];
111+
return tnsArgs[teamIdArgIndex + 1];
113112
}
114113
}
115114

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

130129
if (fs.existsSync(xcconfigFile)) {
131-
const text = fs.readFileSync(xcconfigFile, { encoding: 'utf8'});
130+
const text = fs.readFileSync(xcconfigFile, { encoding: 'utf8' });
132131
let teamId: string;
133132

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

0 commit comments

Comments
 (0)