Skip to content

Commit 1f1f4b3

Browse files
committed
Merge pull request #43 from kribblo/master
--specs: Fix a TypeError, handle the "requests": [number] example from the docs
2 parents b4eb56b + 4b7acba commit 1f1f4b3

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

lib/specs.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,15 @@ function specsRunner(specs, reporter, callback, err, data) {
125125
path.pop();
126126
return;
127127
}
128-
if (typeof data[key] === 'object') {
129-
traverse(specs[key], data[key]);
128+
129+
var spec = specs[key];
130+
if (typeof spec === 'object' && !spec.min && !spec.max) {
131+
traverse(spec, data[key]);
132+
} else if(typeof spec === 'number' && Array.isArray(data[key])) {
133+
tests.push(buildTest(path.join('.'), spec, data[key].length, defaults));
134+
path.pop();
130135
} else {
131-
tests.push(buildTest(path.join('.'), specs[key], data[key], defaults));
136+
tests.push(buildTest(path.join('.'), spec, data[key], defaults));
132137
path.pop();
133138
}
134139
});

test/fixtures/specs.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@
1414
"text": "page load time: {actual} should be less than {expected}",
1515
"max": 5000
1616
},
17-
"foo": {
18-
"bar": {
19-
"max": 100
20-
}
21-
},
2217
"score_keep-alive": {
2318
"min": 90
2419
}

test/specs-test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ describe('Example WebPageTest for Specs', function() {
3232
runs: 3,
3333
waitResults: '127.0.0.1:8000',
3434
medianMetric: 'TTFB',
35-
specs: '{"defaults":{"suiteName":"WPT test of test (not really an error)"},"median":{"firstView":{"render":300,"TTFB":100,"loadTime":4000}}}',
35+
specs: '{"defaults":{"suiteName":"WPT test of test (not really an error)"},"median":{"firstView":{"render":800,"TTFB":600,"loadTime":4000}}}',
3636
reporter: 'min'
3737
}, function(err) {
38-
assert.equal(err, 2);
38+
assert.equal(err, 0);
3939
done();
4040
});
4141
setTimeout(function() {
@@ -49,7 +49,7 @@ describe('Example WebPageTest for Specs', function() {
4949
specs: path.join(__dirname, './fixtures/specs.json'),
5050
reporter: 'spec'
5151
}, function(err) {
52-
assert.equal(err, 1);
52+
assert.equal(err, 0);
5353
done();
5454
});
5555
});

0 commit comments

Comments
 (0)