forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnew.spec.js
More file actions
151 lines (123 loc) · 5.15 KB
/
Copy pathnew.spec.js
File metadata and controls
151 lines (123 loc) · 5.15 KB
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
'use strict';
var fs = require('fs-extra');
var ng = require('../helpers/ng');
var existsSync = require('exists-sync');
var expect = require('chai').expect;
var forEach = require('lodash/forEach');
var walkSync = require('walk-sync');
var Blueprint = require('ember-cli/lib/models/blueprint');
var path = require('path');
var tmp = require('../helpers/tmp');
var root = process.cwd();
var util = require('util');
var conf = require('ember-cli/tests/helpers/conf');
var EOL = require('os').EOL;
var SilentError = require('silent-error');
describe('Acceptance: ng new', function () {
before(conf.setup);
after(conf.restore);
beforeEach(function () {
return tmp.setup('./tmp').then(function () {
process.chdir('./tmp');
});
});
afterEach(function () {
this.timeout(10000);
return tmp.teardown('./tmp');
});
function confirmBlueprintedForDir(dir) {
return function () {
var blueprintPath = path.join(root, dir, 'files');
var expected = walkSync(blueprintPath);
var actual = walkSync('.').sort();
var directory = path.basename(process.cwd());
forEach(Blueprint.renamedFiles, function (destFile, srcFile) {
expected[expected.indexOf(srcFile)] = destFile;
});
expected.forEach(function (file, index) {
expected[index] = file.replace(/__name__/g, 'angular-cli');
});
expected.sort();
expect(directory).to.equal('foo');
expect(expected).to.deep.equal(
actual,
EOL + ' expected: ' + util.inspect(expected) + EOL + ' but got: ' + util.inspect(actual));
};
}
function confirmBlueprinted() {
return confirmBlueprintedForDir('blueprints/ng2');
}
it('ng new foo, where foo does not yet exist, works', function () {
return ng(['new', 'foo', '--skip-npm', '--skip-bower']).then(confirmBlueprinted);
});
it('ng new with empty app does throw exception', function () {
expect(ng(['new', ''])).to.throw;
});
it('ng new without app name does throw exception', function () {
expect(ng(['new', ''])).to.throw;
});
it('ng new with app name creates new directory and has a dasherized package name', function () {
return ng(['new', 'FooApp', '--skip-npm', '--skip-bower', '--skip-git']).then(function () {
expect(!existsSync('FooApp'));
var pkgJson = JSON.parse(fs.readFileSync('package.json', 'utf8'));
expect(pkgJson.name).to.equal('foo-app');
});
});
it('ng new has a .editorconfig file', function () {
return ng(['new', 'FooApp', '--skip-npm', '--skip-bower', '--skip-git']).then(function () {
expect(!existsSync('FooApp'));
var editorConfig = fs.readFileSync('.editorconfig', 'utf8');
expect(editorConfig).to.exist;
});
});
it('Cannot run ng new, inside of ember-cli project', function () {
return ng(['new', 'foo', '--skip-npm', '--skip-bower', '--skip-git'])
.then(function () {
return ng(['new', 'foo', '--skip-npm', '--skip-bower', '--skip-git']).then(() => {
throw new SilentError('Cannot run ng new, inside of ember-cli project should fail.');
}, () => {
expect(!existsSync('foo'));
})
})
.then(confirmBlueprinted);
});
it('ng new without skip-git flag creates .git dir', function () {
return ng(['new', 'foo', '--skip-npm', '--skip-bower']).then(function () {
expect(existsSync('.git'));
});
});
it('ng new with --dry-run does not create new directory', function () {
return ng(['new', 'foo', '--dry-run']).then(function () {
var cwd = process.cwd();
expect(cwd).to.not.match(/foo/, 'does not change cwd to foo in a dry run');
expect(!existsSync(path.join(cwd, 'foo')), 'does not create new directory');
expect(!existsSync(path.join(cwd, '.git')), 'does not create git in current directory');
});
});
it('ng new with --directory uses given directory name and has correct package name', function () {
return ng(['new', 'foo', '--skip-npm', '--skip-bower', '--skip-git', '--directory=bar'])
.then(function () {
var cwd = process.cwd();
expect(cwd).to.not.match(/foo/, 'does not use app name for directory name');
expect(!existsSync(path.join(cwd, 'foo')), 'does not create new directory with app name');
expect(cwd).to.match(/bar/, 'uses given directory name');
expect(existsSync(path.join(cwd, 'bar')), 'creates new directory with specified name');
var pkgJson = JSON.parse(fs.readFileSync('package.json', 'utf8'));
expect(pkgJson.name).to.equal('foo', 'uses app name for package name');
});
});
it('ng new --inline-template does not generate a template file', () => {
return ng(['new', 'foo', '--skip-npm', '--skip-git', '--inline-template'])
.then(() => {
const templateFile = path.join('src', 'app', 'app.component.html');
expect(existsSync(templateFile)).to.equal(false);
});
});
it('ng new --inline-style does not gener a style file', () => {
return ng(['new', 'foo', '--skip-npm', '--skip-git', '--inline-style'])
.then(() => {
const styleFile = path.join('src', 'app', 'app.component.css');
expect(existsSync(styleFile)).to.equal(false);
});
});
});