-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathinit-test.js
More file actions
239 lines (176 loc) · 6.59 KB
/
init-test.js
File metadata and controls
239 lines (176 loc) · 6.59 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
'use strict';
const ember = require('../helpers/ember');
const walkSync = require('walk-sync');
const { globSync } = require('glob');
const Blueprint = require('../../lib/models/blueprint');
const path = require('path');
const fs = require('fs');
const os = require('os');
let root = process.cwd();
const util = require('util');
const { minimatch } = require('minimatch');
const intersect = require('lodash/intersection');
const remove = require('lodash/remove');
const EOL = require('os').EOL;
const td = require('testdouble');
const lintFix = require('../../lib/utilities/lint-fix');
const { isExperimentEnabled } = require('@ember-tooling/blueprint-model/utilities/experiments');
const { DEPRECATIONS } = require('../../lib/debug');
const { confirmViteBlueprint } = require('../helpers-internal/blueprint');
const { expect } = require('chai');
const { dir, file } = require('chai-files');
let defaultIgnoredFiles = Blueprint.ignoredFiles;
describe('Acceptance: ember init', function () {
this.timeout(20000);
async function makeTempDir() {
let baseTmpDir = await fs.promises.mkdtemp(path.join(os.tmpdir(), 'init-test'));
let projectDir = path.join(baseTmpDir, 'hello-world');
await fs.promises.mkdir(projectDir);
return projectDir;
}
let tmpPath;
beforeEach(async function () {
Blueprint.ignoredFiles = defaultIgnoredFiles;
tmpPath = await makeTempDir();
process.chdir(tmpPath);
});
afterEach(function () {
td.reset();
process.chdir(root);
});
function confirmBlueprinted(typescript = false) {
if (isExperimentEnabled('VITE')) {
confirmViteBlueprint();
return;
}
let blueprintPath = path.join(path.dirname(require.resolve('@ember-tooling/classic-build-app-blueprint')), 'files');
// ignore TypeScript files
let expected = walkSync(blueprintPath, {
ignore: ['tsconfig.json', 'types', 'app/config'],
}).map((name) => (typescript ? name : name.replace(/\.ts$/, '.js')));
// This style of assertion can't handle conditionally available files
if (expected.some((x) => x.endsWith('eslint.config.mjs'))) {
expected = [...expected.filter((x) => !x.endsWith('eslint.config.mjs')), 'eslint.config.mjs'];
}
// GJS and GTS files are also conditionally available
expected = expected.filter((x) => !x.endsWith('.gjs') && !x.endsWith('.gts'));
expected.sort();
let actual = walkSync('.').sort();
Object.keys(Blueprint.renamedFiles).forEach((srcFile) => {
expected[expected.indexOf(srcFile)] = Blueprint.renamedFiles[srcFile];
});
removeIgnored(expected);
removeIgnored(actual);
removeTmp(expected);
removeTmp(actual);
expected.sort();
expect(expected).to.deep.equal(
actual,
`${EOL} expected: ${util.inspect(expected)}${EOL} but got: ${util.inspect(actual)}`
);
}
function confirmGlobBlueprinted(pattern) {
let blueprintPath = path.join(path.dirname(require.resolve('@ember-tooling/classic-build-app-blueprint')), 'files');
let actual = pickSync('.', pattern);
let expected = intersect(actual, pickSync(blueprintPath, pattern));
removeIgnored(expected);
removeIgnored(actual);
removeTmp(expected);
removeTmp(actual);
expected.sort();
expect(expected).to.deep.equal(
actual,
`${EOL} expected: ${util.inspect(expected)}${EOL} but got: ${util.inspect(actual)}`
);
}
function pickSync(filePath, pattern) {
return globSync(`**/${pattern}`, {
cwd: filePath,
dot: true,
mark: true,
}).sort();
}
function removeTmp(array) {
remove(array, function (entry) {
return /^tmp[\\/]$/.test(entry);
});
}
function removeIgnored(array) {
remove(array, function (fn) {
return Blueprint.ignoredFiles.some(function (ignoredFile) {
return minimatch(fn, ignoredFile, {
matchBase: true,
});
});
});
}
it('ember init', async function () {
await ember(['init', '--skip-npm']);
confirmBlueprinted();
});
it("init an already init'd folder", async function () {
await ember(['init', '--skip-npm']);
await ember(['init', '--skip-npm']);
confirmBlueprinted();
});
it('init a single file', async function () {
if (DEPRECATIONS.INIT_TARGET_FILES.isRemoved || isExperimentEnabled('VITE')) {
this.skip();
}
await ember(['init', 'app.js', '--skip-npm']);
confirmGlobBlueprinted('app.js');
});
it("init a single file on already init'd folder", async function () {
if (DEPRECATIONS.INIT_TARGET_FILES.isRemoved || isExperimentEnabled('VITE')) {
this.skip();
}
await ember(['init', '--skip-npm']);
await ember(['init', 'app.js', '--skip-npm']);
confirmBlueprinted();
});
it('init multiple files by glob pattern', async function () {
if (DEPRECATIONS.INIT_TARGET_FILES.isRemoved || isExperimentEnabled('VITE')) {
this.skip();
}
await ember(['init', 'app/**', '--skip-npm']);
confirmGlobBlueprinted('app/**');
});
it("init multiple files by glob pattern on already init'd folder", async function () {
if (DEPRECATIONS.INIT_TARGET_FILES.isRemoved || isExperimentEnabled('VITE')) {
this.skip();
}
await ember(['init', '--skip-npm']);
await ember(['init', 'app/**', '--skip-npm']);
confirmBlueprinted();
});
it('init multiple files by glob patterns', async function () {
if (DEPRECATIONS.INIT_TARGET_FILES.isRemoved || isExperimentEnabled('VITE')) {
this.skip();
}
await ember(['init', 'app/**', 'package.json', 'resolver.js', '--skip-npm']);
confirmGlobBlueprinted('{app/**,package.json,resolver.js}');
});
it("init multiple files by glob patterns on already init'd folder", async function () {
if (DEPRECATIONS.INIT_TARGET_FILES.isRemoved || isExperimentEnabled('VITE')) {
this.skip();
}
await ember(['init', '--skip-npm']);
await ember(['init', 'app/**', 'package.json', 'resolver.js', '--skip-npm']);
confirmBlueprinted();
});
it('should not create .git folder', async function () {
await ember(['init', '--skip-npm']);
expect(dir('.git')).to.not.exist;
});
it('calls lint fix function', async function () {
let lintFixStub = td.replace(lintFix, 'run');
await ember(['init', '--skip-npm', '--lint-fix']);
td.verify(lintFixStub(), { ignoreExtraArgs: true, times: 1 });
confirmBlueprinted();
});
it('no CI provider', async function () {
await ember(['init', '--ci-provider=none', '--skip-install', '--skip-git']);
expect(file('.github/workflows/ci.yml')).to.not.exist;
expect(file('config/ember-cli-update.json')).to.include('--ci-provider=none');
});
});