forked from ember-cli/ember-cli
/
destroy-test.js
156 lines (119 loc) · 4.12 KB
/
destroy-test.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
'use strict';
const ember = require('../helpers/ember');
const fs = require('fs-extra');
const path = require('path');
let root = process.cwd();
let tmproot = path.join(root, 'tmp');
const mkTmpDirIn = require('../../lib/utilities/mk-tmp-dir-in');
const Blueprint = require('../../lib/models/blueprint');
const BlueprintNpmTask = require('ember-cli-internal-test-helpers/lib/helpers/disable-npm-on-blueprint');
const chai = require('../chai');
let expect = chai.expect;
let file = chai.file;
describe('Acceptance: ember destroy', function () {
this.timeout(60000);
let tmpdir;
before(function () {
BlueprintNpmTask.disableNPM(Blueprint);
});
after(function () {
BlueprintNpmTask.restoreNPM(Blueprint);
});
beforeEach(async function () {
tmpdir = await mkTmpDirIn(tmproot);
process.chdir(tmpdir);
});
afterEach(function () {
process.chdir(root);
return fs.remove(tmproot);
});
function initApp() {
return ember(['init', '--name=my-app', '--skip-npm', '--skip-bower']);
}
function generate(args) {
let generateArgs = ['generate'].concat(args);
return ember(generateArgs);
}
function destroy(args) {
let destroyArgs = ['destroy'].concat(args);
return ember(destroyArgs);
}
function assertFilesExist(files) {
files.forEach(function (f) {
expect(file(f)).to.exist;
});
}
function assertFilesNotExist(files) {
files.forEach(function (f) {
expect(file(f)).to.not.exist;
});
}
const assertDestroyAfterGenerate = async function (args, files) {
await initApp();
await generate(args);
assertFilesExist(files);
let result = await destroy(args);
expect(result, 'destroy command did not exit with errorCode').to.be.an('object');
assertFilesNotExist(files);
};
it('blueprint foo', function () {
let commandArgs = ['blueprint', 'foo'];
let files = ['blueprints/foo/index.js'];
return assertDestroyAfterGenerate(commandArgs, files);
});
it('blueprint foo/bar', function () {
let commandArgs = ['blueprint', 'foo/bar'];
let files = ['blueprints/foo/bar/index.js'];
return assertDestroyAfterGenerate(commandArgs, files);
});
it('http-mock foo', function () {
let commandArgs = ['http-mock', 'foo'];
let files = ['server/mocks/foo.js'];
return assertDestroyAfterGenerate(commandArgs, files);
});
it('http-proxy foo', function () {
let commandArgs = ['http-proxy', 'foo', 'bar'];
let files = ['server/proxies/foo.js'];
return assertDestroyAfterGenerate(commandArgs, files);
});
it('deletes files generated using blueprint paths', function () {
let commandArgs = [`${__dirname}/../../blueprints/http-proxy`, 'foo', 'bar'];
let files = ['server/proxies/foo.js'];
return assertDestroyAfterGenerate(commandArgs, files);
});
it('deletes files generated using blueprints from the project directory', async function () {
let commandArgs = ['foo', 'bar'];
let files = ['app/foos/bar.js'];
await initApp();
await fs.outputFile(
'blueprints/foo/files/app/foos/__name__.js',
"import Ember from 'ember';\n\n" + 'export default Ember.Object.extend({ foo: true });\n'
);
await generate(commandArgs);
assertFilesExist(files);
await destroy(commandArgs);
assertFilesNotExist(files);
});
it('correctly identifies the root of the project', async function () {
let commandArgs = ['controller', 'foo'];
let files = ['app/controllers/foo.js'];
await initApp();
await fs.outputFile(
'blueprints/controller/files/app/controllers/__name__.js',
"import Ember from 'ember';\n\n" + 'export default Ember.Controller.extend({ custom: true });\n'
);
await generate(commandArgs);
assertFilesExist(files);
process.chdir(path.join(tmpdir, 'app'));
await destroy(commandArgs);
process.chdir(tmpdir);
assertFilesNotExist(files);
});
it('http-mock <name> does not remove server/', async function () {
await initApp();
await generate(['http-mock', 'foo']);
await generate(['http-mock', 'bar']);
await destroy(['http-mock', 'foo']);
expect(file('server/index.js')).to.exist;
});
});