Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add source maps for test debugging
Browse files Browse the repository at this point in the history
guybedford committed Nov 15, 2018
1 parent c885682 commit 2178f5c
Showing 3 changed files with 23 additions and 11 deletions.
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ const { terser } = require("rollup-plugin-terser");
const builtins = require("builtins")();
const fsInliner = require("./fs-inliner.js");

module.exports = async (input, { minify = true } = {}) => {
module.exports = async (input, { minify = true, sourcemap = false } = {}) => {
const resolve = nodeResolve({
module: false,
jsnext: false,
@@ -36,6 +36,7 @@ module.exports = async (input, { minify = true } = {}) => {
});

return await bundle.generate({
sourcemap,
format: "cjs"
});
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -24,6 +24,6 @@
},
"devDependencies": {
"axios": "^0.18.0",
"fontkit": "^1.7.7"
"source-map-support": "^0.5.9"
}
}
29 changes: 20 additions & 9 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
const assert = require('assert');
const fs = require('fs');
const sourceMapSupport = require('source-map-support');
const ncc = require('../');

const sourceMapSources = {};
sourceMapSupport.install({
retrieveSourceMap (source) {
if (!sourceMapSources[source])
return null;

return {
url: source,
map: sourceMapSources[source]
};
}
});

(async () => {
// unit
let cnt = 0;
@@ -31,11 +45,13 @@ const ncc = require('../');
cnt = 0;
for (const test of fs.readdirSync(__dirname + "/integration")) {
cnt ++;
const { code } = await ncc(__dirname + "/integration/" + test, { minify: false });
const { code, map } = await ncc(__dirname + "/integration/" + test, { minify: false, sourcemap: true });
try {
let exports = {};
let module = { exports };
eval(code);
const id = test;
sourceMapSources[id] = map;
eval(code + '\n//# sourceURL=' + id);
if ("function" !== typeof module.exports) {
console.error(
`Integration test "${test}" evaluation failed. It does not export a "run" function`
@@ -44,13 +60,8 @@ const ncc = require('../');
}
await module.exports();
} catch (err) {
const locMatch = err.stack.toString().match(/\<anonymous\>:(\d+):(\d+)/);
let locStr = '';
if (locMatch) {
const line = parseInt(locMatch[1]);
locStr = '\n' + code.split(/\r\n|\r|\n/).slice(line - 4, line + 3).join('\n') + '\n';
}
console.error(`Integration test "${test}" execution failed${locStr}`, err);
console.error(`Integration test "${test}" execution failed`, err);
console.error(err);
return;
}
}

0 comments on commit 2178f5c

Please sign in to comment.