forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate-pipe.spec.js
159 lines (143 loc) · 5.87 KB
/
generate-pipe.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*eslint-disable no-console */
'use strict';
var fs = require('fs-extra');
var ng = require('../helpers/ng');
var existsSync = require('exists-sync');
var expect = require('chai').expect;
var path = require('path');
var tmp = require('../helpers/tmp');
var root = process.cwd();
var Promise = require('angular-cli/ember-cli/lib/ext/promise');
var SilentError = require('silent-error');
const denodeify = require('denodeify');
const readFile = denodeify(fs.readFile);
describe('Acceptance: ng generate pipe', function () {
beforeEach(function () {
return tmp.setup('./tmp').then(function () {
process.chdir('./tmp');
}).then(function () {
return ng(['new', 'foo', '--skip-npm']);
});
});
afterEach(function () {
this.timeout(10000);
return tmp.teardown('./tmp');
});
it('ng generate pipe my-pipe', function () {
const appRoot = path.join(root, 'tmp/foo');
const testPath = path.join(appRoot, 'src/app/my-pipe.pipe.ts');
const testSpecPath = path.join(appRoot, 'src/app/my-pipe.pipe.spec.ts');
const appModulePath = path.join(appRoot, 'src/app/app.module.ts');
return ng(['generate', 'pipe', 'my-pipe'])
.then(() => {
expect(existsSync(testPath)).to.equal(true);
expect(existsSync(testSpecPath)).to.equal(true);
})
.then(() => readFile(appModulePath, 'utf-8'))
.then(content => {
expect(content).matches(/import.*\bMyPipePipe\b.*from '.\/my-pipe.pipe';/);
expect(content).matches(/declarations:\s*\[[^\]]+?,\r?\n\s+MyPipePipe\r?\n/m);
});
});
it('ng generate pipe my-pipe --no-spec', function () {
const appRoot = path.join(root, 'tmp/foo');
const testPath = path.join(appRoot, 'src/app/my-pipe.pipe.ts');
const testSpecPath = path.join(appRoot, 'src/app/my-pipe.pipe.spec.ts');
return ng(['generate', 'pipe', 'my-pipe', '--no-spec'])
.then(() => {
expect(existsSync(testPath)).to.equal(true);
expect(existsSync(testSpecPath)).to.equal(false);
});
});
it('ng generate pipe test' + path.sep + 'my-pipe', function () {
fs.mkdirsSync(path.join(root, 'tmp', 'foo', 'src', 'app', 'test'));
return ng(['generate', 'pipe', 'test' + path.sep + 'my-pipe']).then(() => {
var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', 'test', 'my-pipe.pipe.ts');
expect(existsSync(testPath)).to.equal(true);
});
});
it('ng generate pipe test' + path.sep + '..' + path.sep + 'my-pipe', function () {
return ng(['generate', 'pipe', 'test' + path.sep + '..' + path.sep + 'my-pipe']).then(() => {
var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', 'my-pipe.pipe.ts');
expect(existsSync(testPath)).to.equal(true);
});
});
it('ng generate pipe my-pipe from a child dir', () => {
fs.mkdirsSync(path.join(root, 'tmp', 'foo', 'src', 'app', '1'));
return new Promise(function (resolve) {
process.chdir('./src');
resolve();
})
.then(() => process.chdir('./app'))
.then(() => process.chdir('./1'))
.then(() => {
process.env.CWD = process.cwd();
return ng(['generate', 'pipe', 'my-pipe'])
})
.then(() => {
var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', '1', 'my-pipe.pipe.ts');
expect(existsSync(testPath)).to.equal(true);
}, err => console.log('ERR: ', err));
});
it('ng generate pipe child-dir' + path.sep + 'my-pipe from a child dir', () => {
fs.mkdirsSync(path.join(root, 'tmp', 'foo', 'src', 'app', '1', 'child-dir'));
return new Promise(function (resolve) {
process.chdir('./src');
resolve();
})
.then(() => process.chdir('./app'))
.then(() => process.chdir('./1'))
.then(() => {
process.env.CWD = process.cwd();
return ng(['generate', 'pipe', 'child-dir' + path.sep + 'my-pipe'])
})
.then(() => {
var testPath = path.join(
root, 'tmp', 'foo', 'src', 'app', '1', 'child-dir', 'my-pipe.pipe.ts');
expect(existsSync(testPath)).to.equal(true);
}, err => console.log('ERR: ', err));
});
it('ng generate pipe child-dir' + path.sep + '..' + path.sep + 'my-pipe from a child dir', () => {
fs.mkdirsSync(path.join(root, 'tmp', 'foo', 'src', 'app', '1'));
return new Promise(function (resolve) {
process.chdir('./src');
resolve();
})
.then(() => process.chdir('./app'))
.then(() => process.chdir('./1'))
.then(() => {
process.env.CWD = process.cwd();
return ng(['generate', 'pipe', 'child-dir' + path.sep + '..' + path.sep + 'my-pipe'])
})
.then(() => {
var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', '1', 'my-pipe.pipe.ts');
expect(existsSync(testPath)).to.equal(true);
}, err => console.log('ERR: ', err));
});
it('ng generate pipe ' + path.sep + 'my-pipe from a child dir, gens under ' +
path.join('src', 'app'),
() => {
fs.mkdirsSync(path.join(root, 'tmp', 'foo', 'src', 'app', '1'));
return new Promise(function (resolve) {
process.chdir('./src');
resolve();
})
.then(() => process.chdir('./app'))
.then(() => process.chdir('./1'))
.then(() => {
process.env.CWD = process.cwd();
return ng(['generate', 'pipe', path.sep + 'my-pipe'])
})
.then(() => {
var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', 'my-pipe.pipe.ts');
expect(existsSync(testPath)).to.equal(true);
}, err => console.log('ERR: ', err));
});
it('ng generate pipe ..' + path.sep + 'my-pipe from root dir will fail', () => {
return ng(['generate', 'pipe', '..' + path.sep + 'my-pipe']).then(() => {
throw new SilentError(`ng generate pipe ..${path.sep}my-pipe from root dir should fail.`);
}, (err) => {
expect(err).to.equal(`Invalid path: "..${path.sep}my-pipe" cannot be above the "src${path.sep}app" directory`);
});
});
});