2017-01-14 09:48:52 -05:00

31 lines
1.0 KiB
JavaScript

const generator = require("../../babel-generator").default;
const template = require("../lib");
const chai = require("chai");
const comments = "// Sum two numbers\nconst add = (a, b) => a + b;";
describe("templating", function () {
it("import statement will cause parser to throw by default", function () {
chai.expect(function () {
template("import foo from 'foo'")({});
}).to.throw();
});
it("import statements are allowed with sourceType: module", function () {
chai.expect(function () {
template("import foo from 'foo'", {sourceType: "module"})({});
}).not.to.throw();
});
it("should strip comments by default", function () {
const code = "const add = (a, b) => a + b;";
const output = template(comments)();
chai.expect(generator(output).code).to.be.equal(code);
});
it("should preserve comments with a flag", function () {
const output = template(comments, {preserveComments: true})();
chai.expect(generator(output).code).to.be.equal(comments);
});
});