Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
context.coverage.cov.files = context.coverage.cov.files.map(async (file) => {
if (!file.sourcemaps) {
// return untouched file
return file;
}
const descriptors = {};
const generatedContent = Object.keys(file.source).map((k) => file.source[k].source).join('\n');
// Rather than relying on generated content, get the nodes tree from sourcemap consumer
const sourcemap = SourceMapSupport.retrieveSourceMap(file.filename).map;
const smc = await new SourceMapConsumer(sourcemap);
// For each original files that might have been transformed into this generate content, store a new descriptor
SourceNode.fromStringWithSourceMap(generatedContent, smc).walkSourceContents((sourceFile, content) => {
descriptors[sourceFile] = {
generated: file.filename,
filename: sourceFile,
source: {}
};
content.split('\n').forEach((line, number) => {
descriptors[sourceFile].source[number + 1] = {
source: line,
// consider line covered by default
const ret = {
// Ensure folder separator to be url-friendly
filename: filename.replace(Path.join(process.cwd(), '/').replace(/\\/g, '/'), ''),
percent: 0,
hits: 0,
misses: 0,
sloc: data.sloc,
source: {},
externals: internals.external(filename)
};
// Use sourcemap consumer rather than SourceMapSupport.mapSourcePosition itself which perform path transformations
let sourcemap = null;
if (options.sourcemaps) {
sourcemap = SourceMapSupport.retrieveSourceMap(ret.filename);
if (!sourcemap) {
const smre = /\/\/\#.*data:application\/json[^,]+base64,.*\r?\n?$/;
let sourceIndex = data.source.length - 1;
while (sourceIndex >= 0 && !smre.test(data.source[sourceIndex])) {
sourceIndex--;
}
if (sourceIndex >= 0) {
const re = /(?:\/\/[@#][ \t]+sourceMappingURL=([^\s'"]+?)[ \t]*$)|(?:\/\*[@#][ \t]+sourceMappingURL=([^\*]+?)[ \t]*(?:\*\/)[ \t]*$)/mg;
let lastMatch;
let match;
while (match = re.exec(data.source[sourceIndex])) {
lastMatch = match;
}
sourcemap = {
context.coverage.cov.files = context.coverage.cov.files.map(async (file) => {
if (!file.sourcemaps) {
// return untouched file
return file;
}
const descriptors = {};
const generatedContent = Object.keys(file.source).map((k) => file.source[k].source).join('\n');
// Rather than relying on generated content, get the nodes tree from sourcemap consumer
const sourcemap = SourceMapSupport.retrieveSourceMap(file.filename).map;
const smc = await new SourceMap.SourceMapConsumer(sourcemap);
// For each original files that might have been transformed into this generate content, store a new descriptor
SourceMap.SourceNode.fromStringWithSourceMap(generatedContent, smc).walkSourceContents((sourceFile, content) => {
descriptors[sourceFile] = {
generated: file.filename,
filename: sourceFile,
source: {}
};
content.split('\n').forEach((line, number) => {
descriptors[sourceFile].source[number + 1] = {
source: line,
// consider line covered by default
}).forEach(function(file) {
let full = path.resolve(dirName, file)
let src = sourcemaps.retrieveSourceMap(full).url
if (src.endsWith('.map')) src = src.slice(0, -4);
src = src.replace('/dist/', '/src/').replace('.js', '.ts')
if (!fs.existsSync(src)) return;
if (!filter || filter(path.basename(src))) require(full);
})
}
app.use("/@/", (_req, resp) => {
const filePath = _req.originalUrl.replace(/^\/@\//, "");
const sourceMap = require("source-map-support").retrieveSourceMap(filePath);
resp.sendFile(path.resolve("/", filePath), {
headers: (sourceMap) && {
"X-SourceMap": `/@/${sourceMap.url}`,
},
});
});
}).forEach(function(file) {
let full = path.resolve(dirName, file)
let src = sourcemaps.retrieveSourceMap(full).url
if (src.endsWith('.map')) src = src.slice(0, -4);
src = src.replace('/dist/', '/src/').replace('.js', '.ts')
if (!fs.existsSync(src)) return;
if (!filter || filter(path.basename(src))) require(full);
})
}