Skip to content

Commit 78dda8f

Browse files
Charles Lydingfilipesilva
Charles Lyding
authored andcommitted
test: cleanup and convert acceptance tests to TypeScript
1 parent 0a464ea commit 78dda8f

18 files changed

+369
-451
lines changed

package.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"exports-loader": "^0.6.3",
5555
"extract-text-webpack-plugin": "^2.1.0",
5656
"file-loader": "^0.10.0",
57-
"fs-extra": "~2.0.0",
57+
"fs-extra": "~3.0.1",
5858
"get-caller-file": "^1.0.0",
5959
"glob": "^7.0.3",
6060
"html-webpack-plugin": "^2.19.0",
@@ -109,7 +109,7 @@
109109
"@types/common-tags": "^1.2.4",
110110
"@types/denodeify": "^1.2.29",
111111
"@types/express": "^4.0.32",
112-
"@types/fs-extra": "0.0.37",
112+
"@types/fs-extra": "~3.0.2",
113113
"@types/glob": "^5.0.29",
114114
"@types/jasmine": "~2.2.0",
115115
"@types/lodash": "4.14.50",
@@ -125,7 +125,6 @@
125125
"conventional-changelog": "^1.1.0",
126126
"dtsgenerator": "^0.9.1",
127127
"eslint": "^3.11.0",
128-
"exists-sync": "0.0.4",
129128
"express": "^4.14.0",
130129
"jasmine": "^2.4.1",
131130
"jasmine-spec-reporter": "^3.2.0",
@@ -138,7 +137,6 @@
138137
"request": "^2.74.0",
139138
"resolve-bin": "^0.4.0",
140139
"rewire": "^2.5.1",
141-
"sinon": "^1.17.3",
142140
"spdx-satisfies": "^0.1.3",
143141
"through": "^2.3.6",
144142
"tree-kill": "^1.0.0",

tests/acceptance/destroy.spec.js renamed to tests/acceptance/destroy.spec.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
'use strict';
1+
import { expect } from 'chai';
22

33
const ng = require('../helpers/ng');
44
const tmp = require('../helpers/tmp');
55
const SilentError = require('silent-error');
6-
const expect = require('chai').expect;
76

87
describe('Acceptance: ng destroy', function () {
98
beforeEach(function () {
@@ -22,15 +21,15 @@ describe('Acceptance: ng destroy', function () {
2221
it('without args should fail', function () {
2322
return ng(['destroy']).then(() => {
2423
throw new SilentError('ng destroy should fail.');
25-
}, (err) => {
24+
}, (err: any) => {
2625
expect(err.message).to.equal('The destroy command is not supported by Angular CLI.');
2726
});
2827
});
2928

3029
it('with args should fail', function () {
3130
return ng(['destroy', 'something']).then(() => {
3231
throw new SilentError('ng destroy something should fail.');
33-
}, (err) => {
32+
}, (err: any) => {
3433
expect(err.message).to.equal('The destroy command is not supported by Angular CLI.');
3534
});
3635
});

tests/acceptance/dynamic-path-parser.spec.js renamed to tests/acceptance/dynamic-path-parser.spec.ts

+34-34
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1-
'use strict';
1+
import { expect } from 'chai';
2+
import * as path from 'path';
3+
import { dynamicPathParser } from '@angular/cli/utilities/dynamic-path-parser';
4+
import mockFs = require('mock-fs');
25

3-
var expect = require('chai').expect;
4-
var path = require('path');
5-
var dynamicPathParser = require('../../packages/@angular/cli/utilities/dynamic-path-parser').dynamicPathParser;
6-
var mockFs = require('mock-fs');
7-
8-
var appDir = `src${path.sep}app`;
6+
const appDir = `src${path.sep}app`;
97
const appConfig = {
108
root: 'src'
119
};
1210

1311
describe('dynamic path parser', () => {
14-
var project;
15-
var entityName = 'temp-name';
16-
var rootName = path.parse(process.cwd()).root + 'project';
17-
var root = 'src';
12+
let project: any;
13+
const entityName = 'temp-name';
14+
const rootName = path.parse(process.cwd()).root + 'project';
15+
const root = 'src';
1816
beforeEach(() => {
1917
project = {
2018
root: rootName,
@@ -24,7 +22,7 @@ describe('dynamic path parser', () => {
2422
}]
2523
}
2624
};
27-
var mockFolder = {};
25+
const mockFolder: any = {};
2826
mockFolder[rootName] = {
2927
src: {
3028
app: {
@@ -42,58 +40,58 @@ describe('dynamic path parser', () => {
4240

4341
it('parse from proj root dir', () => {
4442
process.env.PWD = project.root;
45-
var options = {
43+
const options = {
4644
project,
4745
entityName,
4846
appConfig,
4947
dryRun: false
5048
};
51-
var result = dynamicPathParser(options);
49+
const result = dynamicPathParser(options);
5250
expect(result.dir).to.equal(appDir);
5351
expect(result.name).to.equal(entityName);
5452
});
5553

5654
it('parse from proj src dir', () => {
5755
process.env.PWD = path.join(project.root, 'src');
58-
var options = {
56+
const options = {
5957
project,
6058
entityName,
6159
appConfig,
6260
dryRun: false
6361
};
64-
var result = dynamicPathParser(options);
62+
const result = dynamicPathParser(options);
6563
expect(result.dir).to.equal(appDir);
6664
expect(result.name).to.equal(entityName);
6765
});
6866

6967
it(`parse from proj src${path.sep}client dir`, () => {
7068
process.env.PWD = path.join(project.root, 'src', 'client');
71-
var options = {
69+
const options = {
7270
project,
7371
entityName,
7472
appConfig,
7573
dryRun: false
7674
};
77-
var result = dynamicPathParser(options);
75+
const result = dynamicPathParser(options);
7876
expect(result.dir).to.equal(appDir);
7977
expect(result.name).to.equal(entityName);
8078
});
8179

8280
it(`parse from proj src${path.sep}client${path.sep}app dir`, () => {
8381
process.env.PWD = path.join(project.root, 'src', 'client', 'app');
84-
var options = {
82+
const options = {
8583
project,
8684
entityName,
8785
appConfig,
8886
dryRun: false
8987
};
90-
var result = dynamicPathParser(options);
88+
const result = dynamicPathParser(options);
9189
expect(result.dir).to.equal(appDir);
9290
expect(result.name).to.equal(entityName);
9391
});
9492

9593
it(`parse from proj src${path.sep}client${path.sep}app${path.sep}child-dir`, () => {
96-
var mockFolder = {};
94+
const mockFolder: any = {};
9795
mockFolder[rootName] = {
9896
src: {
9997
app: {
@@ -106,19 +104,20 @@ describe('dynamic path parser', () => {
106104
};
107105
mockFs(mockFolder);
108106
process.env.PWD = path.join(project.root, 'src', 'app', 'child-dir');
109-
var options = {
107+
const options = {
110108
project,
111109
entityName,
112110
appConfig,
113111
dryRun: false
114112
};
115-
var result = dynamicPathParser(options);
113+
const result = dynamicPathParser(options);
116114
expect(result.dir).to.equal(`${appDir}${path.sep}child-dir`);
117115
expect(result.name).to.equal(entityName);
118116
});
119117

118+
// tslint:disable-next-line:max-line-length
120119
it(`parse from proj src${path.sep}client${path.sep}app${path.sep}child-dir w/ ..${path.sep}`, () => {
121-
var mockFolder = {};
120+
const mockFolder: any = {};
122121
mockFolder[rootName] = {
123122
src: {
124123
app: {
@@ -130,20 +129,21 @@ describe('dynamic path parser', () => {
130129
};
131130
mockFs(mockFolder);
132131
process.env.PWD = path.join(project.root, 'src', 'app', 'child-dir');
133-
var options = {
132+
const options = {
134133
project,
135134
entityName: '..' + path.sep + entityName,
136135
appConfig,
137136
dryRun: false
138137
};
139-
var result = dynamicPathParser(options);
138+
const result = dynamicPathParser(options);
140139
expect(result.dir).to.equal(appDir);
141140
expect(result.name).to.equal(entityName);
142141
});
143142

143+
// tslint:disable-next-line:max-line-length
144144
it(`parse from proj src${path.sep}client${path.sep}app${path.sep}child-dir${path.sep}grand-child-dir w/ ..${path.sep}`,
145145
() => {
146-
var mockFolder = {};
146+
const mockFolder: any = {};
147147
mockFolder[rootName] = {
148148
src: {
149149
app: {
@@ -157,19 +157,19 @@ describe('dynamic path parser', () => {
157157
};
158158
mockFs(mockFolder);
159159
process.env.PWD = path.join(project.root, 'src', 'app', 'child-dir', 'grand-child-dir');
160-
var options = {
160+
const options = {
161161
project,
162162
entityName: '..' + path.sep + entityName,
163163
appConfig,
164164
dryRun: false
165165
};
166-
var result = dynamicPathParser(options);
166+
const result = dynamicPathParser(options);
167167
expect(result.dir).to.equal(`${appDir}${path.sep}child-dir`);
168168
expect(result.name).to.equal(entityName);
169169
});
170170

171171
it('auto look for dirs with a "+" when not specified', () => {
172-
var mockFolder = {};
172+
const mockFolder: any = {};
173173
mockFolder[rootName] = {
174174
src: {
175175
app: {
@@ -179,26 +179,26 @@ describe('dynamic path parser', () => {
179179
};
180180
mockFs(mockFolder);
181181
process.env.PWD = path.join(project.root, 'src', 'app', 'my-route');
182-
var options = {
182+
const options = {
183183
project,
184184
entityName,
185185
appConfig,
186186
dryRun: false
187187
};
188-
var result = dynamicPathParser(options);
188+
const result = dynamicPathParser(options);
189189
expect(result.dir).to.equal(`${appDir}${path.sep}+my-route`);
190190
expect(result.name).to.equal(entityName);
191191
});
192192

193193
it('create new dirs as dasherized', () => {
194194
process.env.PWD = project.root;
195-
var options = {
195+
const options = {
196196
project,
197197
entityName: path.join('NewDir', entityName),
198198
appConfig,
199199
dryRun: false
200200
};
201-
var result = dynamicPathParser(options);
201+
const result = dynamicPathParser(options);
202202
expect(result.dir).to.equal(`${appDir}${path.sep}new-dir`);
203203
expect(result.name).to.equal(entityName);
204204
});

tests/acceptance/generate-class.spec.js renamed to tests/acceptance/generate-class.spec.ts

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
'use strict';
1+
import * as fs from 'fs-extra';
2+
import { expect } from 'chai';
3+
import * as path from 'path';
24

35
const ng = require('../helpers/ng');
46
const tmp = require('../helpers/tmp');
57

6-
const existsSync = require('exists-sync');
7-
const expect = require('chai').expect;
8-
const path = require('path');
98
const root = process.cwd();
109

1110
const testPath = path.join(root, 'tmp', 'foo', 'src', 'app');
@@ -26,21 +25,21 @@ describe('Acceptance: ng generate class', function () {
2625

2726
it('ng generate class my-class', function () {
2827
return ng(['generate', 'class', 'my-class']).then(() => {
29-
expect(existsSync(path.join(testPath, 'my-class.ts'))).to.equal(true);
30-
expect(existsSync(path.join(testPath, 'my-class.spec.ts'))).to.equal(false);
28+
expect(fs.pathExistsSync(path.join(testPath, 'my-class.ts'))).to.equal(true);
29+
expect(fs.pathExistsSync(path.join(testPath, 'my-class.spec.ts'))).to.equal(false);
3130
});
3231
});
3332

3433
it('ng generate class my-class --no-spec', function () {
3534
return ng(['generate', 'class', 'my-class', '--no-spec']).then(() => {
36-
expect(existsSync(path.join(testPath, 'my-class.ts'))).to.equal(true);
37-
expect(existsSync(path.join(testPath, 'my-class.spec.ts'))).to.equal(false);
35+
expect(fs.pathExistsSync(path.join(testPath, 'my-class.ts'))).to.equal(true);
36+
expect(fs.pathExistsSync(path.join(testPath, 'my-class.spec.ts'))).to.equal(false);
3837
});
3938
});
4039

4140
it('ng generate class my-class.model', function () {
4241
return ng(['generate', 'class', 'my-class.model']).then(() => {
43-
expect(existsSync(path.join(testPath, 'my-class.model.ts'))).to.equal(true);
42+
expect(fs.pathExistsSync(path.join(testPath, 'my-class.model.ts'))).to.equal(true);
4443
});
4544
});
4645
});

0 commit comments

Comments
 (0)