Skip to content

Add tests #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 14, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.DS_Store

*.js
!/*.js
!bin/nativescript.js
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ install:
- npm install
- grunt pack --no-color
script:
- 'true'
- npm test
git:
submodules: false
deploy:
Expand Down
15 changes: 11 additions & 4 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ module.exports = function(grunt) {
watch: {
devall: {
files: ["lib/**/*.ts", 'test/**/*.ts'],
tasks: ['ts:devall'],
tasks: [
'ts:devall',
'shell:npm_test'
],
options: {
atBegin: true,
interrupt: true
Expand All @@ -67,7 +70,8 @@ module.exports = function(grunt) {
shell: {
options: {
stdout: true,
stderr: true
stderr: true,
failOnError: true
},

build_package: {
Expand All @@ -81,7 +85,12 @@ module.exports = function(grunt) {
})()
}
}
},

npm_test: {
command: "npm test"
}

},

copy: {
Expand Down Expand Up @@ -125,8 +134,6 @@ module.exports = function(grunt) {
"clean",
"ts:release_build",

//"shell:ci_unit_tests",

"set_package_version",
"shell:build_package",

Expand Down
25 changes: 14 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"main": "./lib/nativescript-cli.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "node_modules\\.bin\\_mocha --ui mocha-fibers --recursive --reporter spec --require test/test-bootstrap.js --timeout 15000 test/"
},
"repository": {
"type": "git",
Expand All @@ -24,29 +24,32 @@
"dependencies": {
"fibers": "https://github.com/icenium/node-fibers/tarball/master",
"filesize": "2.0.3",
"progress-stream": "0.5.0",
"log4js": "0.6.9",
"mkdirp": "0.3.5",
"npm": "1.4.10",
"osenv": "0.1.0",
"progress-stream": "0.5.0",
"properties-parser": "0.2.3",
"rimraf": "2.2.6",
"semver": "3.0.1",
"shelljs": "0.3.0",
"tabtab": "https://github.com/tailsu/node-tabtab/tarball/master",
"underscore": "1.5.2",
"unzip": "0.1.9",
"yargs": "1.2.2",
"npm": "1.4.10",
"properties-parser": "0.2.3",
"watchr": "2.4.11",
"rimraf": "2.2.6",
"mkdirp": "0.3.5",
"shelljs": "0.3.0",
"semver": "3.0.1"
"yargs": "1.2.2"
},
"analyze": true,
"devDependencies": {
"grunt": "0.4.2",
"grunt-ts": "1.11.2",
"grunt-contrib-clean": "0.5.0",
"grunt-contrib-copy": "0.5.0",
"grunt-contrib-watch": "0.5.3",
"grunt-shell": "0.6.4",
"grunt-contrib-copy": "0.5.0"
"grunt-ts": "1.11.2",
"mocha": "1.21.4",
"mocha-fibers": "https://github.com/tailsu/mocha-fibers/tarball/master",
"should": "4.0.4"
},
"license": "Apache-2.0",
"engines": {
Expand Down
4 changes: 4 additions & 0 deletions test/.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/// <reference path="../lib/.d.ts" />
/// <reference path="./definitions/mocha.d.ts" />
/// <reference path="./definitions/should.d.ts" />

110 changes: 110 additions & 0 deletions test/definitions/mocha.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// Type definitions for mocha 1.17.1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file should be in common lib

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The common library would have its own tests. It might use mocha or not.
As these might differ, it's cleaner to have the mocha definitions here, in the upper repo. Or, have a repo for common test setup, which will be added as a submodule to each 'consumer' test folder.

// 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;
118 changes: 118 additions & 0 deletions test/definitions/should.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
// Type definitions for should.js 3.1.2
// Project: https://github.com/visionmedia/should.js
// Definitions by: Alex Varju <https://github.com/varju/>, Maxime LUCE <https://github.com/SomaticIT/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped

interface Object {
should: ShouldAssertion;
}

interface ShouldAssertion {
// basic grammar
a: ShouldAssertion;
an: ShouldAssertion;
and: ShouldAssertion;
be: ShouldAssertion;
have: ShouldAssertion;
with: ShouldAssertion;
of: ShouldAssertion;
not: ShouldAssertion;

// validators
arguments: ShouldAssertion;
empty: ShouldAssertion;
ok: ShouldAssertion;
true: ShouldAssertion;
false: ShouldAssertion;
NaN: ShouldAssertion;
Infinity: ShouldAssertion;
Array: ShouldAssertion;
Object: ShouldAssertion;
String: ShouldAssertion;
Boolean: ShouldAssertion;
Number: ShouldAssertion;
Error: ShouldAssertion;
Function: ShouldAssertion;
eql(expected: any, description?: string): ShouldAssertion;
equal(expected: any, description?: string): ShouldAssertion;
within(start: number, finish: number, description?: string): ShouldAssertion;
approximately(value: number, delta: number, description?: string): ShouldAssertion;
type(expected: any, description?: string): ShouldAssertion;
instanceof(constructor: Function, description?: string): ShouldAssertion;
above(n: number, description?: string): ShouldAssertion;
below(n: number, description?: string): ShouldAssertion;
match(other: {}, description?: string): ShouldAssertion;
match(other: (val: any) => any, description?: string): ShouldAssertion;
match(regexp: RegExp, description?: string): ShouldAssertion;
match(other: any, description?: string): ShouldAssertion;
matchEach(other: {}, description?: string): ShouldAssertion;
matchEach(other: (val: any) => any, description?: string): ShouldAssertion;
matchEach(regexp: RegExp, description?: string): ShouldAssertion;
matchEach(other: any, description?: string): ShouldAssertion;
length(n: number, description?: string): ShouldAssertion;
property(name: string, description?: string): ShouldAssertion;
property(name: string, val: any, description?: string): ShouldAssertion;
properties(names: string[]): ShouldAssertion;
properties(name: string): ShouldAssertion;
properties(descriptor: any): ShouldAssertion;
properties(...properties: string[]): ShouldAssertion;
ownProperty(name: string, description?: string): ShouldAssertion;
contain(obj: any): ShouldAssertion;
containEql(obj: any): ShouldAssertion;
containDeep(obj: any): ShouldAssertion;
keys(...allKeys: string[]): ShouldAssertion;
keys(allKeys: string[]): ShouldAssertion;
header(field: string, val?: string): ShouldAssertion;
status(code: number): ShouldAssertion;
json: ShouldAssertion;
html: ShouldAssertion;
startWith(expected: string, message?: any): ShouldAssertion;
endWith(expected: string, message?: any): ShouldAssertion;
throw(message?: any): ShouldAssertion;

// deprecated
include(obj: any, description?: string): ShouldAssertion;
includeEql(obj: any[], description?: string): ShouldAssertion;

// aliases
exactly(expected: any, description?: string): ShouldAssertion;
instanceOf(constructor: Function, description?: string): ShouldAssertion;
throwError(message?: any): ShouldAssertion;
lengthOf(n: number, description?: string): ShouldAssertion;
key(key: string): ShouldAssertion;
haveOwnProperty(name: string, description?: string): ShouldAssertion;
greaterThan(n: number, description?: string): ShouldAssertion;
lessThan(n: number, description?: string): ShouldAssertion;
}

interface ShouldInternal {
// should.js's extras
exist(actual: any): void;
exists(actual: any): void;
not: ShouldInternal;
}

interface Internal extends ShouldInternal {
(obj: any): ShouldAssertion;

// node.js's assert functions
fail(actual: any, expected: any, message: string, operator: string): void;
assert(value: any, message: string): void;
ok(value: any, message?: string): void;
equal(actual: any, expected: any, message?: string): void;
notEqual(actual: any, expected: any, message?: string): void;
deepEqual(actual: any, expected: any, message?: string): void;
notDeepEqual(actual: any, expected: any, message?: string): void;
strictEqual(actual: any, expected: any, message?: string): void;
notStrictEqual(actual: any, expected: any, message?: string): void;
throws(block: any, error?: any, message?: string): void;
doesNotThrow(block: any, message?: string): void;
ifError(value: any): void;
inspect(value: any, obj: any): any;
}

declare var should: Internal;

declare module "should" {
export = should;
}
29 changes: 29 additions & 0 deletions test/platform-service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/// <reference path=".d.ts" />

import PlatformServiceLib = require('../lib/services/platform-service');
import NodePackageManagerLib = require('../lib/node-package-manager');
import ProjectLib = require('../lib/services/project-service');
import stubs = require('./stubs');

import yok = require('../lib/common/yok');

require('should');

var testInjector = new yok.Yok();
testInjector.register('platformService', PlatformServiceLib.PlatformService);
testInjector.register('errors', stubs.ErrorsStub);
testInjector.register('fs', stubs.FileSystemStub);
testInjector.register('logger', stubs.LoggerStub);
testInjector.register('npm', stubs.NPMStub);
testInjector.register('projectData', stubs.ProjectDataStub);
testInjector.register('platformsData', stubs.PlatformsDataStub);

describe('PlatformService', function(){
describe('#updatePlatforms()', function(){
it('should fail when no services provided', function(){
var platformService = testInjector.resolve('platformService');
(function(){return platformService.updatePlatforms().wait(); }).should.throw();

})
})
});
Loading