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

Improve code quality by increasing code coverage: lib/source-map-from-file.js #453

Closed
Closed
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
2 changes: 1 addition & 1 deletion lib/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ try {
const { readdirSync, readFileSync, statSync } = require('fs')
const { isAbsolute, resolve, extname } = require('path')
const { pathToFileURL, fileURLToPath } = require('url')
const getSourceMapFromFile = require('./source-map-from-file')
const { getSourceMapFromFile } = require('./source-map-from-file')
// TODO: switch back to @c88/v8-coverage once patch is landed.
const v8toIstanbul = require('v8-to-istanbul')
const util = require('util')
Expand Down
12 changes: 11 additions & 1 deletion lib/source-map-from-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,13 @@ function sourceMapFromDataUrl (url) {
const { 0: format, 1: data } = url.split(',')
const splitFormat = format.split(';')
const contentType = splitFormat[0]
// always evaluates to true for our use cases. Could possibly be false.
// Per https://github.com/bcoe/c8/pull/453#discussion_r1106306167
const base64 = splitFormat[splitFormat.length - 1] === 'base64'
if (contentType === 'application/json') {
// the data variable is never a json string in the test cases
// the upstream branch in node.js still has this logic
// https://github.com/nodejs/node/blob/v19.x/lib/internal/source_map/source_map_cache.js#L241
const decodedData = base64 ? Buffer.from(data, 'base64').toString('utf8') : data
try {
return JSON.parse(decodedData)
Expand All @@ -97,4 +102,9 @@ function sourceMapFromDataUrl (url) {
}
}

module.exports = getSourceMapFromFile
module.exports = {
getSourceMapFromFile,
dataFromUrl,
sourceMapFromFile,
sourceMapFromDataUrl
}
Loading
Loading