Skip to content

Commit 21e4703

Browse files
committed
Merge pull request #108 from NativeScript/fatme/tests
Project service integration tests and unit tests for platform service
2 parents c489328 + 4cb4e14 commit 21e4703

12 files changed

+731
-48
lines changed

lib/commands/create-project.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export class CreateProjectCommand implements ICommand {
55

66
execute(args: string[]): IFuture<void> {
77
return (() => {
8-
this.$projectService.createProject(args[0], args[1]).wait();
8+
this.$projectService.createProject(args[0]).wait();
99
}).future<void>()();
1010
}
1111
}

lib/declarations.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
interface INodePackageManager {
22
getCacheRootPath(): IFuture<string>;
3-
addToCache(packageName: string): IFuture<void>;
3+
addToCache(packageName: string, version: string): IFuture<void>;
4+
cacheUnpack(packageName: string, version: string, unpackTarget?: string): IFuture<void>;
45
load(config?: any): IFuture<void>;
56
install(packageName: string, options?: INpmInstallOptions): IFuture<string>;
67
getLatestVersion(packageName: string): IFuture<string>;

lib/definitions/project.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
interface IProjectService {
2-
createProject(projectName: string, projectId: string): IFuture<void>;
2+
createProject(projectName: string): IFuture<void>;
33
}
44

55
interface IProjectData {

lib/node-package-manager.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ export class NodePackageManager implements INodePackageManager {
3131
}).future<string>()();
3232
}
3333

34-
public addToCache(packageName: string): IFuture<void> {
34+
public addToCache(packageName: string, version: string): IFuture<void> {
3535
return (() => {
3636
this.load().wait();
37-
this.addToCacheCore(packageName).wait();
37+
this.addToCacheCore(packageName, version).wait();
3838
}).future<void>()();
3939
}
4040

@@ -113,9 +113,22 @@ export class NodePackageManager implements INodePackageManager {
113113
return future;
114114
}
115115

116-
private addToCacheCore(packageName: string): IFuture<void> {
116+
private addToCacheCore(packageName: string, version: string): IFuture<void> {
117117
var future = new Future<void>();
118-
npm.commands["cache"].add(packageName, (err: Error, data: any) => {
118+
npm.commands["cache"].add(packageName, version, undefined, (err: Error, data: any) => {
119+
if(err) {
120+
future.throw(err);
121+
} else {
122+
future.return();
123+
}
124+
});
125+
return future;
126+
}
127+
128+
public cacheUnpack(packageName: string, version: string, unpackTarget?: string): IFuture<void> {
129+
var future = new Future<void>();
130+
unpackTarget = unpackTarget || path.join(npm.cache, packageName, version, "package");
131+
npm.commands["cache"].unpack(packageName, version, unpackTarget, (err: Error, data: any) => {
119132
if(err) {
120133
future.throw(err);
121134
} else {

lib/services/platform-service.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export class PlatformService implements IPlatformService {
4444
this.validatePlatform(platform);
4545

4646
var platformPath = path.join(this.$projectData.platformsDir, platform);
47+
4748
if (this.$fs.exists(platformPath).wait()) {
4849
this.$errors.fail("Platform %s already added", platform);
4950
}
@@ -212,7 +213,7 @@ export class PlatformService implements IPlatformService {
212213

213214
_.each(platforms, platform => {
214215
var parts = platform.split("@");
215-
platform = parts[0];
216+
platform = parts[0].toLowerCase();
216217
var version = parts[1];
217218

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

453454
if(!this.$fs.exists(npmCacheDirectoryPath).wait()) {
454-
this.$npm.addToCache(util.format("%s@%s", packageName, version)).wait();
455+
this.$npm.addToCache(packageName, version).wait();
455456
}
456457

457458
return npmCacheDirectoryPath;

lib/services/project-service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ export class ProjectService implements IProjectService {
1717
private $projectNameValidator: IProjectNameValidator,
1818
private $projectTemplatesService: IProjectTemplatesService) { }
1919

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

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

2929
var projectDir = path.join(path.resolve(options.path || "."), projectName);
3030
this.$fs.createDirectory(projectDir).wait();

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
},
5656
"analyze": true,
5757
"devDependencies": {
58+
"chai": "1.8.x",
5859
"grunt": "0.4.2",
5960
"grunt-contrib-clean": "0.5.0",
6061
"grunt-contrib-copy": "0.5.0",

test/definitions/chai.d.ts

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

0 commit comments

Comments
 (0)