appTestTs

This commit is contained in:
Vasil Chimev
2019-11-14 10:07:45 +02:00
parent 7b319626aa
commit 8136302611
7 changed files with 176 additions and 8 deletions

View File

@@ -6,6 +6,7 @@ platforms/
# NativeScript Template
*.js.map
*.js
!karma.conf.js
!webpack.config.js
# Logs

View File

@@ -0,0 +1,9 @@
import { EventData } from "tns-core-modules/data/observable";
import { Page } from "tns-core-modules/ui/page";
import { HelloWorldModel } from "./main-view-model";
export function navigatingTo(args: EventData) {
const page = <Page>args.object;
page.bindingContext = new HelloWorldModel();
}

View File

@@ -0,0 +1,5 @@
<Page xmlns="http://schemas.nativescript.org/tns.xsd" id="page" navigatingTo="navigatingTo">
<StackLayout id="stack">
<Label id="label" text="{{ message }}"></Label>
</StackLayout>
</Page>

View File

@@ -0,0 +1,5 @@
<Page xmlns="http://schemas.nativescript.org/tns.xsd" id="page">
<StackLayout id="stack">
<Label id="label" text="Test Page Stack Label"></Label>
</StackLayout>
</Page>

View File

@@ -1,9 +1,47 @@
// A sample Mocha test
describe('Array', function () {
describe('#indexOf()', function () {
it('should return -1 when the value is not present', function () {
assert.equal(-1, [1, 2, 3].indexOf(5));
assert.equal(-1, [1, 2, 3].indexOf(0));
});
import { Builder, Label, Frame } from "@nativescript/core/ui";
import { navigateToModule } from "@nativescript/core/testing/ui-helper";
import { assert } from "@nativescript/core/testing/tk-unit";
// function assert(test: any, message?: string) {
// if (!test) {
// throw new Error(message);
// }
// }
const snippet = `
<StackLayout id="stack">
<Label id="label" text="Label"></Label>
</StackLayout>`
describe("---> describe", function () {
it("---> snippet", function () {
const rootView = Builder.parse(snippet);
const label = <Label>rootView.getViewById("label");
const actualText = label.text;
const expectedText = "Labe";
assert(actualText === expectedText, `Actual: ${actualText}, Expected: ${expectedText}`);
});
it("---> page", function () {
const rootView = Builder.load("test-page");
const label = <Label>rootView.getViewById("label");
const actualText = label.text;
const expectedText = "Test Page Stack Labe";
assert(actualText === expectedText, `Actual: ${actualText}, Expected: ${expectedText}`);
});
it("---> module", function () {
navigateToModule("test-module");
const label = <Label>Frame.topmost().getViewById("label");
const actualText = label.text;
const expectedText = "42 taps lef";
assert(actualText === expectedText, `Actual: ${actualText}, Expected: ${expectedText}`);
});
});

109
e2e/appTestTs/karma.conf.js Normal file
View File

@@ -0,0 +1,109 @@
module.exports = function (config) {
const options = {
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['mocha', 'chai'],
// list of files / patterns to load in the browser
files: ['app/tests/**/*.ts'],
// list of files to exclude
exclude: [
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: [],
customLaunchers: {
android: {
base: 'NS',
platform: 'android'
},
ios: {
base: 'NS',
platform: 'ios'
},
ios_simulator: {
base: 'NS',
platform: 'ios',
arguments: ['--emulator']
}
},
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false
};
setWebpackPreprocessor(config, options);
setWebpack(config, options);
config.set(options);
}
function setWebpackPreprocessor(config, options) {
if (config && config.bundle) {
if (!options.preprocessors) {
options.preprocessors = {};
}
options.files.forEach(file => {
if (!options.preprocessors[file]) {
options.preprocessors[file] = [];
}
options.preprocessors[file].push('webpack');
});
}
}
function setWebpack(config, options) {
if (config && config.bundle) {
const env = {};
env[config.platform] = true;
env.sourceMap = config.debugBrk;
env.appPath = config.appPath;
options.webpack = require('./webpack.config')(env);
delete options.webpack.entry;
delete options.webpack.output.libraryTarget;
const invalidPluginsForUnitTesting = ["GenerateBundleStarterPlugin", "GenerateNativeScriptEntryPointsPlugin"];
options.webpack.plugins = options.webpack.plugins.filter(p => !invalidPluginsForUnitTesting.includes(p.constructor.name));
}
}

View File

@@ -13,9 +13,10 @@
"license": "SEE LICENSE IN <your-license-filename>",
"repository": "<fill-your-repository-here>",
"dependencies": {
"@nativescript/core": "file:../../../../Downloads/nativescript-core-6.3.0.tgz",
"@nativescript/theme": "~2.2.0",
"nativescript-unit-test-runner": "^0.7.0",
"tns-core-modules": "~6.2.0"
"tns-core-modules": "file:../../../../Downloads/tns-core-modules-6.3.0.tgz"
},
"devDependencies": {
"@types/karma-chai": "0.1.2",