Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: NativeScript/nativescript-unit-test-runner
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.0.0
Choose a base ref
...
head repository: NativeScript/nativescript-unit-test-runner
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v3.0.0
Choose a head ref

Commits on May 11, 2021

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    e80dd39 View commit details
  2. chore: 2.0.1

    NathanWalker committed May 11, 2021
    Copy the full SHA
    48a002f View commit details
  3. chore: 2.0.2

    NathanWalker committed May 11, 2021
    Copy the full SHA
    2ada8e2 View commit details
  4. Copy the full SHA
    e7b19d8 View commit details
  5. chore: 2.0.3

    NathanWalker committed May 11, 2021
    Copy the full SHA
    719a7e1 View commit details

Commits on May 13, 2021

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    e3ee135 View commit details
  2. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    6842f96 View commit details
  3. chore: 2.0.4

    NathanWalker committed May 13, 2021
    Copy the full SHA
    4327c48 View commit details

Commits on Jun 2, 2021

  1. Copy the full SHA
    0eb7184 View commit details
  2. chore: 2.0.5

    NathanWalker committed Jun 2, 2021
    Copy the full SHA
    a9d24d1 View commit details

Commits on Nov 23, 2021

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    4ba5ee9 View commit details
  2. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    97eea37 View commit details
  3. chore: wip

    edusperoni authored and NathanWalker committed Nov 23, 2021
    Copy the full SHA
    754388c View commit details
  4. feat: better API

    edusperoni authored and NathanWalker committed Nov 23, 2021
    Copy the full SHA
    145f8eb View commit details
  5. feat: add --env.codeCoverage

    edusperoni authored and NathanWalker committed Nov 23, 2021
    Copy the full SHA
    877cc3c View commit details
  6. chore: 3.0.0-rc.0

    NathanWalker committed Nov 23, 2021
    Copy the full SHA
    f2ab742 View commit details
  7. chore: 3.0.0-rc.1

    NathanWalker committed Nov 23, 2021
    Copy the full SHA
    82d7ef0 View commit details
  8. chore: npmignore

    NathanWalker committed Nov 23, 2021
    Copy the full SHA
    c672f88 View commit details
  9. chore: cleanup

    edusperoni authored and NathanWalker committed Nov 23, 2021
    Copy the full SHA
    7a8efea View commit details
  10. chore: error message failover

    edusperoni authored and NathanWalker committed Nov 23, 2021
    Copy the full SHA
    42504ef View commit details
  11. Copy the full SHA
    8212103 View commit details
  12. chore: add deprecation warning

    edusperoni authored and NathanWalker committed Nov 23, 2021
    Copy the full SHA
    93c5892 View commit details
  13. fix: getTestEntrypoint

    NathanWalker committed Nov 23, 2021
    Copy the full SHA
    9e4b885 View commit details
  14. chore: 3.0.0-rc.3

    NathanWalker committed Nov 23, 2021
    Copy the full SHA
    e786a23 View commit details
  15. chore: 3.0.0

    NathanWalker committed Nov 23, 2021
    Copy the full SHA
    ca0cee3 View commit details
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ test-app/
*.js
*.js.map
!nativescript.webpack.js
!nativescript.webpack.compat.js
!loaders/unit-test-loader.js

coverage
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -11,7 +11,9 @@ tscommand.tmp.txt
.tscache/
.vscode/
*.ts
!app/main.d.ts
*.js.map
definitions
platforms/android/*
!platforms/android/*.aar
*.tgz
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# [3.0.0](https://github.com/NativeScript/nativescript-unit-test-runner/compare/v2.0.0...v3.0.0) (2021-11-23)


### Bug Fixes

* default ip for android emulators ([#52](https://github.com/NativeScript/nativescript-unit-test-runner/issues/52)) ([97eea37](https://github.com/NativeScript/nativescript-unit-test-runner/commit/97eea37eb7d2a920af0d85509676674d48b6d079))
* angular updates ([0eb7184](https://github.com/NativeScript/nativescript-unit-test-runner/commit/0eb71849f96cdafaa84077eb665f3c60daaf77eb))
* ensure compatibility running test-loader last ([#49](https://github.com/NativeScript/nativescript-unit-test-runner/issues/49)) ([6842f96](https://github.com/NativeScript/nativescript-unit-test-runner/commit/6842f96be830d8eec667b06d8e8fc6403e7f1b18))
* getTestEntrypoint ([9e4b885](https://github.com/NativeScript/nativescript-unit-test-runner/commit/9e4b88567ce561839acdcb0802fee45869cdde8d))
* replace all separators with / ([#50](https://github.com/NativeScript/nativescript-unit-test-runner/issues/50)) ([4ba5ee9](https://github.com/NativeScript/nativescript-unit-test-runner/commit/4ba5ee9ff3a2a1939655301b301903c29c51844e))
* update socket events for karma 6 ([e7b19d8](https://github.com/NativeScript/nativescript-unit-test-runner/commit/e7b19d819ed3ff77ad7ec79b1d424460731e40d7))


### Features

* add --env.codeCoverage ([877cc3c](https://github.com/NativeScript/nativescript-unit-test-runner/commit/877cc3c12c6a138ee3e4f9d0bb2d2cb26310dfaa))
* add unitTesting gradle variable ([#46](https://github.com/NativeScript/nativescript-unit-test-runner/issues/46)) ([e80dd39](https://github.com/NativeScript/nativescript-unit-test-runner/commit/e80dd39cfd0c9869413838f58b68f1630bead63b))
* better API ([145f8eb](https://github.com/NativeScript/nativescript-unit-test-runner/commit/145f8ebc5393bb766059b7a995a47861d21c83d0))
* keep compatibility with test-runner v2 ([8212103](https://github.com/NativeScript/nativescript-unit-test-runner/commit/8212103bd5595bddc4e5f08119cec6f24d2e02da))
* support keeping app open after run via --env.stayOpen ([#48](https://github.com/NativeScript/nativescript-unit-test-runner/issues/48)) ([e3ee135](https://github.com/NativeScript/nativescript-unit-test-runner/commit/e3ee135782577aa3d8920df112cf100b74c58655))
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Unit test runner for NativeScript
=================================

Refer to the documentation of NativeScript CLI's `tns test init` command for usage.
Refer to the documentation of NativeScript CLI's `ns test init` command for usage.

If you encounter an issue, please log it at https://github.com/NativeScript/nativescript-cli/
12 changes: 10 additions & 2 deletions app/app.css
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
.landingContainer {
background-color: #65ADF1;
background-color: white;
}

.landingBackground {
horizontal-align: center;
vertical-align: top;
opacity: 0.3;
}

.landingText {
@@ -22,6 +21,7 @@
.statusBar {
background-color: #65ADF1;
color: white;
padding: 10;
}

.statusText {
@@ -69,5 +69,13 @@

.failedTestDetails {
font-size: 10;
color: black;
}

.btn-primary {
background-color: #65ADF1;
padding: 8 5 8 5;
width: 250;
color: white;
border-radius: 6;
}
6 changes: 3 additions & 3 deletions app/bundle-main-page.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Page xmlns="http://www.nativescript.org/tns.xsd" loaded="pageLoaded">
<GridLayout cssClass="landingContainer">
<Image src="{{ imageSrc }}" stretch="none" cssClass="landingBackground"/>
<GridLayout class="landingContainer">
<Image src="{{ imageSrc }}" stretch="aspectFit" class="landingBackground" width="150"/>

<Label text="{{ serverInfo }}" cssClass="landingText"/>
<Label text="{{ serverInfo }}" class="landingText"/>
</GridLayout>
</Page>
4 changes: 2 additions & 2 deletions app/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="{{ imageSrc }}" stretch="none" class="landingBackground"/>
<GridLayout class="landingContainer">
<Image src="{{ imageSrc }}" stretch="aspectFit" class="landingBackground" width="150"/>

<Label text="{{ serverInfo }}" class="landingText"/>
</GridLayout>
60 changes: 47 additions & 13 deletions app/main-view-model.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
/// <reference path="../declarations.d.ts"/>
import { Observable, ObservableArray, Http, Device, Frame } from "@nativescript/core";
import { Observable, ObservableArray, Http, Device, Frame, isAndroid } from "@nativescript/core";
import { KarmaHostResolver } from './services/karma-host-resolver';
import { KarmaFilesService } from './services/karma-files-service';
import { TestExecutionService } from './services/test-execution-service';
import { killProcess } from "./stop-process";
import { executeWebpackTests } from "./services/webpack-test-runner";

declare var global: any;
declare const __TEST_RUNNER_STAY_OPEN__: boolean;

function enableSocketIoDebugging() {
console.log('enabling socket.io debugging');
@@ -19,6 +21,17 @@ function enableSocketIoDebugging() {

var config: INetworkConfiguration = require('../config');
config.options = config.options || {};
// For whatever reason, Android emulators sometime struggle to find a
// reachable host ip and make a successful call for the `context.json` file.
// This happens in the test runner, even though mobile browsers can make successful calls to the
// already discovered ips. According to
// https://developer.android.com/studio/run/emulator-networking#networkaddresses
// ip addr: `10.0.2.2` is a special alias to your host loopback interface
// (i.e., 127.0.0.1 on your development machine)
// adding this ipaddr eases the struggle. (no effect on actual devices)
if (isAndroid)
config.ips = (config.ips || []).concat(['10.0.2.2'])

if (!config.options.appDirectoryRelativePath) {
config.options.appDirectoryRelativePath = "app";
}
@@ -114,6 +127,12 @@ export class TestBrokerViewModel extends Observable {
const errors = this.testExecutionService.runTests(scripts);
errors.forEach(err => this.error(err.msg, err.url, err.line));

try {
executeWebpackTests();
} catch (e) {
this.error(`${e?.message || e}`);
}

if (!this.hasError) {
console.log('NSUTR: beginning test run');
if (config.options.debugBrk) {
@@ -133,13 +152,15 @@ export class TestBrokerViewModel extends Observable {
this.emitInfoToSocketIfNeeded(data);
this.emitStartToSocketIfNeeded(data);

this.updateView({
testsRunning: true,
testsPassed: 0,
testsFailed: 0,
testsRan: 0,
testsTotal: data.total
});
if (Object.hasOwnProperty.call(data, "total")) { // data.total only appears when tests are booting up and represent the total number of tests
this.updateView({
testsRunning: true,
testsPassed: 0,
testsFailed: 0,
testsRan: 0,
testsTotal: data.total
});
}
}

public result(data) {
@@ -161,11 +182,20 @@ export class TestBrokerViewModel extends Observable {

delete this.start;

this.emitToSocket('complete', data || {}, () => {
let acknowledged = false;
const ackFn = () => {
if (acknowledged) {
return;
}
acknowledged = true;
console.log('NSUTR: completeAck');
this.emitToSocket('disconnect');
setTimeout(() => killProcess(), 500);
});
if (typeof __TEST_RUNNER_STAY_OPEN__ === 'undefined' || !__TEST_RUNNER_STAY_OPEN__) {
setTimeout(() => killProcess(), 500);
}
};
this.emitToSocket('complete', data || {}, ackFn);
setTimeout(ackFn, 1000); // acknowledge is no longer sent by the karma server, so we use a timeout to ensure it runs
}

public error(msg: string, url?: string, line?: number) {
@@ -202,7 +232,7 @@ export class TestBrokerViewModel extends Observable {
}
};

this.updateView({ serverInfo: `connecting to ${this.baseUrl}`});
this.updateView({ serverInfo: `connected to ${this.baseUrl}` });
let io = require('../socket.io');
const socket = this.socket = io.connect(this.baseUrl, { forceBase64: true });

@@ -236,6 +266,10 @@ export class TestBrokerViewModel extends Observable {

private emitToSocket(...args: any[]) {
if (this.karmaRequestedRun) {
if (args.length > 0 && args[0] === 'disconnect') {
this.socket.disconnect();
return;
}
this.socket.emit.apply(this.socket, arguments);
}
}
@@ -246,7 +280,7 @@ export class TestBrokerViewModel extends Observable {
this.startEmitted = true;
}
}

private emitInfoToSocketIfNeeded(data) {
if (this.startEmitted) {
this.emitToSocket('info', data);
5 changes: 5 additions & 0 deletions app/main.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface RunTestAppOptions {
runTests?: () => unknown
}

export function runTestApp(options?: RunTestAppOptions);
21 changes: 21 additions & 0 deletions app/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
declare let require: any;

import { Application } from "@nativescript/core";
import "./app.css";
import { registerTestRunner } from "./services/webpack-test-runner";

const context = require.context("./", true, /.*\.(js|css|xml)/);
global.registerWebpackModules(context);

export interface RunTestAppOptions {
runTests?: () => unknown;
}

export function runTestApp(options: RunTestAppOptions = {}) {
if (options?.runTests) {
registerTestRunner(() => {
options.runTests();
});
}
Application.run({ moduleName: "bundle-app-root" });
}
8 changes: 4 additions & 4 deletions app/run-details.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<Page xmlns="http://www.nativescript.org/tns.xsd" loaded="pageLoaded">
<ListView items="{{ testResults }}">
<ListView.itemTemplate>
<StackLayout cssClass="{{ success, success ? 'passedTest' : 'failedTest' }} ">
<StackLayout class="{{ success, success ? 'passedTest' : 'failedTest' }} " padding="10">
<Label
text="{{ description }}"
cssClass="{{ success, success ? 'passedTestTitle' : 'failedTestTitle' }}"/>
class="{{ success, success ? 'passedTestTitle' : 'failedTestTitle' }}"/>
<Label
text="{{ time, 'time: ' + time + 'ms' }}"
cssClass="{{ success, success ? 'passedTestDetails' : 'failedTestDetails' }}"/>
class="{{ success, success ? 'passedTestDetails' : 'failedTestDetails' }}"/>
<TextView
text="{{ log }}"
visibility="{{ success, success ? 'collapsed' : 'visible' }}"
editable="false"
cssClass="failedTestDetails"/>
class="failedTestDetails"/>
</StackLayout>
</ListView.itemTemplate>
</ListView>
10 changes: 10 additions & 0 deletions app/services/webpack-test-runner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
let runTests: () => unknown;

export function registerTestRunner(testRunner: () => unknown) {
runTests = testRunner;
}


export function executeWebpackTests() {
runTests?.();
}
2 changes: 1 addition & 1 deletion app/test-run-page.xml
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@
</StackLayout>
</StackLayout>

<Button text="View Test Run Details" tap="{{ viewTestRunDetails }}" row="3"/>
<Button text="View Test Run Details" tap="{{ viewTestRunDetails }}" row="3" class="btn-primary" marginBottom="20"/>

<GridLayout row="4" class="statusBar">
<Label text="{{ serverInfo }}" class="statusText"/>
8 changes: 8 additions & 0 deletions lib/before-build-task-args.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

module.exports = function (hookArgs, $options) {
if(!hookArgs || !hookArgs.args) {
return;
}
const unitTesting = $options && $options.env && $options.env.unitTesting || false;
hookArgs.args.push(`-PunitTesting=${!!unitTesting}`);
};
29 changes: 18 additions & 11 deletions loaders/unit-test-loader.js
Original file line number Diff line number Diff line change
@@ -11,19 +11,26 @@ module.exports = function unitTestLoader(source, map) {
const opts = this.getOptions();
const testPathRelativeToAppPath = relative(opts.appPath, this.resourcePath);
const ext = extname(testPathRelativeToAppPath);
const loadPath = testPathRelativeToAppPath.replace(ext, "").replace(sep, '/'); // use forward slash always
const loadPath = testPathRelativeToAppPath.replace(ext, "").split(sep).join('/'); // use forward slash always

source = `
// UNIT-TEST-LOADER START
try {
console.log('Loading test: ${loadPath}');
global.loadModule('${loadPath}');
} catch(err) {
console.log('Failed to load test ${loadPath}.', err)
throw new Error('Failed to load test ${loadPath}.');
if (loadPath) {
const platformExt = loadPath.split('.').slice(-1)[0];
if (['ios', 'android'].includes(platformExt) && opts.platform !== platformExt) {
source = '';
} else {
source = `
// UNIT-TEST-LOADER START
try {
console.log('Loading test: ${loadPath}');
global.loadModule('${loadPath}');
} catch(err) {
console.log('Failed to load test ${loadPath}.', err)
throw new Error('Failed to load test ${loadPath}.');
}
// UNIT-TEST-LOADER END
`;
}
// UNIT-TEST-LOADER END
`;
}

this.callback(null, source, map);
};
Loading