Skip to content

Commit

Permalink
chore: adding integration tests for source-maps
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe committed May 2, 2019
1 parent 12cf864 commit 36b651d
Show file tree
Hide file tree
Showing 11 changed files with 184 additions and 6 deletions.
5 changes: 0 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
"istanbul-reports": "^2.0.0",
"rimraf": "^2.6.2",
"test-exclude": "^5.0.0",
"uuid": "^3.3.2",
"v8-to-istanbul": "^3.0.1",
"yargs": "^13.1.0",
"yargs-parser": "^10.1.0"
Expand Down
20 changes: 20 additions & 0 deletions test/fixtures/source-maps/branches/branches.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
if (false) {
console.info('unreachable')
} else if (true) {
console.info('reachable')
} else {
console.info('unreachable')
}

function branch (a) {
if (a) {
console.info('a = true')
} else if (undefined) {
console.info('unreachable')
} else {
console.info('a = false')
}
}

branch(true)
branch(false)
2 changes: 2 additions & 0 deletions test/fixtures/source-maps/branches/branches.nyc.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions test/fixtures/source-maps/branches/branches.typescript.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions test/fixtures/source-maps/branches/branches.typescript.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
enum ATrue {
IsTrue = 1,
IsFalse = 0
}

if (false) {
console.info('unreachable')
} else if (true) {
console.info('reachable')
} else {
console.info('unreachable')
}

function branch (a: boolean) {
if (a) {
console.info('a = true')
} else if (undefined) {
console.info('unreachable')
} else {
console.info('a = false')
}
}

branch(!!ATrue.IsTrue)
branch(!!ATrue.IsFalse)
2 changes: 2 additions & 0 deletions test/fixtures/source-maps/branches/branches.uglify.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/fixtures/source-maps/branches/branches.uglify.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 53 additions & 0 deletions test/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,57 @@ describe('c8', () => {
output.toString('utf8').should.matchSnapshot()
})
})

describe('source-maps', () => {
beforeEach(cb => rimraf('tmp/source-map', cb))

describe('TypeScript', () => {
// Bugs:
// closing '}' on `if` is not covered.
it('remaps branches', () => {
const { output } = spawnSync(nodePath, [
c8Path,
'--exclude="test/*.js"',
'--temp-directory=tmp/source-map',
'--clean=false',
nodePath,
require.resolve('./fixtures/source-maps/branches/branches.typescript.js')
])
output.toString('utf8').should.matchSnapshot()
})
})

// Bugs:
// string in `console.info` shown as uncovered branch.
describe('UglifyJS 3', () => {
it('remaps branches', () => {
const { output } = spawnSync(nodePath, [
c8Path,
'--exclude="test/*.js"',
'--temp-directory=tmp/source-map',
'--clean=false',
nodePath,
require.resolve('./fixtures/source-maps/branches/branches.uglify.js')
])
output.toString('utf8').should.matchSnapshot()
})
})

describe('nyc', () => {
// Bugs:
// first 'if' statement indicates two odd missing branches.
// line 4 should be covered.
it('remaps branches', () => {
const { output } = spawnSync(nodePath, [
c8Path,
'--exclude="test/*.js"',
'--temp-directory=tmp/source-map',
'--clean=false',
nodePath,
require.resolve('./fixtures/source-maps/branches/branches.nyc.js')
])
output.toString('utf8').should.matchSnapshot()
})
})
})
})
52 changes: 52 additions & 0 deletions test/integration.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,55 @@ All files | 83.33 | 85.71 | 60 | 83.33 | |
-----------|----------|----------|----------|----------|-------------------|
,"
`;

exports[`c8 source-maps TypeScript remaps branches 1`] = `
",reachable
a = true
a = false
------------------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
------------------------|----------|----------|----------|----------|-------------------|
All files | 84 | 57.14 | 100 | 84 | |
branches.typescript.ts | 84 | 57.14 | 100 | 84 | 7,11,12,18 |
------------------------|----------|----------|----------|----------|-------------------|
,"
`;

exports[`c8 source-maps UglifyJS 3 nyc remaps branches 1`] = `
",reachable
a = true
a = false
-------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
-------------|----------|----------|----------|----------|-------------------|
All files | 70 | 44.44 | 100 | 70 | |
branches.js | 70 | 44.44 | 100 | 70 | 2,4,5,6,7,13 |
-------------|----------|----------|----------|----------|-------------------|
,"
`;

exports[`c8 source-maps UglifyJS 3 remaps branches 1`] = `
",reachable
a = true
a = false
-------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
-------------|----------|----------|----------|----------|-------------------|
All files | 80 | 50 | 100 | 80 | |
branches.js | 80 | 50 | 100 | 80 | 2,5,6,13 |
-------------|----------|----------|----------|----------|-------------------|
,"
`;

exports[`c8 source-maps nyc remaps branches 1`] = `
",reachable
a = true
a = false
-------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
-------------|----------|----------|----------|----------|-------------------|
All files | 70 | 44.44 | 100 | 70 | |
branches.js | 70 | 44.44 | 100 | 70 | 2,4,5,6,7,13 |
-------------|----------|----------|----------|----------|-------------------|
,"
`;

0 comments on commit 36b651d

Please sign in to comment.