swc/node-swc/__tests__/module_test.js

50 lines
1.3 KiB
JavaScript

const swc = require("../../");
it("should emit _interopRequireDefault", () => {
const out = swc.transformSync(`import foo from "foo"`, {
module: {
type: "commonjs"
}
});
expect(out.map).toBeFalsy();
expect(out.code).toContain(`function _interopRequireDefault`);
expect(out.code).toContain(`_interopRequireDefault(require("foo"))`);
});
it("should emit _interopRequireWildcard", () => {
const out = swc.transformSync('import * as foo from "foo"', {
module: {
type: "commonjs"
}
});
expect(out.map).toBeFalsy();
expect(out.code).toContain(`function _interopRequireWildcard`);
expect(out.code).toContain(
`_interopRequireWildcard(require("foo"))`
);
});
it("should work with amd and external helpers", () => {
const out = swc.transformSync(
`class Foo {}
class Bar extends Foo {}`,
{
jsc: {
externalHelpers: true
},
module: {
type: "amd",
moduleId: "a"
}
}
);
expect(out.map).toBeFalsy();
expect(out.code).toContain(`define("a",`);
expect(out.code).toContain(`_classCallCheck(this, Foo);`);
expect(out.code).toContain(`_inherits(Bar, Foo);`);
});