Skip to content

Commit

Permalink
added test for skipping transpilation
Browse files Browse the repository at this point in the history
this revealed a subtle inconsistency WRT reference directories
  • Loading branch information
FND committed Feb 9, 2018
1 parent b1317eb commit 26c56a9
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/bundle/babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ module.exports = function generateTranspiler({ features = [], jsx, exclude }) {
// distinguish paths from package identifiers - as per Node's
// resolution algorithm <https://nodejs.org/api/modules.html>, a
// string is a path if it begins with `/`, `./` or `../`
// FIXME: duplicates `AssetManager#resolvePath`, resulting in
// inconsistency WRT working directory
return /^\.{0,2}\//.test(pkg) ? pkg : `node_modules/${pkg}/**`;
});
}
Expand Down
16 changes: 16 additions & 0 deletions test/unit/fixtures/node_modules/my-lib/dist.js

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

3 changes: 3 additions & 0 deletions test/unit/fixtures/src/alt2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import MYLIB from "my-lib/dist";

console.log(`[…] ${MYLIB}`); // eslint-disable-line no-console
52 changes: 52 additions & 0 deletions test/unit/test_bundling.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,58 @@ console.log("[\\u2026] " + util); // eslint-disable-line no-console
});
});

it("should support skipping transpilation for select packages", () => {
let cwd = process.cwd();
process.chdir(FIXTURES_DIR); // XXX: should not be test-specific!?
let restore = _ => process.chdir(cwd);

let config = [{
source: "./src/alt2.js",
target: "./dist/bundle.js",
transpiler: {
features: ["es2015"],
exclude: ["my-lib"]
}
}];
let assetManager = new MockAssetManager(FIXTURES_DIR);

return faucetJS(config, assetManager).
then(restore, restore). // XXX: hacky
then(_ => {
assetManager.assertWrites([{
filepath: path.resolve(FIXTURES_DIR, "./dist/bundle.js"),
/* eslint-disable max-len */
content: makeBundle(`
var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
function createCommonjsModule(fn, module) {
return module = { exports: {} }, fn(module, module.exports), module.exports;
}
var dist = createCommonjsModule(function (module) {
/* eslint-disable */
(function(window) {
var MYLIB = "MY-LIB";
{
module.exports = MYLIB;
}
}(commonjsGlobal));
});
console.log("[\\u2026] " + dist); // eslint-disable-line no-console
`.trim())
/* eslint-enable max-len */
}]);
});
});

it("should support custom file extensions", () => {
let config = [{
source: "./src/index.coffee",
Expand Down

0 comments on commit 26c56a9

Please sign in to comment.