Skip to content

Commit c05efb1

Browse files
committed
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.
1 parent 7e09183 commit c05efb1

5 files changed

Lines changed: 445 additions & 1 deletion

File tree

gruntfile.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,12 @@ module.exports = function(grunt) {
142142
]
143143
};
144144

145+
var nodeTestEnv = JSON.parse(JSON.stringify(process.env));
146+
nodeTestEnv['NODE_PATH'] = localCfg.outModulesDir;
147+
148+
localCfg.nodeTestsDir = pathModule.join(localCfg.outModulesDir, 'node-tests');
149+
150+
145151
localCfg.mainPackageContent = grunt.file.readJSON(localCfg.packageJsonFilePath);
146152
localCfg.packageVersion = getPackageVersion(localCfg.packageJsonFilePath);
147153
localCfg.commitSHA = getCommitSha();
@@ -180,6 +186,9 @@ module.exports = function(grunt) {
180186
],
181187
cwd: localCfg.outModulesDir
182188
},
189+
nodeTests: {
190+
src: localCfg.nodeTestsDir,
191+
},
183192
readyAppFiles: {
184193
src: [localCfg.outModulesDir + "/apps/**"]
185194
}
@@ -302,6 +311,24 @@ module.exports = function(grunt) {
302311
compiler: "node_modules/typescript/bin/tsc",
303312
noEmitOnError: true
304313
}
314+
},
315+
buildNodeTests: {
316+
src: [
317+
'js-libs/easysax/**/*.ts',
318+
'xml/**/*.ts',
319+
'node-tests/**/*.ts',
320+
],
321+
outDir: localCfg.outModulesDir,
322+
options: {
323+
fast: 'never',
324+
module: "commonjs",
325+
target: "es5",
326+
sourceMap: false,
327+
declaration: false,
328+
removeComments: "<%= !grunt.option('leavecomments') || '' %>",
329+
compiler: "node_modules/typescript/bin/tsc",
330+
noEmitOnError: true
331+
}
305332
}
306333
},
307334
tslint: {
@@ -348,6 +375,11 @@ module.exports = function(grunt) {
348375
options: {
349376
callback: assignGitSHA
350377
}
378+
},
379+
},
380+
simplemocha: {
381+
node: {
382+
src: localCfg.nodeTestsDir + '/**/*.js'
351383
}
352384
}
353385
});
@@ -359,6 +391,7 @@ module.exports = function(grunt) {
359391
grunt.loadNpmTasks("grunt-tslint");
360392
grunt.loadNpmTasks("grunt-multi-dest");
361393
grunt.loadNpmTasks("grunt-shell");
394+
grunt.loadNpmTasks("grunt-simple-mocha");
362395

363396
var cloneTasks = function(originalTasks, taskNameSuffix)
364397
{
@@ -487,4 +520,10 @@ module.exports = function(grunt) {
487520
"pack-definitions",
488521
"get-ready-packages"
489522
]));
523+
524+
grunt.registerTask("node-tests", [
525+
"clean:nodeTests",
526+
"ts:buildNodeTests",
527+
"simplemocha:node",
528+
]);
490529
};

node-tests/definitions/chai.d.ts

Lines changed: 284 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,284 @@
1+
2+
// Type definitions for chai 1.7.2
3+
// Project: http://chaijs.com/
4+
// Definitions by: Jed Hunsaker <https://github.com/jedhunsaker/>, Bart van der Schoor <https://github.com/Bartvds>
5+
// Definitions: https://github.com/borisyankov/DefinitelyTyped
6+
7+
declare module chai {
8+
export class AssertionError {
9+
constructor(message: string, _props?: any, ssf?: Function);
10+
name: string;
11+
message: string;
12+
showDiff: boolean;
13+
stack: string;
14+
}
15+
16+
function expect(target: any, message?: string): Expect;
17+
18+
export var assert: Assert;
19+
export var config: Config;
20+
21+
export interface Config {
22+
includeStack: boolean;
23+
}
24+
25+
// Provides a way to extend the internals of Chai
26+
function use(fn: (chai: any, utils: any) => void): any;
27+
28+
interface ExpectStatic {
29+
(target: any): Expect;
30+
}
31+
32+
interface Assertions {
33+
attr(name: string, value?: string): any;
34+
css(name: string, value?: string): any;
35+
data(name: string, value?: string): any;
36+
class(className: string): any;
37+
id(id: string): any;
38+
html(html: string): any;
39+
text(text: string): any;
40+
value(value: string): any;
41+
visible: any;
42+
hidden: any;
43+
selected: any;
44+
checked: any;
45+
disabled: any;
46+
empty: any;
47+
exist: any;
48+
}
49+
50+
interface Expect extends LanguageChains, NumericComparison, TypeComparison, Assertions {
51+
not: Expect;
52+
deep: Deep;
53+
a: TypeComparison;
54+
an: TypeComparison;
55+
include: Include;
56+
contain: Include;
57+
ok: Expect;
58+
true: Expect;
59+
false: Expect;
60+
null: Expect;
61+
undefined: Expect;
62+
exist: Expect;
63+
empty: Expect;
64+
arguments: Expect;
65+
Arguments: Expect;
66+
equal: Equal;
67+
equals: Equal;
68+
eq: Equal;
69+
eql: Equal;
70+
eqls: Equal;
71+
property: Property;
72+
ownProperty: OwnProperty;
73+
haveOwnProperty: OwnProperty;
74+
length: Length;
75+
lengthOf: Length;
76+
match(RegularExpression: RegExp, message?: string): Expect;
77+
string(string: string, message?: string): Expect;
78+
keys: Keys;
79+
key(string: string): Expect;
80+
throw: Throw;
81+
throws: Throw;
82+
Throw: Throw;
83+
respondTo(method: string, message?: string): Expect;
84+
itself: Expect;
85+
satisfy(matcher: Function, message?: string): Expect;
86+
closeTo(expected: number, delta: number, message?: string): Expect;
87+
members: Members;
88+
}
89+
90+
interface LanguageChains {
91+
to: Expect;
92+
be: Expect;
93+
been: Expect;
94+
is: Expect;
95+
that: Expect;
96+
and: Expect;
97+
have: Expect;
98+
with: Expect;
99+
at: Expect;
100+
of: Expect;
101+
same: Expect;
102+
}
103+
104+
interface NumericComparison {
105+
above: NumberComparer;
106+
gt: NumberComparer;
107+
greaterThan: NumberComparer;
108+
least: NumberComparer;
109+
gte: NumberComparer;
110+
below: NumberComparer;
111+
lt: NumberComparer;
112+
lessThan: NumberComparer;
113+
most: NumberComparer;
114+
lte: NumberComparer;
115+
within(start: number, finish: number, message?: string): Expect;
116+
}
117+
118+
interface NumberComparer {
119+
(value: number, message?: string): Expect;
120+
}
121+
122+
interface TypeComparison {
123+
(type: string, message?: string): Expect;
124+
instanceof: InstanceOf;
125+
instanceOf: InstanceOf;
126+
}
127+
128+
interface InstanceOf {
129+
(constructor: Object, message?: string): Expect;
130+
}
131+
132+
interface Deep {
133+
equal: Equal;
134+
property: Property;
135+
}
136+
137+
interface Equal {
138+
(value: any, message?: string): Expect;
139+
}
140+
141+
interface Property {
142+
(name: string, value?: any, message?: string): Expect;
143+
}
144+
145+
interface OwnProperty {
146+
(name: string, message?: string): Expect;
147+
}
148+
149+
interface Length extends LanguageChains, NumericComparison {
150+
(length: number, message?: string): Expect;
151+
}
152+
153+
interface Include {
154+
(value: Object, message?: string): Expect;
155+
(value: string, message?: string): Expect;
156+
(value: number, message?: string): Expect;
157+
keys: Keys;
158+
members: Members;
159+
}
160+
161+
interface Keys {
162+
(...keys: string[]): Expect;
163+
(keys: any[]): Expect;
164+
}
165+
166+
interface Members {
167+
(set: any[], message?: string): Expect;
168+
}
169+
170+
interface Throw {
171+
(): Expect;
172+
(expected: string, message?: string): Expect;
173+
(expected: RegExp, message?: string): Expect;
174+
(constructor: Error, expected?: string, message?: string): Expect;
175+
(constructor: Error, expected?: RegExp, message?: string): Expect;
176+
(constructor: Function, expected?: string, message?: string): Expect;
177+
(constructor: Function, expected?: RegExp, message?: string): Expect;
178+
}
179+
180+
export interface Assert {
181+
(express: any, msg?: string):void;
182+
183+
fail(actual?: any, expected?: any, msg?: string, operator?: string):void;
184+
185+
ok(val: any, msg?: string):void;
186+
notOk(val: any, msg?: string):void;
187+
188+
equal(act: any, exp: any, msg?: string):void;
189+
notEqual(act: any, exp: any, msg?: string):void;
190+
191+
strictEqual(act: any, exp: any, msg?: string):void;
192+
notStrictEqual(act: any, exp: any, msg?: string):void;
193+
194+
deepEqual(act: any, exp: any, msg?: string):void;
195+
notDeepEqual(act: any, exp: any, msg?: string):void;
196+
197+
isTrue(val: any, msg?: string):void;
198+
isFalse(val: any, msg?: string):void;
199+
200+
isNull(val: any, msg?: string):void;
201+
isNotNull(val: any, msg?: string):void;
202+
203+
isUndefined(val: any, msg?: string):void;
204+
isDefined(val: any, msg?: string):void;
205+
206+
isFunction(val: any, msg?: string):void;
207+
isNotFunction(val: any, msg?: string):void;
208+
209+
isObject(val: any, msg?: string):void;
210+
isNotObject(val: any, msg?: string):void;
211+
212+
isArray(val: any, msg?: string):void;
213+
isNotArray(val: any, msg?: string):void;
214+
215+
isString(val: any, msg?: string):void;
216+
isNotString(val: any, msg?: string):void;
217+
218+
isNumber(val: any, msg?: string):void;
219+
isNotNumber(val: any, msg?: string):void;
220+
221+
isBoolean(val: any, msg?: string):void;
222+
isNotBoolean(val: any, msg?: string):void;
223+
224+
typeOf(val: any, type: string, msg?: string):void;
225+
notTypeOf(val: any, type: string, msg?: string):void;
226+
227+
instanceOf(val: any, type: Function, msg?: string):void;
228+
notInstanceOf(val: any, type: Function, msg?: string):void;
229+
230+
include(exp: string, inc: any, msg?: string):void;
231+
include(exp: any[], inc: any, msg?: string):void;
232+
233+
notInclude(exp: string, inc: any, msg?: string):void;
234+
notInclude(exp: any[], inc: any, msg?: string):void;
235+
236+
match(exp: any, re: RegExp, msg?: string):void;
237+
notMatch(exp: any, re: RegExp, msg?: string):void;
238+
239+
property(obj: Object, prop: string, msg?: string):void;
240+
notProperty(obj: Object, prop: string, msg?: string):void;
241+
deepProperty(obj: Object, prop: string, msg?: string):void;
242+
notDeepProperty(obj: Object, prop: string, msg?: string):void;
243+
244+
propertyVal(obj: Object, prop: string, val: any, msg?: string):void;
245+
propertyNotVal(obj: Object, prop: string, val: any, msg?: string):void;
246+
247+
deepPropertyVal(obj: Object, prop: string, val: any, msg?: string):void;
248+
deepPropertyNotVal(obj: Object, prop: string, val: any, msg?: string):void;
249+
250+
lengthOf(exp: any, len: number, msg?: string):void;
251+
//alias frenzy
252+
throw(fn: Function, msg?: string):void;
253+
throw(fn: Function, regExp: RegExp):void;
254+
throw(fn: Function, errType: Function, msg?: string):void;
255+
throw(fn: Function, errType: Function, regExp: RegExp):void;
256+
257+
throws(fn: Function, msg?: string):void;
258+
throws(fn: Function, regExp: RegExp):void;
259+
throws(fn: Function, errType: Function, msg?: string):void;
260+
throws(fn: Function, errType: Function, regExp: RegExp):void;
261+
262+
Throw(fn: Function, msg?: string):void;
263+
Throw(fn: Function, regExp: RegExp):void;
264+
Throw(fn: Function, errType: Function, msg?: string):void;
265+
Throw(fn: Function, errType: Function, regExp: RegExp):void;
266+
267+
doesNotThrow(fn: Function, msg?: string):void;
268+
doesNotThrow(fn: Function, regExp: RegExp):void;
269+
doesNotThrow(fn: Function, errType: Function, msg?: string):void;
270+
doesNotThrow(fn: Function, errType: Function, regExp: RegExp):void;
271+
272+
operator(val: any, operator: string, val2: any, msg?: string):void;
273+
closeTo(act: number, exp: number, delta: number, msg?: string):void;
274+
275+
sameMembers(set1: any[], set2: any[], msg?: string):void;
276+
includeMembers(set1: any[], set2: any[], msg?: string):void;
277+
278+
ifError(val: any, msg?: string):void;
279+
}
280+
}
281+
282+
declare module "chai" {
283+
export = chai;
284+
}

0 commit comments

Comments
 (0)