Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove destroy() behavior #190

Merged
merged 1 commit into from
Apr 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ converter.applyCoverage([
// output coverage information in a form that can
// be consumed by Istanbul.
console.info(JSON.stringify(converter.toIstanbul()))

// cleanup resources allocated in "load" (i.e. by the source-map dependency),
// the converter may not be used anymore afterwards
converter.destroy()
```

## Ignoring Uncovered Lines
Expand Down
2 changes: 1 addition & 1 deletion lib/v8-to-istanbul.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ module.exports = class V8ToIstanbul {
}

destroy () {
this.sourceMap = undefined
// no longer necessary, but preserved for backwards compatibility.
}

_resolveSource (rawSourceMap, sourcePath) {
Expand Down
23 changes: 2 additions & 21 deletions test/v8-to-istanbul.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const sourcemap = require('source-map')
const assert = require('assert')

require('tap').mochaGlobals()
const should = require('should')

describe('V8ToIstanbul', async () => {
describe('constructor', () => {
Expand All @@ -22,8 +21,6 @@ describe('V8ToIstanbul', async () => {
v8ToIstanbul.covSources[0].source.lines.length.should.equal(48)
v8ToIstanbul.covSources.length.should.equal(1)
v8ToIstanbul.wrapperLength.should.equal(0) // common-js header.

v8ToIstanbul.destroy()
})

it('handles ESM style paths', async () => {
Expand All @@ -35,8 +32,6 @@ describe('V8ToIstanbul', async () => {
v8ToIstanbul.covSources[0].source.lines.length.should.equal(48)
v8ToIstanbul.covSources.length.should.equal(1)
v8ToIstanbul.wrapperLength.should.equal(0) // ESM header.

v8ToIstanbul.destroy()
})

it('handles source maps with sourceRoot', async () => {
Expand Down Expand Up @@ -64,8 +59,6 @@ ${'//'}${'#'} sourceMappingURL=data:application/json;base64,${base64Sourcemap}
await v8ToIstanbul.load()

v8ToIstanbul.path.should.equal(absoluteSourceFilePath)

v8ToIstanbul.destroy()
})

it('handles sourceContent', async () => {
Expand Down Expand Up @@ -97,8 +90,6 @@ ${'//'}${'#'} sourceMappingURL=data:application/json;base64,${base64Sourcemap}
// if the source is transpiled and since we didn't inline the source map into the transpiled source file
// that means it was bale to access the content via the provided sources object
v8ToIstanbul.sourceTranspiled.should.not.be.undefined()

v8ToIstanbul.destroy()
})

it('should clamp line source column >= 0', async () => {
Expand Down Expand Up @@ -129,8 +120,6 @@ ${'//'}${'#'} sourceMappingURL=data:application/json;base64,${base64Sourcemap}
endOffset: matchedNewLineChar + 10
}]
}])

v8ToIstanbul.destroy()
})

it('should exclude files when passing excludePath', async () => {
Expand All @@ -149,8 +138,6 @@ ${'//'}${'#'} sourceMappingURL=data:application/json;base64,${base64Sourcemap}
}]
}])
Object.keys(v8ToIstanbul.toIstanbul()).should.eql(['/src/index.ts', '/src/utils.ts'].map(path.normalize))

v8ToIstanbul.destroy()
})
})

Expand All @@ -169,7 +156,6 @@ ${'//'}${'#'} sourceMappingURL=data:application/json;base64,${base64Sourcemap}
0
)
await v8ToIstanbul.load()
v8ToIstanbul.destroy()
})

it('should handle relative sourceRoots correctly', async () => {
Expand All @@ -179,7 +165,6 @@ ${'//'}${'#'} sourceMappingURL=data:application/json;base64,${base64Sourcemap}
)
await v8ToIstanbul.load()
assert(v8ToIstanbul.path.includes(path.normalize('v8-to-istanbul/test/fixtures/one-up/relative-source-root.js')))
v8ToIstanbul.destroy()
})

it('should handles source maps with multiple sources', async () => {
Expand All @@ -191,8 +176,6 @@ ${'//'}${'#'} sourceMappingURL=data:application/json;base64,${base64Sourcemap}

v8ToIstanbul.covSources.length.should.equal(3)
Object.keys(v8ToIstanbul.toIstanbul()).should.eql(['/webpack/bootstrap', '/src/index.ts', '/src/utils.ts'].map(path.normalize))

v8ToIstanbul.destroy()
})
})

Expand All @@ -201,18 +184,16 @@ ${'//'}${'#'} sourceMappingURL=data:application/json;base64,${base64Sourcemap}
pathToFileURL(require.resolve('./fixtures/scripts/no-sourcemap-content.compiled.js')).href
)
await v8ToIstanbul.load()
v8ToIstanbul.destroy()
})

it('test sourcemap content had null', async () => {
const v8ToIstanbul = new V8ToIstanbul(
pathToFileURL(require.resolve('./fixtures/scripts/sourcecontent-null.compiled.js')).href
)
await v8ToIstanbul.load()
v8ToIstanbul.destroy()
})

it('destroy cleans up source map', async () => {
it('destroy no longer cleans up source map', async () => {
const v8ToIstanbul = new V8ToIstanbul(
pathToFileURL(require.resolve('./fixtures/scripts/empty.compiled.js')).href
)
Expand All @@ -223,7 +204,7 @@ ${'//'}${'#'} sourceMappingURL=data:application/json;base64,${base64Sourcemap}

v8ToIstanbul.destroy()

should.not.exist(v8ToIstanbul.sourceMap)
assert(v8ToIstanbul.sourceMap !== undefined)
})

// execute JavaScript files in fixtures directory; these
Expand Down