Skip to content

Commit 10b8f6e

Browse files
committed
Update test codes
1 parent 4a28181 commit 10b8f6e

File tree

4 files changed

+35
-50
lines changed

4 files changed

+35
-50
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
"license": "MIT",
2525
"readmeFilename": "README.md",
2626
"devDependencies": {
27-
"chai": "^3.2.0",
28-
"coffee-script": "~1.9",
27+
"bluebird": "^3.3.5",
2928
"coveralls": "~2.11",
3029
"istanbul": "^0.4.3",
31-
"mocha": "^2.3.0"
30+
"mocha": "^2.3.0",
31+
"power-assert": "^1.3.1"
3232
}
3333
}

test/helper.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict';
2+
3+
const fs = require('fs');
4+
5+
global.Promise = require('bluebird');
6+
global.readFile = Promise.promisify(fs.readFile);
7+
global.assert = require('power-assert');

test/json2lcov-cli.js

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,23 @@
11
'use strict';
22

3-
var fs = require('fs'),
4-
path = require('path'),
5-
exec = require('child_process').exec,
6-
expect = require('chai').expect,
7-
jsoncovToLcov = require('../lib/json2lcov');
8-
9-
describe('json2lcov-cli', function(){
10-
11-
var expectLcovContent = '';
12-
13-
beforeEach(function(done){
14-
fs.readFile( path.resolve('./test/fixtures/fixture.lcov'), function (error, content) {
15-
expectLcovContent = content.toString();
16-
done();
3+
const fs = require('fs');
4+
const path = require('path');
5+
const exec = require('child_process').exec;
6+
const jsoncovToLcov = require('../lib/json2lcov');
7+
8+
describe('json2lcov-cli', function() {
9+
beforeEach(function() {
10+
return readFile('./test/fixtures/fixture.lcov').then((content) => {
11+
this.lcov = content.toString();
1712
});
1813
});
1914

20-
it('converted into lcov from json-cov', function(done){
15+
it('converted into lcov from json-cov', function(done) {
16+
const fixtureFile = path.resolve('./test/fixtures/fixture.json');
2117

22-
var fixtureFile = path.resolve('./test/fixtures/fixture.json');
23-
24-
exec('cat ' + fixtureFile + ' | ./bin/json2lcov.js', function (error, stdout, stderr) {
25-
expect(stdout.toString()).to.equals(expectLcovContent);
18+
exec('cat ' + fixtureFile + ' | ./bin/json2lcov.js', (error, stdout, stderr) => {
19+
assert.equal(stdout.toString(), this.lcov);
2620
done();
2721
});
28-
2922
});
30-
3123
});

test/json2lcov.js

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,21 @@
11
'use strict';
22

3-
var fs = require('fs'),
4-
path = require('path'),
5-
expect = require('chai').expect,
6-
jsoncovToLcov = require('../lib/json2lcov');
7-
8-
describe('json2lcov', function(){
9-
10-
var expectLcovContent = '';
11-
12-
beforeEach(function(done){
13-
fs.readFile( path.resolve('./test/fixtures/fixture.lcov'), function (error, content) {
14-
expectLcovContent = content.toString();
15-
done();
3+
const fs = require('fs');
4+
const path = require('path');
5+
const jsoncovToLcov = require('../lib/json2lcov');
6+
7+
describe('json2lcov', function() {
8+
beforeEach(function() {
9+
return readFile('./test/fixtures/fixture.lcov').then((content) => {
10+
this.lcov = content.toString();
1611
});
1712
});
1813

19-
it('converted into lcov from json-cov', function(done){
20-
21-
fs.readFile( path.resolve('./test/fixtures/fixture.json'), function (error, content) {
22-
23-
if (error) {
24-
throw error;
25-
}
26-
27-
var result = jsoncovToLcov( JSON.parse(content.toString()) );
28-
expect(result).to.equals(expectLcovContent);
29-
done();
14+
it('converted into lcov from json-cov', function() {
15+
return readFile('./test/fixtures/fixture.json').then((content) => {
16+
const result = jsoncovToLcov( JSON.parse(content.toString()) );
3017

18+
assert.equal(result, this.lcov);
3119
});
32-
3320
});
34-
3521
});

0 commit comments

Comments
 (0)