Skip to content

Commit fe6538d

Browse files
committed
feat: implement unit testing with bundle
NativeScript/nativescript-cli#4392
1 parent 98f30a7 commit fe6538d

11 files changed

+405
-290
lines changed

bundle-app-root.xml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<Frame defaultPage="main-page" id="root-frame">
2+
</Frame>

bundle-app.ts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import * as application from "tns-core-modules/application";
2+
application.run({ moduleName: "bundle-app-root" });

declarations.d.ts

+54-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
interface String {
1+
declare const enum ScriptTypes {
2+
TestType, // from tests folder
3+
CodeUnderTestType, // from app folder
4+
FrameworkAdapterType // from node_modules
5+
}
6+
7+
interface String {
28
startsWith(prefix: string): boolean;
39
}
410

@@ -14,3 +20,50 @@ declare module java {
1420
}
1521
}
1622

23+
interface IHostConfiguration {
24+
port: number;
25+
ips: string[];
26+
options: {
27+
debugBrk?: boolean;
28+
debugTransport?: boolean;
29+
bundle?: boolean;
30+
appDirectoryRelativePath?: string;
31+
}
32+
}
33+
34+
interface INetworkConfiguration extends IHostConfiguration {
35+
reachableIp: string;
36+
}
37+
38+
interface IKarmaContext {
39+
files: string[];
40+
}
41+
42+
interface IScriptInfo {
43+
url: string;
44+
localPath?: string;
45+
contents?: string;
46+
type?: ScriptTypes;
47+
}
48+
49+
interface IKarmaHostResolver {
50+
resolveKarmaHost(ips: string[], port: number): Promise<string>;
51+
}
52+
53+
interface IKarmaConnectionService {
54+
connect(baseUrl: string): Promise<void>;
55+
}
56+
57+
interface IKarmaFilesService {
58+
getServedFilesData(baseUrl: string, config: IHostConfiguration): Promise<IScriptInfo[]>;
59+
}
60+
61+
interface ITestExecutionService {
62+
runTests(scripts: IScriptInfo[]): ITestExecutionError[];
63+
}
64+
65+
interface ITestExecutionError {
66+
msg: string;
67+
url: string;
68+
line: number;
69+
}

lib/after-prepare.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import * as path from "path";
22
import * as fs from "fs";
33

4-
module.exports = function ($platformsData, $testExecutionService) {
5-
if($testExecutionService && $testExecutionService.platform) {
4+
module.exports = function ($platformsData, $testExecutionService, $options) {
5+
if($testExecutionService && $testExecutionService.platform && !$options.bundle) {
66
let platformData = $platformsData.getPlatformData($testExecutionService.platform),
77
projectFilesPath = path.join(platformData.appDestinationDirectoryPath, "app"),
88
packageJsonPath = path.join(projectFilesPath, 'package.json'),

main-page.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Page xmlns="http://www.nativescript.org/tns.xsd" loaded="pageLoaded">
22
<GridLayout cssClass="landingContainer">
3-
<Image src="~/tns_modules/nativescript-unit-test-runner/nativescript.png" stretch="none" cssClass="landingBackground"/>
3+
<Image src="{{ imageSrc }}" stretch="none" cssClass="landingBackground"/>
44

55
<Label text="{{ serverInfo }}" cssClass="landingText"/>
66
</GridLayout>

0 commit comments

Comments
 (0)