Nicolò Ribaudo ad1798ed48
Only bundle the release build, and don't import src in tests (#13978)
* Only bundle the release build, and don't import `src` in tests

* Use file extension to signal skipping

* Remove unnecessary config change

* Fix imports
2021-11-24 10:08:53 -05:00

57 lines
1.4 KiB
JavaScript

import { parseSync, traverse } from "@babel/core";
import { shouldTransform } from "../lib/util.js";
function getPath(input, parserOpts = {}) {
let targetPath;
traverse(
parseSync(input, {
parserOpts,
filename: "example.js",
configFile: false,
}),
{
FunctionExpression(path) {
targetPath = path;
path.stop();
},
},
);
return targetPath;
}
describe("shouldTransform", () => {
const positiveCases = [
"(function a([a]) {})",
"({ b: function a([a]) {} })",
"(function a({a}) {})",
"(function a(...a) {})",
"(function a({ ...a }) {})",
"(function a([a = 1]) {})",
"(function a(b, { a: [,...a] }) {})",
];
const negativeCases = [
"(function () {})",
"(function a() {})",
"(function a(a) {})",
"(function a() { var a })",
"(function b([a]) { var a })",
"(function b([a]) { function a() {} })",
"(function a(x = a) {})",
"(function a() { var { a } = {}; })",
"(function b([a]) { var { a } = {}; })",
"(function a({ [a]: b }) {})",
];
describe("the following cases should be transformed", () => {
test.each(positiveCases)("%p", input => {
expect(shouldTransform(getPath(input))).toBe("a");
});
});
describe("the following cases should not be transformed", () => {
test.each(negativeCases)("%p", input => {
expect(shouldTransform(getPath(input))).toBe(false);
});
});
});