Skip to content

Commit d525768

Browse files
author
tunnckoCore
committed
update tests
1 parent dcaf5b7 commit d525768

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

test.js

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@
1010
var assert = require('assert');
1111
var fnRegex = require('./index');
1212
var cleanupCoverageCode = require('cleanup-coverage-code');
13+
var coverageCodeRegex = require('coverage-code-regex');
1314
var fixtures = require('./fixtures');
1415

1516
function match(str) {
1617
return str.toString().match(fnRegex());
1718
}
1819

19-
function hackExpected(expected) {
20+
function hackLastTestExpected(expected) {
2021
expected = expected.split('var').filter(Boolean);
2122
expected = expected.map(function(val) {
2223
return val.replace(/\s+/g,'');
@@ -48,8 +49,9 @@ describe('function-regex:', function() {
4849
var expected = 'cmd, args, opts';
4950

5051
// hack, because the coverage tools remove whitespaces
51-
actual = actual.split(',').join(', ');
52-
assert.strictEqual(actual, expected);
52+
actual = actual.replace(/\s+/g, '').split(/,/)
53+
expected = expected.replace(/\s+/g, '').split(',')
54+
assert.deepEqual(actual, expected);
5355

5456
// fixtureTwo
5557
actual = match(fixtures.fixtureTwo().fn)[2]
@@ -61,23 +63,14 @@ describe('function-regex:', function() {
6163

6264
it('should match function body (fixtureOne)', function(done) {
6365
var actual = match(fixtures.fixtureOne().fn)[3]
64-
var expected = hackExpected(fixtures.fixtureOne().body);
65-
66-
// hack, because the coverage tools add some ugly code
67-
// like `__cov_Ejgcx$XN18CSfmeWn$f7vQ.f['2']++`
68-
actual = cleanupCoverageCode(actual);
69-
70-
assert.strictEqual(actual, expected);
71-
done();
72-
});
73-
74-
it('should match function body (fixtureTwo)', function(done) {
75-
var actual = match(fixtures.fixtureOne().fn)[3]
76-
var expected = hackExpected(fixtures.fixtureOne().body);
66+
var expected = fixtures.fixtureOne().body;
7767

7868
// hack, because the coverage tools add some ugly code
7969
// like `__cov_Ejgcx$XN18CSfmeWn$f7vQ.f['2']++`
80-
actual = cleanupCoverageCode(actual);
70+
if (coverageCodeRegex().test(actual)) {
71+
actual = cleanupCoverageCode(actual);
72+
expected = hackLastTestExpected(expected);
73+
}
8174

8275
assert.strictEqual(actual, expected);
8376
done();

0 commit comments

Comments
 (0)