/
scaffold-tests.js
95 lines (86 loc) · 2.82 KB
/
scaffold-tests.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
module.exports = {
friendlyName: 'Scaffold tests',
description: 'Generate JSON test files for any machines in this local machinepack which don\'t already have them.',
extendedDescription: '',
inputs: {
dir: {
description: 'The path to the machinepack (if path is not absolute, will be resolved from the current working directory)',
example: '/Users/mikermcneil/machinepack-foo/',
required: true
}
},
exits: {
error: {
description: 'Unexpected error occurred.'
},
notMachinepack: {
description: 'The specified path is not the root directory of a machinepack'
},
success: {
description: 'Done.'
}
},
fn: function(inputs, exits) {
var path = require('path');
var async = require('async');
var Filesystem = require('machinepack-fs');
var Machine = require('machine');
Machine.build(require('./read-package-json'))
.configure({
dir: inputs.dir
}).exec({
error: exits.error,
notMachinepack: exits.notMachinepack,
success: function (machinepack){
async.each(machinepack.machines, function (identity, next){
// Determine the path where the test suite should live
var pathToTestSuiteJsonFile = path.resolve(inputs.dir, path.join('tests', identity+'.json'));
// Generate a boilerplate test suite
var suite = {
machine: identity,
expectations: [
// {
// todo: true,
// using: {},
// outcome: 'success'
// }
]
};
// TODO: At some point, come back here and generate a more custom test suite for each machine.
// (note that we'd have to import the machine definition though)
// e.g.
// Generate a test suite for this machine
// var testSuite = {
// machine: identity,
// expectations: (function (){
// return _.reduce();
// })()
// };
// And write it to disk as a new JSON file
// (unless a test already exists w/ the same filename- in that case,
// leave it alone and keep moving)
Filesystem.writeJson({
json: suite,
destination: pathToTestSuiteJsonFile
}).exec({
// An unexpected error occurred.
error: function(err) {
return next(err);
},
// OK.
success: function() {
return next();
},
// A file or folder already exists at the specified `destination`
alreadyExists: function() {
return next();
},
});
}, function (err) {
if (err) return exits.error(err);
return exits.success();
});
}
});
},
};