-
Notifications
You must be signed in to change notification settings - Fork 19
/
vows.js
93 lines (76 loc) · 2.43 KB
/
vows.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
/*
* vows.js: Methods for interacting with vows during test execution.
*
* (C) 2010 Charlie Robbins
* MIT LICENSE
*
*/
var vows = require('vows'),
assert = require('assert'),
eyes = require('eyes');
//
// Attempts to match against the pattern. If a match
// is found it should then merge the topics together
// and call the step generator with the merged topic
// and any matches.
//
var mergingTopic = function (step, text, topics) {
var match, topic = {};
if(!(match = step.pattern.match(text))) {
return;
}
topics.forEach(function (item) { topic.merge(item) });
return function () {
step.generator.call(this, topic, match.slice(1));
};
};
exports.findStep = function (text, steps) {
};
exports.createVows = function (filename, features) {
// For each set of features in a single file (i.e. module)
// setup the vows suite to export or run
var suite = vows.describe(filename);
Object.keys(features).forEach(function (i) {
// For each feature create a new batch
var feature = features[i],
batch = {};
feature.scenarios.forEach(function (scenario) {
// For each scenario in the feature, add a context for that scenario
// at the same level: top-level contexts that can be run concurrently.
batch[scenario.name] = exports.scenarioVows(scenario);
});
// The the batch representing the feature to the suite
suite.addBatch(batch);
});
return suite;
};
exports.scenarioVows = function (scenario) {
// Create root context, and set current context to it.
var context = {}, current = context, then = false;
if (scenario.outline) {
// If the scenario is a 'Scenario Outline'
}
else {
// Otherwise if it is just a 'Scenario'
scenario.breakdown.forEach(function (breakdown) {
var breakdown = breakdown[Object.keys(breakdown).shift()],
text = breakdown.join(' ');
// Remark: i18n compatibility here
if(breakdown[0] === 'THEN') {
then = true;
}
if (!then) {
// If we haven't seen 'then' we must make these nested contexts
current[text] = {
topic: text //exports.findStep(text, steps)
};
current = current[text];
}
else {
// If we have passed a 'then' keyword, we can now add tests to this context
current[text] = text //exports.findStep(text, steps);
}
});
}
return context;
};