From 8ec9e0986991c0e35fd87c3cae5d92c2953a7a25 Mon Sep 17 00:00:00 2001 From: rosen-vladimirov Date: Tue, 4 Aug 2015 20:16:29 +0300 Subject: [PATCH] Modify test infrastructure and grunt tasks As common lib is now a separate npm package, it has its own tests, that must be run when executing `grunt test` or `npm test` in nativescript-cli. Modify test command in package.json in order to run the tests. Change Gruntfile.js in order to ignore/build the correct typescript files in common lib. Add Bluebird as dependency as it is required for common lib. Update mocha version. Remove `chai` and `mocha` definitions as they are part of common lib now. Update some dev dependencies. --- Gruntfile.js | 23 +-- lib/common | 2 +- package.json | 13 +- test/.d.ts | 2 - test/definitions/chai.d.ts | 283 ------------------------------------ test/definitions/mocha.d.ts | 110 -------------- 6 files changed, 22 insertions(+), 411 deletions(-) delete mode 100644 test/definitions/chai.d.ts delete mode 100644 test/definitions/mocha.d.ts diff --git a/Gruntfile.js b/Gruntfile.js index 2200ecdbd2..2f347fa181 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,5 +1,3 @@ -var util = require("util"); - var now = new Date().toISOString(); function shallowCopy(obj) { @@ -14,6 +12,13 @@ var travis = process.env["TRAVIS"]; var buildNumber = process.env["TRAVIS_BUILD_NUMBER"] || process.env["BUILD_NUMBER"] || "non-ci"; module.exports = function(grunt) { + var path = require("path"); + var commonLibNodeModules = path.join("lib", "common", "node_modules"); + if(require("fs").existsSync(commonLibNodeModules)) { + grunt.file.delete(commonLibNodeModules); + } + grunt.file.write(path.join("lib", "common", ".d.ts"), ""); + grunt.initConfig({ copyPackageTo: process.env["CopyPackageTo"] || ".", @@ -22,7 +27,6 @@ module.exports = function(grunt) { dateString: now.substr(0, now.indexOf("T")), pkg: grunt.file.readJSON("package.json"), - ts: { options: { target: 'es5', @@ -30,21 +34,22 @@ module.exports = function(grunt) { sourceMap: true, declaration: false, removeComments: false, - noImplicitAny: true + noImplicitAny: true, + experimentalDecorators: true }, devlib: { - src: ["lib/**/*.ts"], + src: ["lib/**/*.ts", "!lib/common/node_modules/**/*.ts"], reference: "lib/.d.ts" }, devall: { - src: ["lib/**/*.ts", "test/**/*.ts"], + src: ["lib/**/*.ts", "test/**/*.ts", "!lib/common/node_modules/**/*.ts", "lib/common/test/unit-tests/**/*.ts", "definitions/**/*.ts", "!lib/common/test/.d.ts"], reference: "lib/.d.ts" }, release_build: { - src: ["lib/**/*.ts", "test/**/*.ts"], + src: ["lib/**/*.ts", "test/**/*.ts", "!lib/common/node_modules/**/*.ts"], reference: "lib/.d.ts", options: { sourceMap: false, @@ -55,7 +60,7 @@ module.exports = function(grunt) { watch: { devall: { - files: ["lib/**/*.ts", 'test/**/*.ts'], + files: ["lib/**/*.ts", 'test/**/*.ts', "!lib/common/node_modules/**/*.ts"], tasks: [ 'ts:devall', 'shell:npm_test' @@ -105,7 +110,7 @@ module.exports = function(grunt) { }, clean: { - src: ["test/**/*.js*", "lib/**/*.js*", "!lib/common/vendor/*.js", "*.tgz"] + src: ["test/**/*.js*", "lib/**/*.js*", "!lib/common/vendor/*.js", "!lib/common/**/*.json", "!lib/common/Gruntfile.js", "!lib/common/node_modules/**/*", "!lib/common/hooks/**/*.js", "!lib/common/bin/*.js", "*.tgz"] } }); diff --git a/lib/common b/lib/common index e7114d499f..8d3a39ed08 160000 --- a/lib/common +++ b/lib/common @@ -1 +1 @@ -Subproject commit e7114d499f23e9837779217288be2db9a243f320 +Subproject commit 8d3a39ed08d5594ca3d4cd48fc6fb785707277d3 diff --git a/package.json b/package.json index 1a82821694..3217a7870f 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ }, "main": "./lib/nativescript-cli.js", "scripts": { - "test": "node_modules\\.bin\\_mocha --ui mocha-fibers --recursive --reporter spec --require test/test-bootstrap.js --timeout 60000 test/", + "test": "node_modules\\.bin\\_mocha --ui mocha-fibers --recursive --reporter spec --require test/test-bootstrap.js --timeout 60000 test/ lib/common/test/unit-tests", "postinstall": "node postinstall.js", "preuninstall": "node preuninstall.js" }, @@ -24,6 +24,7 @@ "mobile" ], "dependencies": { + "bluebird": "2.9.34", "bplist-parser": "0.1.0", "broccoli": "0.16.4", "broccoli-funnel": "0.2.3", @@ -81,12 +82,12 @@ "devDependencies": { "chai": "1.8.x", "grunt": "0.4.5", - "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-clean": "0.6.0", + "grunt-contrib-copy": "0.8.0", + "grunt-contrib-watch": "0.6.1", + "grunt-shell": "1.1.2", "grunt-ts": "4.2.0", - "mocha": "1.21.4", + "mocha": "2.2.5", "mocha-fibers": "https://github.com/Icenium/mocha-fibers/tarball/master", "should": "7.0.2", "typescript": "1.5.3" diff --git a/test/.d.ts b/test/.d.ts index b9a278d22c..a60f219d69 100644 --- a/test/.d.ts +++ b/test/.d.ts @@ -1,4 +1,2 @@ /// -/// /// - diff --git a/test/definitions/chai.d.ts b/test/definitions/chai.d.ts deleted file mode 100644 index 113158d837..0000000000 --- a/test/definitions/chai.d.ts +++ /dev/null @@ -1,283 +0,0 @@ -// Type definitions for chai 1.7.2 -// Project: http://chaijs.com/ -// Definitions by: Jed Hunsaker , Bart van der Schoor -// 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; -} diff --git a/test/definitions/mocha.d.ts b/test/definitions/mocha.d.ts deleted file mode 100644 index 64255a7ba1..0000000000 --- a/test/definitions/mocha.d.ts +++ /dev/null @@ -1,110 +0,0 @@ -// Type definitions for mocha 1.17.1 -// Project: http://visionmedia.github.io/mocha/ -// Definitions by: Kazi Manzur Rashid , 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;