Skip to content

Commit 2a63c08

Browse files
committed
work toward fixing async coverage assertions
1 parent 374efd9 commit 2a63c08

7 files changed

Lines changed: 55 additions & 19 deletions

File tree

.jshintrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"browser": true,
3+
"jquery": true,
4+
"node": true
5+
}

lib/child.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ function run() {
130130
_require(options.code, true);
131131

132132
// require tests
133-
options.tests.forEach(function(res) {
134-
_require(res, false);
133+
options.tests.forEach(function(test) {
134+
_require(test, false);
135135
});
136136
}
137137

lib/coverage.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ exports.add = function(coverage) {
1717
};
1818

1919
exports.get = function() {
20-
var summaries
20+
var summaries;
2121
if (collector) {
2222
summaries = [];
2323
collector.files().forEach(function(file) {
@@ -54,10 +54,10 @@ exports.instrument = function(options, callback) {
5454
includes: resolvePaths(options.code),
5555
excludes: resolvePaths(options.tests)
5656
}, function (err, matcher) {
57-
var instrumenter
57+
var instrumenter;
5858

5959
if (err) {
60-
return callback(err)
60+
return callback(err);
6161
}
6262

6363
instrumenter = new istanbul.Instrumenter();

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@
1919
"test": "make test"
2020
},
2121
"dependencies": {
22-
"underscore": "1.3.3",
23-
"argsparser": "0.0.6",
24-
"cli-table": "0.0.2",
25-
"tracejs": "0.1.4"
22+
"underscore": "1.3.3",
23+
"argsparser": "0.0.6",
24+
"cli-table": "0.0.2",
25+
"tracejs": "0.1.4"
2626
},
2727
"devDependencies": {
2828
"chainer": "0.0.5",
2929
"timekeeper": "0.0.2"
3030
},
3131
"optionalDependencies": {
32-
"istanbul": "0.2.4"
32+
"istanbul": "0.2.4"
3333
},
3434
"licenses": [
3535
{

test/fixtures/coverage-code.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
exports.myMethod = function() {
2+
return 123;
3+
};
4+
5+
exports.myAsyncMethod = function(callback) {
6+
setTimeout(function() {
7+
callback(123);
8+
}, 10000);
9+
};

test/fixtures/coverage-test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
test('myMethod test', function() {
2+
equal(myMethod(), 123, 'myMethod returns right result');
3+
});
4+
5+
test('myAsyncMethod test', function() {
6+
ok(true, 'myAsyncMethod started');
7+
8+
stop();
9+
expect(2);
10+
11+
myAsyncMethod(function(data) {
12+
equal(data, 123, 'myAsyncMethod returns right result');
13+
start();
14+
});
15+
});

test/testrunner.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -155,18 +155,26 @@ chain.add('uncaught exception', function() {
155155
chain.add('coverage', function() {
156156
tr.options.coverage = true;
157157
tr.run({
158-
code: fixtures + '/testrunner-code.js',
159-
tests: fixtures + '/testrunner-tests.js',
158+
code: fixtures + '/coverage-code.js',
159+
tests: fixtures + '/coverage-test.js'
160160
}, function(err, res) {
161-
var coverage = {
161+
var stat = {
162162
files: 1,
163-
statements: { covered: 4, total: 5 },
164-
branches: { covered: 0, total: 0 },
165-
functions: { covered: 2, total: 3 },
166-
lines: { covered: 4, total: 5 }
163+
tests: 2,
164+
assertions: 3,
165+
failed: 0,
166+
passed: 3,
167+
coverage: {
168+
files: 1,
169+
statements: { covered: 4, total: 5 },
170+
branches: { covered: 0, total: 0 },
171+
functions: { covered: 2, total: 3 },
172+
lines: { covered: 4, total: 5 }
173+
}
167174
};
175+
delete res.runtime;
168176
a.equal(err, null, 'no errors');
169-
a.deepEqual(coverage, res.coverage, 'Coverage calculated');
177+
a.deepEqual(stat, res, 'coverage code testing works');
170178
chain.next();
171179
});
172180
});
@@ -176,4 +184,3 @@ chain.add(function() {
176184
});
177185

178186
chain.start();
179-

0 commit comments

Comments
 (0)