Skip to content
This repository was archived by the owner on Dec 17, 2018. It is now read-only.

Commit 02b0b55

Browse files
committedJul 23, 2017
#7 Tests for erector-set template object generation
Also added .vscode to .gitignore
1 parent b089a1f commit 02b0b55

File tree

3 files changed

+114
-4
lines changed

3 files changed

+114
-4
lines changed
 

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.idea/
22
.nyc_output
3+
.vscode
34
coverage
45
*.tgz
56
debug.log

‎test/tools/utilities/files.spec.js

+112-3
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,118 @@ tap.test('#deleteFolder', (suite) => {
121121
});
122122

123123
tap.test('#getTemplates', (suite) => {
124-
// return a list erector template objects
125-
// use .destination if provided
126-
// set template to blank if .blank is true
124+
const create = (templates) =>
125+
files.getTemplates('/root', '/root/current', templates);
126+
let mockResolve;
127+
128+
suite.beforeEach((done) => {
129+
mockResolve = sinon.stub(path, 'resolve');
130+
mockResolve.callsFake(function() {
131+
return Array.prototype.slice.call(arguments)
132+
.join('/');
133+
});
134+
135+
done();
136+
});
137+
138+
suite.afterEach((done) => {
139+
mockResolve.restore();
140+
141+
done();
142+
});
143+
144+
suite.test('should return a list of erector template objects', (test) => {
145+
test.plan(1);
146+
147+
const templates = create([
148+
{ name: 'pizza', overwrite: false },
149+
{ name: 'broccoli', update: true },
150+
{ name: 'burger' }
151+
]);
152+
153+
test.deepEqual(templates, [
154+
{
155+
check: undefined,
156+
destination: '/root/pizza',
157+
overwrite: false,
158+
template: '/root/current/templates/pizza',
159+
update: undefined
160+
},
161+
{
162+
check: undefined,
163+
destination: '/root/broccoli',
164+
overwrite: undefined,
165+
template: '/root/current/templates/broccoli',
166+
update: true
167+
},
168+
{
169+
check: undefined,
170+
destination: '/root/burger',
171+
overwrite: undefined,
172+
template: '/root/current/templates/burger',
173+
update: undefined
174+
}
175+
]);
176+
177+
test.end();
178+
});
179+
180+
suite.test('should utilize the destination field if provided', (test) => {
181+
test.plan(1);
182+
183+
const templates = create([
184+
{ name: 'pizza', destination: '/the/pizzeria/palace' },
185+
{ name: 'burger' }
186+
]);
187+
188+
test.deepEqual(templates, [
189+
{
190+
check: undefined,
191+
destination: '/the/pizzeria/palace',
192+
overwrite: undefined,
193+
template: '/root/current/templates/pizza',
194+
update: undefined
195+
},
196+
{
197+
check: undefined,
198+
destination: '/root/burger',
199+
overwrite: undefined,
200+
template: '/root/current/templates/burger',
201+
update: undefined
202+
}
203+
]);
204+
205+
test.end();
206+
});
207+
208+
suite.test('should provide a blank template if .blank is truthy', (test) => {
209+
test.plan(1);
210+
211+
const templates = create([
212+
{ name: 'pizza' },
213+
{ blank: true, name: 'broccoli' }
214+
]);
215+
216+
test.deepEqual(templates, [
217+
{
218+
check: undefined,
219+
destination: '/root/pizza',
220+
overwrite: undefined,
221+
template: '/root/current/templates/pizza',
222+
update: undefined
223+
},
224+
{
225+
check: undefined,
226+
destination: '/root/broccoli',
227+
overwrite: undefined,
228+
template: undefined,
229+
update: undefined
230+
}
231+
]);
232+
233+
test.end();
234+
});
235+
127236
suite.end();
128237
});
129238

‎tools/utilities/files.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const removePath = (folder, file) => {
2323
exports.getTemplates = (rootDir, directory, filenames) => filenames.map((filename) => ({
2424
check: filename.check,
2525
destination: filename.destination || path.resolve(rootDir, filename.name),
26-
template: filename.blank ? undefined : [directory, 'templates', filename.name].join(path.sep),
26+
template: filename.blank ? undefined : path.resolve(directory, 'templates', filename.name),
2727
update: filename.update,
2828
overwrite: filename.overwrite
2929
}));

0 commit comments

Comments
 (0)
This repository has been archived.