Skip to content

Project service integration tests and unit tests for platform service #108

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
Oct 2, 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: 1 addition & 1 deletion lib/commands/create-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export class CreateProjectCommand implements ICommand {

execute(args: string[]): IFuture<void> {
return (() => {
this.$projectService.createProject(args[0], args[1]).wait();
this.$projectService.createProject(args[0]).wait();
}).future<void>()();
}
}
Expand Down
3 changes: 2 additions & 1 deletion lib/declarations.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
interface INodePackageManager {
getCacheRootPath(): IFuture<string>;
addToCache(packageName: string): IFuture<void>;
addToCache(packageName: string, version: string): IFuture<void>;
cacheUnpack(packageName: string, version: string, unpackTarget?: string): IFuture<void>;
load(config?: any): IFuture<void>;
install(packageName: string, options?: INpmInstallOptions): IFuture<string>;
getLatestVersion(packageName: string): IFuture<string>;
Expand Down
2 changes: 1 addition & 1 deletion lib/definitions/project.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
interface IProjectService {
createProject(projectName: string, projectId: string): IFuture<void>;
createProject(projectName: string): IFuture<void>;
}

interface IProjectData {
Expand Down
21 changes: 17 additions & 4 deletions lib/node-package-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ export class NodePackageManager implements INodePackageManager {
}).future<string>()();
}

public addToCache(packageName: string): IFuture<void> {
public addToCache(packageName: string, version: string): IFuture<void> {
return (() => {
this.load().wait();
this.addToCacheCore(packageName).wait();
this.addToCacheCore(packageName, version).wait();
}).future<void>()();
}

Expand Down Expand Up @@ -113,9 +113,22 @@ export class NodePackageManager implements INodePackageManager {
return future;
}

private addToCacheCore(packageName: string): IFuture<void> {
private addToCacheCore(packageName: string, version: string): IFuture<void> {
var future = new Future<void>();
npm.commands["cache"].add(packageName, (err: Error, data: any) => {
npm.commands["cache"].add(packageName, version, undefined, (err: Error, data: any) => {
if(err) {
future.throw(err);
} else {
future.return();
}
});
return future;
}

public cacheUnpack(packageName: string, version: string, unpackTarget?: string): IFuture<void> {
var future = new Future<void>();
unpackTarget = unpackTarget || path.join(npm.cache, packageName, version, "package");
npm.commands["cache"].unpack(packageName, version, unpackTarget, (err: Error, data: any) => {
if(err) {
future.throw(err);
} else {
Expand Down
5 changes: 3 additions & 2 deletions lib/services/platform-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export class PlatformService implements IPlatformService {
this.validatePlatform(platform);

var platformPath = path.join(this.$projectData.platformsDir, platform);

if (this.$fs.exists(platformPath).wait()) {
this.$errors.fail("Platform %s already added", platform);
}
Expand Down Expand Up @@ -212,7 +213,7 @@ export class PlatformService implements IPlatformService {

_.each(platforms, platform => {
var parts = platform.split("@");
platform = parts[0];
platform = parts[0].toLowerCase();
var version = parts[1];

this.validatePlatformInstalled(platform);
Expand Down Expand Up @@ -451,7 +452,7 @@ export class PlatformService implements IPlatformService {
var npmCacheDirectoryPath = this.getNpmCacheDirectoryCore(packageName, version).wait();

if(!this.$fs.exists(npmCacheDirectoryPath).wait()) {
this.$npm.addToCache(util.format("%s@%s", packageName, version)).wait();
this.$npm.addToCache(packageName, version).wait();
}

return npmCacheDirectoryPath;
Expand Down
4 changes: 2 additions & 2 deletions lib/services/project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ export class ProjectService implements IProjectService {
private $projectNameValidator: IProjectNameValidator,
private $projectTemplatesService: IProjectTemplatesService) { }

public createProject(projectName: string, projectId: string): IFuture<void> {
public createProject(projectName: string): IFuture<void> {
return(() => {
if (!projectName) {
this.$errors.fail("You must specify <App name> when creating a new project.");
}
this.$projectNameValidator.validate(projectName);

projectId = options.appid || this.$projectHelper.generateDefaultAppId(projectName, "org.nativescript");
var projectId = options.appid || this.$projectHelper.generateDefaultAppId(projectName, "org.nativescript");

var projectDir = path.join(path.resolve(options.path || "."), projectName);
this.$fs.createDirectory(projectDir).wait();
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
},
"analyze": true,
"devDependencies": {
"chai": "1.8.x",
"grunt": "0.4.2",
"grunt-contrib-clean": "0.5.0",
"grunt-contrib-copy": "0.5.0",
Expand Down
283 changes: 283 additions & 0 deletions test/definitions/chai.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,283 @@
// 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;
}
Loading