mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 20:11:24 +08:00
Start nodejs test suite to avoid testing non-UI stuff with a real device.
1. Place tests in ./node-tests 2. Add chai, mocha, grunt-simple-mocha dev dependencies 3. Run it all with the grunt node-tests task.
This commit is contained in:
39
gruntfile.js
39
gruntfile.js
@ -142,6 +142,12 @@ module.exports = function(grunt) {
|
||||
]
|
||||
};
|
||||
|
||||
var nodeTestEnv = JSON.parse(JSON.stringify(process.env));
|
||||
nodeTestEnv['NODE_PATH'] = localCfg.outModulesDir;
|
||||
|
||||
localCfg.nodeTestsDir = pathModule.join(localCfg.outModulesDir, 'node-tests');
|
||||
|
||||
|
||||
localCfg.mainPackageContent = grunt.file.readJSON(localCfg.packageJsonFilePath);
|
||||
localCfg.packageVersion = getPackageVersion(localCfg.packageJsonFilePath);
|
||||
localCfg.commitSHA = getCommitSha();
|
||||
@ -180,6 +186,9 @@ module.exports = function(grunt) {
|
||||
],
|
||||
cwd: localCfg.outModulesDir
|
||||
},
|
||||
nodeTests: {
|
||||
src: localCfg.nodeTestsDir,
|
||||
},
|
||||
readyAppFiles: {
|
||||
src: [localCfg.outModulesDir + "/apps/**"]
|
||||
}
|
||||
@ -302,6 +311,24 @@ module.exports = function(grunt) {
|
||||
compiler: "node_modules/typescript/bin/tsc",
|
||||
noEmitOnError: true
|
||||
}
|
||||
},
|
||||
buildNodeTests: {
|
||||
src: [
|
||||
'js-libs/easysax/**/*.ts',
|
||||
'xml/**/*.ts',
|
||||
'node-tests/**/*.ts',
|
||||
],
|
||||
outDir: localCfg.outModulesDir,
|
||||
options: {
|
||||
fast: 'never',
|
||||
module: "commonjs",
|
||||
target: "es5",
|
||||
sourceMap: false,
|
||||
declaration: false,
|
||||
removeComments: "<%= !grunt.option('leavecomments') || '' %>",
|
||||
compiler: "node_modules/typescript/bin/tsc",
|
||||
noEmitOnError: true
|
||||
}
|
||||
}
|
||||
},
|
||||
tslint: {
|
||||
@ -348,6 +375,11 @@ module.exports = function(grunt) {
|
||||
options: {
|
||||
callback: assignGitSHA
|
||||
}
|
||||
},
|
||||
},
|
||||
simplemocha: {
|
||||
node: {
|
||||
src: localCfg.nodeTestsDir + '/**/*.js'
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -359,6 +391,7 @@ module.exports = function(grunt) {
|
||||
grunt.loadNpmTasks("grunt-tslint");
|
||||
grunt.loadNpmTasks("grunt-multi-dest");
|
||||
grunt.loadNpmTasks("grunt-shell");
|
||||
grunt.loadNpmTasks("grunt-simple-mocha");
|
||||
|
||||
var cloneTasks = function(originalTasks, taskNameSuffix)
|
||||
{
|
||||
@ -487,4 +520,10 @@ module.exports = function(grunt) {
|
||||
"pack-definitions",
|
||||
"get-ready-packages"
|
||||
]));
|
||||
|
||||
grunt.registerTask("node-tests", [
|
||||
"clean:nodeTests",
|
||||
"ts:buildNodeTests",
|
||||
"simplemocha:node",
|
||||
]);
|
||||
};
|
||||
|
284
node-tests/definitions/chai.d.ts
vendored
Normal file
284
node-tests/definitions/chai.d.ts
vendored
Normal file
@ -0,0 +1,284 @@
|
||||
|
||||
// Type definitions for chai 1.7.2
|
||||
// Project: http://chaijs.com/
|
||||
// Definitions by: Jed Hunsaker <https://github.com/jedhunsaker/>, Bart van der Schoor <https://github.com/Bartvds>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
declare module chai {
|
||||
export class AssertionError {
|
||||
constructor(message: string, _props?: any, ssf?: Function);
|
||||
name: string;
|
||||
message: string;
|
||||
showDiff: boolean;
|
||||
stack: string;
|
||||
}
|
||||
|
||||
function expect(target: any, message?: string): Expect;
|
||||
|
||||
export var assert: Assert;
|
||||
export var config: Config;
|
||||
|
||||
export interface Config {
|
||||
includeStack: boolean;
|
||||
}
|
||||
|
||||
// Provides a way to extend the internals of Chai
|
||||
function use(fn: (chai: any, utils: any) => void): any;
|
||||
|
||||
interface ExpectStatic {
|
||||
(target: any): Expect;
|
||||
}
|
||||
|
||||
interface Assertions {
|
||||
attr(name: string, value?: string): any;
|
||||
css(name: string, value?: string): any;
|
||||
data(name: string, value?: string): any;
|
||||
class(className: string): any;
|
||||
id(id: string): any;
|
||||
html(html: string): any;
|
||||
text(text: string): any;
|
||||
value(value: string): any;
|
||||
visible: any;
|
||||
hidden: any;
|
||||
selected: any;
|
||||
checked: any;
|
||||
disabled: any;
|
||||
empty: any;
|
||||
exist: any;
|
||||
}
|
||||
|
||||
interface Expect extends LanguageChains, NumericComparison, TypeComparison, Assertions {
|
||||
not: Expect;
|
||||
deep: Deep;
|
||||
a: TypeComparison;
|
||||
an: TypeComparison;
|
||||
include: Include;
|
||||
contain: Include;
|
||||
ok: Expect;
|
||||
true: Expect;
|
||||
false: Expect;
|
||||
null: Expect;
|
||||
undefined: Expect;
|
||||
exist: Expect;
|
||||
empty: Expect;
|
||||
arguments: Expect;
|
||||
Arguments: Expect;
|
||||
equal: Equal;
|
||||
equals: Equal;
|
||||
eq: Equal;
|
||||
eql: Equal;
|
||||
eqls: Equal;
|
||||
property: Property;
|
||||
ownProperty: OwnProperty;
|
||||
haveOwnProperty: OwnProperty;
|
||||
length: Length;
|
||||
lengthOf: Length;
|
||||
match(RegularExpression: RegExp, message?: string): Expect;
|
||||
string(string: string, message?: string): Expect;
|
||||
keys: Keys;
|
||||
key(string: string): Expect;
|
||||
throw: Throw;
|
||||
throws: Throw;
|
||||
Throw: Throw;
|
||||
respondTo(method: string, message?: string): Expect;
|
||||
itself: Expect;
|
||||
satisfy(matcher: Function, message?: string): Expect;
|
||||
closeTo(expected: number, delta: number, message?: string): Expect;
|
||||
members: Members;
|
||||
}
|
||||
|
||||
interface LanguageChains {
|
||||
to: Expect;
|
||||
be: Expect;
|
||||
been: Expect;
|
||||
is: Expect;
|
||||
that: Expect;
|
||||
and: Expect;
|
||||
have: Expect;
|
||||
with: Expect;
|
||||
at: Expect;
|
||||
of: Expect;
|
||||
same: Expect;
|
||||
}
|
||||
|
||||
interface NumericComparison {
|
||||
above: NumberComparer;
|
||||
gt: NumberComparer;
|
||||
greaterThan: NumberComparer;
|
||||
least: NumberComparer;
|
||||
gte: NumberComparer;
|
||||
below: NumberComparer;
|
||||
lt: NumberComparer;
|
||||
lessThan: NumberComparer;
|
||||
most: NumberComparer;
|
||||
lte: NumberComparer;
|
||||
within(start: number, finish: number, message?: string): Expect;
|
||||
}
|
||||
|
||||
interface NumberComparer {
|
||||
(value: number, message?: string): Expect;
|
||||
}
|
||||
|
||||
interface TypeComparison {
|
||||
(type: string, message?: string): Expect;
|
||||
instanceof: InstanceOf;
|
||||
instanceOf: InstanceOf;
|
||||
}
|
||||
|
||||
interface InstanceOf {
|
||||
(constructor: Object, message?: string): Expect;
|
||||
}
|
||||
|
||||
interface Deep {
|
||||
equal: Equal;
|
||||
property: Property;
|
||||
}
|
||||
|
||||
interface Equal {
|
||||
(value: any, message?: string): Expect;
|
||||
}
|
||||
|
||||
interface Property {
|
||||
(name: string, value?: any, message?: string): Expect;
|
||||
}
|
||||
|
||||
interface OwnProperty {
|
||||
(name: string, message?: string): Expect;
|
||||
}
|
||||
|
||||
interface Length extends LanguageChains, NumericComparison {
|
||||
(length: number, message?: string): Expect;
|
||||
}
|
||||
|
||||
interface Include {
|
||||
(value: Object, message?: string): Expect;
|
||||
(value: string, message?: string): Expect;
|
||||
(value: number, message?: string): Expect;
|
||||
keys: Keys;
|
||||
members: Members;
|
||||
}
|
||||
|
||||
interface Keys {
|
||||
(...keys: string[]): Expect;
|
||||
(keys: any[]): Expect;
|
||||
}
|
||||
|
||||
interface Members {
|
||||
(set: any[], message?: string): Expect;
|
||||
}
|
||||
|
||||
interface Throw {
|
||||
(): Expect;
|
||||
(expected: string, message?: string): Expect;
|
||||
(expected: RegExp, message?: string): Expect;
|
||||
(constructor: Error, expected?: string, message?: string): Expect;
|
||||
(constructor: Error, expected?: RegExp, message?: string): Expect;
|
||||
(constructor: Function, expected?: string, message?: string): Expect;
|
||||
(constructor: Function, expected?: RegExp, message?: string): Expect;
|
||||
}
|
||||
|
||||
export interface Assert {
|
||||
(express: any, msg?: string):void;
|
||||
|
||||
fail(actual?: any, expected?: any, msg?: string, operator?: string):void;
|
||||
|
||||
ok(val: any, msg?: string):void;
|
||||
notOk(val: any, msg?: string):void;
|
||||
|
||||
equal(act: any, exp: any, msg?: string):void;
|
||||
notEqual(act: any, exp: any, msg?: string):void;
|
||||
|
||||
strictEqual(act: any, exp: any, msg?: string):void;
|
||||
notStrictEqual(act: any, exp: any, msg?: string):void;
|
||||
|
||||
deepEqual(act: any, exp: any, msg?: string):void;
|
||||
notDeepEqual(act: any, exp: any, msg?: string):void;
|
||||
|
||||
isTrue(val: any, msg?: string):void;
|
||||
isFalse(val: any, msg?: string):void;
|
||||
|
||||
isNull(val: any, msg?: string):void;
|
||||
isNotNull(val: any, msg?: string):void;
|
||||
|
||||
isUndefined(val: any, msg?: string):void;
|
||||
isDefined(val: any, msg?: string):void;
|
||||
|
||||
isFunction(val: any, msg?: string):void;
|
||||
isNotFunction(val: any, msg?: string):void;
|
||||
|
||||
isObject(val: any, msg?: string):void;
|
||||
isNotObject(val: any, msg?: string):void;
|
||||
|
||||
isArray(val: any, msg?: string):void;
|
||||
isNotArray(val: any, msg?: string):void;
|
||||
|
||||
isString(val: any, msg?: string):void;
|
||||
isNotString(val: any, msg?: string):void;
|
||||
|
||||
isNumber(val: any, msg?: string):void;
|
||||
isNotNumber(val: any, msg?: string):void;
|
||||
|
||||
isBoolean(val: any, msg?: string):void;
|
||||
isNotBoolean(val: any, msg?: string):void;
|
||||
|
||||
typeOf(val: any, type: string, msg?: string):void;
|
||||
notTypeOf(val: any, type: string, msg?: string):void;
|
||||
|
||||
instanceOf(val: any, type: Function, msg?: string):void;
|
||||
notInstanceOf(val: any, type: Function, msg?: string):void;
|
||||
|
||||
include(exp: string, inc: any, msg?: string):void;
|
||||
include(exp: any[], inc: any, msg?: string):void;
|
||||
|
||||
notInclude(exp: string, inc: any, msg?: string):void;
|
||||
notInclude(exp: any[], inc: any, msg?: string):void;
|
||||
|
||||
match(exp: any, re: RegExp, msg?: string):void;
|
||||
notMatch(exp: any, re: RegExp, msg?: string):void;
|
||||
|
||||
property(obj: Object, prop: string, msg?: string):void;
|
||||
notProperty(obj: Object, prop: string, msg?: string):void;
|
||||
deepProperty(obj: Object, prop: string, msg?: string):void;
|
||||
notDeepProperty(obj: Object, prop: string, msg?: string):void;
|
||||
|
||||
propertyVal(obj: Object, prop: string, val: any, msg?: string):void;
|
||||
propertyNotVal(obj: Object, prop: string, val: any, msg?: string):void;
|
||||
|
||||
deepPropertyVal(obj: Object, prop: string, val: any, msg?: string):void;
|
||||
deepPropertyNotVal(obj: Object, prop: string, val: any, msg?: string):void;
|
||||
|
||||
lengthOf(exp: any, len: number, msg?: string):void;
|
||||
//alias frenzy
|
||||
throw(fn: Function, msg?: string):void;
|
||||
throw(fn: Function, regExp: RegExp):void;
|
||||
throw(fn: Function, errType: Function, msg?: string):void;
|
||||
throw(fn: Function, errType: Function, regExp: RegExp):void;
|
||||
|
||||
throws(fn: Function, msg?: string):void;
|
||||
throws(fn: Function, regExp: RegExp):void;
|
||||
throws(fn: Function, errType: Function, msg?: string):void;
|
||||
throws(fn: Function, errType: Function, regExp: RegExp):void;
|
||||
|
||||
Throw(fn: Function, msg?: string):void;
|
||||
Throw(fn: Function, regExp: RegExp):void;
|
||||
Throw(fn: Function, errType: Function, msg?: string):void;
|
||||
Throw(fn: Function, errType: Function, regExp: RegExp):void;
|
||||
|
||||
doesNotThrow(fn: Function, msg?: string):void;
|
||||
doesNotThrow(fn: Function, regExp: RegExp):void;
|
||||
doesNotThrow(fn: Function, errType: Function, msg?: string):void;
|
||||
doesNotThrow(fn: Function, errType: Function, regExp: RegExp):void;
|
||||
|
||||
operator(val: any, operator: string, val2: any, msg?: string):void;
|
||||
closeTo(act: number, exp: number, delta: number, msg?: string):void;
|
||||
|
||||
sameMembers(set1: any[], set2: any[], msg?: string):void;
|
||||
includeMembers(set1: any[], set2: any[], msg?: string):void;
|
||||
|
||||
ifError(val: any, msg?: string):void;
|
||||
}
|
||||
}
|
||||
|
||||
declare module "chai" {
|
||||
export = chai;
|
||||
}
|
110
node-tests/definitions/mocha.d.ts
vendored
Normal file
110
node-tests/definitions/mocha.d.ts
vendored
Normal file
@ -0,0 +1,110 @@
|
||||
// Type definitions for mocha 1.17.1
|
||||
// Project: http://visionmedia.github.io/mocha/
|
||||
// Definitions by: Kazi Manzur Rashid <https://github.com/kazimanzurrashid/>, otiai10 <https://github.com/otiai10>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
interface Mocha {
|
||||
// Setup mocha with the given setting options.
|
||||
setup(options: MochaSetupOptions): Mocha;
|
||||
|
||||
//Run tests and invoke `fn()` when complete.
|
||||
run(callback?: () => void): void;
|
||||
|
||||
// Set reporter as function
|
||||
reporter(reporter: () => void): Mocha;
|
||||
|
||||
// Set reporter, defaults to "dot"
|
||||
reporter(reporter: string): Mocha;
|
||||
|
||||
// Enable growl support.
|
||||
growl(): Mocha
|
||||
}
|
||||
|
||||
interface MochaSetupOptions {
|
||||
//milliseconds to wait before considering a test slow
|
||||
slow?: number;
|
||||
|
||||
// timeout in milliseconds
|
||||
timeout?: number;
|
||||
|
||||
// ui name "bdd", "tdd", "exports" etc
|
||||
ui?: string;
|
||||
|
||||
//array of accepted globals
|
||||
globals?: any[];
|
||||
|
||||
// reporter instance (function or string), defaults to `mocha.reporters.Dot`
|
||||
reporter?: any;
|
||||
|
||||
// bail on the first test failure
|
||||
bail?: Boolean;
|
||||
|
||||
// ignore global leaks
|
||||
ignoreLeaks?: Boolean;
|
||||
|
||||
// grep string or regexp to filter tests with
|
||||
grep?: any;
|
||||
}
|
||||
|
||||
interface MochaDone {
|
||||
(error?: Error): void;
|
||||
}
|
||||
|
||||
declare var mocha: Mocha;
|
||||
|
||||
declare var describe : {
|
||||
(description: string, spec: () => void): void;
|
||||
only(description: string, spec: () => void): void;
|
||||
skip(description: string, spec: () => void): void;
|
||||
timeout(ms: number): void;
|
||||
}
|
||||
|
||||
// alias for `describe`
|
||||
declare var context : {
|
||||
(contextTitle: string, spec: () => void): void;
|
||||
only(contextTitle: string, spec: () => void): void;
|
||||
skip(contextTitle: string, spec: () => void): void;
|
||||
timeout(ms: number): void;
|
||||
}
|
||||
|
||||
declare var it: {
|
||||
(expectation: string, assertion?: () => void): void;
|
||||
(expectation: string, assertion?: (done: MochaDone) => void): void;
|
||||
only(expectation: string, assertion?: () => void): void;
|
||||
only(expectation: string, assertion?: (done: MochaDone) => void): void;
|
||||
skip(expectation: string, assertion?: () => void): void;
|
||||
skip(expectation: string, assertion?: (done: MochaDone) => void): void;
|
||||
timeout(ms: number): void;
|
||||
};
|
||||
|
||||
declare function before(action: () => void): void;
|
||||
|
||||
declare function before(action: (done: MochaDone) => void): void;
|
||||
|
||||
declare function setup(action: () => void): void;
|
||||
|
||||
declare function setup(action: (done: MochaDone) => void): void;
|
||||
|
||||
declare function after(action: () => void): void;
|
||||
|
||||
declare function after(action: (done: MochaDone) => void): void;
|
||||
|
||||
declare function teardown(action: () => void): void;
|
||||
|
||||
declare function teardown(action: (done: MochaDone) => void): void;
|
||||
|
||||
declare function beforeEach(action: () => void): void;
|
||||
|
||||
declare function beforeEach(action: (done: MochaDone) => void): void;
|
||||
|
||||
declare function suiteSetup(action: () => void): void;
|
||||
|
||||
declare function suiteSetup(action: (done: MochaDone) => void): void;
|
||||
|
||||
declare function afterEach(action: () => void): void;
|
||||
|
||||
declare function afterEach(action: (done: MochaDone) => void): void;
|
||||
|
||||
declare function suiteTeardown(action: () => void): void;
|
||||
|
||||
declare function suiteTeardown(action: (done: MochaDone) => void): void;
|
7
node-tests/test-xml.ts
Normal file
7
node-tests/test-xml.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import {assert} from "chai";
|
||||
|
||||
describe("test", () => {
|
||||
it("dummy", () => {
|
||||
assert.equal(1, 2);
|
||||
});
|
||||
});
|
@ -8,7 +8,8 @@
|
||||
},
|
||||
"files": [
|
||||
"**/*.*",
|
||||
"**/*"
|
||||
"**/*",
|
||||
"!node-tests/"
|
||||
],
|
||||
"license": "Apache-2.0",
|
||||
"devDependencies": {
|
||||
@ -20,6 +21,9 @@
|
||||
"grunt-shell": "1.1.2",
|
||||
"grunt-ts": "4.0.1",
|
||||
"grunt-tslint": "0.4.2",
|
||||
"mocha": "2.2.5",
|
||||
"grunt-simple-mocha": "0.4.0",
|
||||
"chai": "2.3.0",
|
||||
"typescript": "1.5.0-beta"
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user