Skip to content

Commit 31b202c

Browse files
committed
Add mocha and should.js; fix bootstraps; fix tests; run on build
1 parent 27721e7 commit 31b202c

10 files changed

+467
-16
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.DS_Store
2+
13
*.js
24
!/*.js
35
!bin/nativescript.js

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ install:
99
- npm install
1010
- grunt pack --no-color
1111
script:
12-
- 'true'
12+
- npm test
1313
git:
1414
submodules: false
1515
deploy:

Gruntfile.js

+11-4
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ module.exports = function(grunt) {
5656
watch: {
5757
devall: {
5858
files: ["lib/**/*.ts", 'test/**/*.ts'],
59-
tasks: ['ts:devall'],
59+
tasks: [
60+
'ts:devall',
61+
'shell:npm_test'
62+
],
6063
options: {
6164
atBegin: true,
6265
interrupt: true
@@ -67,7 +70,8 @@ module.exports = function(grunt) {
6770
shell: {
6871
options: {
6972
stdout: true,
70-
stderr: true
73+
stderr: true,
74+
failOnError: true
7175
},
7276

7377
build_package: {
@@ -81,7 +85,12 @@ module.exports = function(grunt) {
8185
})()
8286
}
8387
}
88+
},
89+
90+
npm_test: {
91+
command: "npm test"
8492
}
93+
8594
},
8695

8796
copy: {
@@ -125,8 +134,6 @@ module.exports = function(grunt) {
125134
"clean",
126135
"ts:release_build",
127136

128-
//"shell:ci_unit_tests",
129-
130137
"set_package_version",
131138
"shell:build_package",
132139

package.json

+14-11
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
},
1111
"main": "./lib/nativescript-cli.js",
1212
"scripts": {
13-
"test": "echo \"Error: no test specified\" && exit 1"
13+
"test": "node_modules\\.bin\\_mocha --ui mocha-fibers --recursive --reporter spec --require test/test-bootstrap.js --timeout 15000 test/"
1414
},
1515
"repository": {
1616
"type": "git",
@@ -24,29 +24,32 @@
2424
"dependencies": {
2525
"fibers": "https://github.com/icenium/node-fibers/tarball/master",
2626
"filesize": "2.0.3",
27-
"progress-stream": "0.5.0",
2827
"log4js": "0.6.9",
28+
"mkdirp": "0.3.5",
29+
"npm": "1.4.10",
2930
"osenv": "0.1.0",
31+
"progress-stream": "0.5.0",
32+
"properties-parser": "0.2.3",
33+
"rimraf": "2.2.6",
34+
"semver": "3.0.1",
35+
"shelljs": "0.3.0",
3036
"tabtab": "https://github.com/tailsu/node-tabtab/tarball/master",
3137
"underscore": "1.5.2",
3238
"unzip": "0.1.9",
33-
"yargs": "1.2.2",
34-
"npm": "1.4.10",
35-
"properties-parser": "0.2.3",
3639
"watchr": "2.4.11",
37-
"rimraf": "2.2.6",
38-
"mkdirp": "0.3.5",
39-
"shelljs": "0.3.0",
40-
"semver": "3.0.1"
40+
"yargs": "1.2.2"
4141
},
4242
"analyze": true,
4343
"devDependencies": {
4444
"grunt": "0.4.2",
45-
"grunt-ts": "1.11.2",
4645
"grunt-contrib-clean": "0.5.0",
46+
"grunt-contrib-copy": "0.5.0",
4747
"grunt-contrib-watch": "0.5.3",
4848
"grunt-shell": "0.6.4",
49-
"grunt-contrib-copy": "0.5.0"
49+
"grunt-ts": "1.11.2",
50+
"mocha": "1.21.4",
51+
"mocha-fibers": "https://github.com/tailsu/mocha-fibers/tarball/master",
52+
"should": "4.0.4"
5053
},
5154
"license": "Apache-2.0",
5255
"engines": {

test/.d.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/// <reference path="../lib/.d.ts" />
2+
/// <reference path="./definitions/mocha.d.ts" />
3+
/// <reference path="./definitions/should.d.ts" />
4+

test/definitions/mocha.d.ts

+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
// Type definitions for mocha 1.17.1
2+
// Project: http://visionmedia.github.io/mocha/
3+
// Definitions by: Kazi Manzur Rashid <https://github.com/kazimanzurrashid/>, otiai10 <https://github.com/otiai10>
4+
// Definitions: https://github.com/borisyankov/DefinitelyTyped
5+
6+
interface Mocha {
7+
// Setup mocha with the given setting options.
8+
setup(options: MochaSetupOptions): Mocha;
9+
10+
//Run tests and invoke `fn()` when complete.
11+
run(callback?: () => void): void;
12+
13+
// Set reporter as function
14+
reporter(reporter: () => void): Mocha;
15+
16+
// Set reporter, defaults to "dot"
17+
reporter(reporter: string): Mocha;
18+
19+
// Enable growl support.
20+
growl(): Mocha
21+
}
22+
23+
interface MochaSetupOptions {
24+
//milliseconds to wait before considering a test slow
25+
slow?: number;
26+
27+
// timeout in milliseconds
28+
timeout?: number;
29+
30+
// ui name "bdd", "tdd", "exports" etc
31+
ui?: string;
32+
33+
//array of accepted globals
34+
globals?: any[];
35+
36+
// reporter instance (function or string), defaults to `mocha.reporters.Dot`
37+
reporter?: any;
38+
39+
// bail on the first test failure
40+
bail?: Boolean;
41+
42+
// ignore global leaks
43+
ignoreLeaks?: Boolean;
44+
45+
// grep string or regexp to filter tests with
46+
grep?: any;
47+
}
48+
49+
interface MochaDone {
50+
(error?: Error): void;
51+
}
52+
53+
declare var mocha: Mocha;
54+
55+
declare var describe : {
56+
(description: string, spec: () => void): void;
57+
only(description: string, spec: () => void): void;
58+
skip(description: string, spec: () => void): void;
59+
timeout(ms: number): void;
60+
}
61+
62+
// alias for `describe`
63+
declare var context : {
64+
(contextTitle: string, spec: () => void): void;
65+
only(contextTitle: string, spec: () => void): void;
66+
skip(contextTitle: string, spec: () => void): void;
67+
timeout(ms: number): void;
68+
}
69+
70+
declare var it: {
71+
(expectation: string, assertion?: () => void): void;
72+
(expectation: string, assertion?: (done: MochaDone) => void): void;
73+
only(expectation: string, assertion?: () => void): void;
74+
only(expectation: string, assertion?: (done: MochaDone) => void): void;
75+
skip(expectation: string, assertion?: () => void): void;
76+
skip(expectation: string, assertion?: (done: MochaDone) => void): void;
77+
timeout(ms: number): void;
78+
};
79+
80+
declare function before(action: () => void): void;
81+
82+
declare function before(action: (done: MochaDone) => void): void;
83+
84+
declare function setup(action: () => void): void;
85+
86+
declare function setup(action: (done: MochaDone) => void): void;
87+
88+
declare function after(action: () => void): void;
89+
90+
declare function after(action: (done: MochaDone) => void): void;
91+
92+
declare function teardown(action: () => void): void;
93+
94+
declare function teardown(action: (done: MochaDone) => void): void;
95+
96+
declare function beforeEach(action: () => void): void;
97+
98+
declare function beforeEach(action: (done: MochaDone) => void): void;
99+
100+
declare function suiteSetup(action: () => void): void;
101+
102+
declare function suiteSetup(action: (done: MochaDone) => void): void;
103+
104+
declare function afterEach(action: () => void): void;
105+
106+
declare function afterEach(action: (done: MochaDone) => void): void;
107+
108+
declare function suiteTeardown(action: () => void): void;
109+
110+
declare function suiteTeardown(action: (done: MochaDone) => void): void;

test/definitions/should.d.ts

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
// Type definitions for should.js 3.1.2
2+
// Project: https://github.com/visionmedia/should.js
3+
// Definitions by: Alex Varju <https://github.com/varju/>, Maxime LUCE <https://github.com/SomaticIT/>
4+
// Definitions: https://github.com/borisyankov/DefinitelyTyped
5+
6+
interface Object {
7+
should: ShouldAssertion;
8+
}
9+
10+
interface ShouldAssertion {
11+
// basic grammar
12+
a: ShouldAssertion;
13+
an: ShouldAssertion;
14+
and: ShouldAssertion;
15+
be: ShouldAssertion;
16+
have: ShouldAssertion;
17+
with: ShouldAssertion;
18+
of: ShouldAssertion;
19+
not: ShouldAssertion;
20+
21+
// validators
22+
arguments: ShouldAssertion;
23+
empty: ShouldAssertion;
24+
ok: ShouldAssertion;
25+
true: ShouldAssertion;
26+
false: ShouldAssertion;
27+
NaN: ShouldAssertion;
28+
Infinity: ShouldAssertion;
29+
Array: ShouldAssertion;
30+
Object: ShouldAssertion;
31+
String: ShouldAssertion;
32+
Boolean: ShouldAssertion;
33+
Number: ShouldAssertion;
34+
Error: ShouldAssertion;
35+
Function: ShouldAssertion;
36+
eql(expected: any, description?: string): ShouldAssertion;
37+
equal(expected: any, description?: string): ShouldAssertion;
38+
within(start: number, finish: number, description?: string): ShouldAssertion;
39+
approximately(value: number, delta: number, description?: string): ShouldAssertion;
40+
type(expected: any, description?: string): ShouldAssertion;
41+
instanceof(constructor: Function, description?: string): ShouldAssertion;
42+
above(n: number, description?: string): ShouldAssertion;
43+
below(n: number, description?: string): ShouldAssertion;
44+
match(other: {}, description?: string): ShouldAssertion;
45+
match(other: (val: any) => any, description?: string): ShouldAssertion;
46+
match(regexp: RegExp, description?: string): ShouldAssertion;
47+
match(other: any, description?: string): ShouldAssertion;
48+
matchEach(other: {}, description?: string): ShouldAssertion;
49+
matchEach(other: (val: any) => any, description?: string): ShouldAssertion;
50+
matchEach(regexp: RegExp, description?: string): ShouldAssertion;
51+
matchEach(other: any, description?: string): ShouldAssertion;
52+
length(n: number, description?: string): ShouldAssertion;
53+
property(name: string, description?: string): ShouldAssertion;
54+
property(name: string, val: any, description?: string): ShouldAssertion;
55+
properties(names: string[]): ShouldAssertion;
56+
properties(name: string): ShouldAssertion;
57+
properties(descriptor: any): ShouldAssertion;
58+
properties(...properties: string[]): ShouldAssertion;
59+
ownProperty(name: string, description?: string): ShouldAssertion;
60+
contain(obj: any): ShouldAssertion;
61+
containEql(obj: any): ShouldAssertion;
62+
containDeep(obj: any): ShouldAssertion;
63+
keys(...allKeys: string[]): ShouldAssertion;
64+
keys(allKeys: string[]): ShouldAssertion;
65+
header(field: string, val?: string): ShouldAssertion;
66+
status(code: number): ShouldAssertion;
67+
json: ShouldAssertion;
68+
html: ShouldAssertion;
69+
startWith(expected: string, message?: any): ShouldAssertion;
70+
endWith(expected: string, message?: any): ShouldAssertion;
71+
throw(message?: any): ShouldAssertion;
72+
73+
// deprecated
74+
include(obj: any, description?: string): ShouldAssertion;
75+
includeEql(obj: any[], description?: string): ShouldAssertion;
76+
77+
// aliases
78+
exactly(expected: any, description?: string): ShouldAssertion;
79+
instanceOf(constructor: Function, description?: string): ShouldAssertion;
80+
throwError(message?: any): ShouldAssertion;
81+
lengthOf(n: number, description?: string): ShouldAssertion;
82+
key(key: string): ShouldAssertion;
83+
haveOwnProperty(name: string, description?: string): ShouldAssertion;
84+
greaterThan(n: number, description?: string): ShouldAssertion;
85+
lessThan(n: number, description?: string): ShouldAssertion;
86+
}
87+
88+
interface ShouldInternal {
89+
// should.js's extras
90+
exist(actual: any): void;
91+
exists(actual: any): void;
92+
not: ShouldInternal;
93+
}
94+
95+
interface Internal extends ShouldInternal {
96+
(obj: any): ShouldAssertion;
97+
98+
// node.js's assert functions
99+
fail(actual: any, expected: any, message: string, operator: string): void;
100+
assert(value: any, message: string): void;
101+
ok(value: any, message?: string): void;
102+
equal(actual: any, expected: any, message?: string): void;
103+
notEqual(actual: any, expected: any, message?: string): void;
104+
deepEqual(actual: any, expected: any, message?: string): void;
105+
notDeepEqual(actual: any, expected: any, message?: string): void;
106+
strictEqual(actual: any, expected: any, message?: string): void;
107+
notStrictEqual(actual: any, expected: any, message?: string): void;
108+
throws(block: any, error?: any, message?: string): void;
109+
doesNotThrow(block: any, message?: string): void;
110+
ifError(value: any): void;
111+
inspect(value: any, obj: any): any;
112+
}
113+
114+
declare var should: Internal;
115+
116+
declare module "should" {
117+
export = should;
118+
}

test/platform-service.ts

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/// <reference path=".d.ts" />
2+
3+
import PlatformServiceLib = require('../lib/services/platform-service');
4+
import NodePackageManagerLib = require('../lib/node-package-manager');
5+
import ProjectLib = require('../lib/services/project-service');
6+
import stubs = require('./stubs');
7+
8+
import yok = require('../lib/common/yok');
9+
10+
require('should');
11+
12+
var testInjector = new yok.Yok();
13+
testInjector.register('platformService', PlatformServiceLib.PlatformService);
14+
testInjector.register('errors', stubs.ErrorsStub);
15+
testInjector.register('fs', stubs.FileSystemStub);
16+
testInjector.register('logger', stubs.LoggerStub);
17+
testInjector.register('npm', stubs.NPMStub);
18+
testInjector.register('projectData', stubs.ProjectDataStub);
19+
testInjector.register('platformsData', stubs.PlatformsDataStub);
20+
21+
describe('PlatformService', function(){
22+
describe('#updatePlatforms()', function(){
23+
it('should fail when no services provided', function(){
24+
var platformService = testInjector.resolve('platformService');
25+
(function(){return platformService.updatePlatforms().wait(); }).should.throw();
26+
27+
})
28+
})
29+
});

0 commit comments

Comments
 (0)