Skip to content

feat: add Test configurations allowing unit tests debugging #236

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,20 @@
"sourceMaps": true,
"watch": true
},
{
"name": "Test on iOS",
"type": "nativescript",
"request": "launch",
"platform": "ios",
"appRoot": "${workspaceRoot}",
"sourceMaps": true,
"watch": false,
"stopOnEntry": true,
"launchTests": true,
"tnsArgs": [
"--justlaunch"
]
},
{
"name": "Attach on iOS",
"type": "nativescript",
Expand All @@ -161,6 +175,20 @@
"sourceMaps": true,
"watch": true
},
{
"name": "Test on Android",
"type": "nativescript",
"request": "launch",
"platform": "android",
"appRoot": "${workspaceRoot}",
"sourceMaps": true,
"watch": false,
"stopOnEntry": true,
"launchTests": true,
"tnsArgs": [
"--justlaunch"
]
},
{
"name": "Attach on Android",
"type": "nativescript",
Expand Down Expand Up @@ -281,6 +309,11 @@
"type": "object",
"description": "A set of mappings for rewriting the locations of source files from what the sourcemap says, to their locations on the disk.",
"default": null
},
"launchTests": {
"type": "boolean",
"description": "If true, the launch request will run the unit tests instead of the app itself.",
"default": false
}
}
},
Expand Down Expand Up @@ -336,4 +369,4 @@
}
]
}
}
}
5 changes: 3 additions & 2 deletions src/project/androidProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@ export class AndroidProject extends Project {
return { tnsProcess: debugProcess, tnsOutputEventEmitter };
}

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

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

const debugProcess: ChildProcess = super.executeDebugCommand(args);
const debugProcess: ChildProcess = options.launchTests ?
super.executeTestCommand(args) : super.executeDebugCommand(args);
const tnsOutputEventEmitter: EventEmitter = new EventEmitter();
const shouldWaitAfterRestartMessage = semver.lt(semver.coerce(this.cliVersion), '5.1.0');
const waitForRestartMessage = shouldWaitAfterRestartMessage || args.indexOf('--debug-brk') > -1;
Expand Down
5 changes: 3 additions & 2 deletions src/project/iosProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ export class IosProject extends Project {
return { tnsProcess: debugProcess, tnsOutputEventEmitter };
}

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

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

const debugProcess: ChildProcess = super.executeDebugCommand(args);
const tnsOutputEventEmitter: EventEmitter = new EventEmitter();

this.configureReadyEvent(debugProcess.stdout, tnsOutputEventEmitter);
Expand Down
6 changes: 5 additions & 1 deletion src/project/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export abstract class Project {

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

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

protected configureReadyEvent(readableStream: stream.Readable, eventEmitter: EventEmitter): void {
new scanner.StringMatchingScanner(readableStream).onEveryMatch('TypeScript compiler failed', () => {
Expand All @@ -42,4 +42,8 @@ export abstract class Project {
protected executeDebugCommand(args: string[]): ChildProcess {
return this._cli.execute(['debug', this.platformName()].concat(args), this._appRoot);
}

protected executeTestCommand(args: string[]): ChildProcess {
return this._cli.execute(['test', this.platformName()].concat(args), this._appRoot);
}
}
8 changes: 4 additions & 4 deletions src/services/buildService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ export class BuildService {
}
}

cliCommand = project.debug({ stopOnEntry: args.stopOnEntry, watch: args.watch }, tnsArgs);
cliCommand = project.debug({ stopOnEntry: args.stopOnEntry, watch: args.watch, launchTests: args.launchTests }, tnsArgs);
} else if (args.request === 'attach') {
cliCommand = project.attach(args.tnsArgs);
}

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

if (teamIdArgIndex > 0 && teamIdArgIndex + 1 < tnsArgs.length) {
return tnsArgs[ teamIdArgIndex + 1 ];
return tnsArgs[teamIdArgIndex + 1];
}
}

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

if (fs.existsSync(xcconfigFile)) {
const text = fs.readFileSync(xcconfigFile, { encoding: 'utf8'});
const text = fs.readFileSync(xcconfigFile, { encoding: 'utf8' });
let teamId: string;

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