Skip to content

feat: implement unit testing with bundle #33

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 2 commits into from
Mar 19, 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
2 changes: 2 additions & 0 deletions bundle-app-root.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<Frame defaultPage="main-page" id="root-frame">
</Frame>
2 changes: 2 additions & 0 deletions bundle-app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import * as application from "tns-core-modules/application";
application.run({ moduleName: "bundle-app-root" });
55 changes: 54 additions & 1 deletion declarations.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
interface String {
declare const enum ScriptTypes {
TestType, // from tests folder
CodeUnderTestType, // from app folder
FrameworkAdapterType // from node_modules
}

interface String {
startsWith(prefix: string): boolean;
}

Expand All @@ -14,3 +20,50 @@ declare module java {
}
}

interface IHostConfiguration {
port: number;
ips: string[];
options: {
debugBrk?: boolean;
debugTransport?: boolean;
bundle?: boolean;
appDirectoryRelativePath?: string;
}
}

interface INetworkConfiguration extends IHostConfiguration {
reachableIp: string;
}

interface IKarmaContext {
files: string[];
}

interface IScriptInfo {
url: string;
localPath?: string;
contents?: string;
type?: ScriptTypes;
}

interface IKarmaHostResolver {
resolveKarmaHost(ips: string[], port: number): Promise<string>;
}

interface IKarmaConnectionService {
connect(baseUrl: string): Promise<void>;
}

interface IKarmaFilesService {
getServedFilesData(baseUrl: string, config: IHostConfiguration): Promise<IScriptInfo[]>;
}

interface ITestExecutionService {
runTests(scripts: IScriptInfo[]): ITestExecutionError[];
}

interface ITestExecutionError {
msg: string;
url: string;
line: number;
}
5 changes: 3 additions & 2 deletions lib/after-prepare.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import * as path from "path";
import * as fs from "fs";

module.exports = function ($platformsData, $testExecutionService) {
if($testExecutionService && $testExecutionService.platform) {
module.exports = function (hookArgs, $platformsData, $testExecutionService) {
const bundle = hookArgs && hookArgs.appFilesUpdaterOptions && hookArgs.appFilesUpdaterOptions.bundle;
if($testExecutionService && $testExecutionService.platform && !bundle) {
let platformData = $platformsData.getPlatformData($testExecutionService.platform),
projectFilesPath = path.join(platformData.appDestinationDirectoryPath, "app"),
packageJsonPath = path.join(projectFilesPath, 'package.json'),
Expand Down
2 changes: 1 addition & 1 deletion main-page.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Page xmlns="http://www.nativescript.org/tns.xsd" loaded="pageLoaded">
<GridLayout cssClass="landingContainer">
<Image src="~/tns_modules/nativescript-unit-test-runner/nativescript.png" stretch="none" cssClass="landingBackground"/>
<Image src="{{ imageSrc }}" stretch="none" cssClass="landingBackground"/>

<Label text="{{ serverInfo }}" cssClass="landingText"/>
</GridLayout>
Expand Down
Loading