mirror of
https://github.com/hanzoai/babel.git
synced 2026-09-24 16:56:45 +00:00
51 lines
1.5 KiB
JavaScript
51 lines
1.5 KiB
JavaScript
import * as babel from "@babel/core";
|
|
|
|
import reactPreset from "../lib/index.js";
|
|
|
|
describe("react preset", () => {
|
|
it("does throw clear error when no options passed for Babel 6", () => {
|
|
expect(() => {
|
|
reactPreset({ version: "6.5.0" });
|
|
}).toThrow(Error, /Requires Babel "\^7.0.0-0"/);
|
|
});
|
|
it("throws when unknown option is passed", () => {
|
|
expect(() => {
|
|
reactPreset({ assertVersion() {} }, { runtine: true });
|
|
}).toThrowErrorMatchingInlineSnapshot(`
|
|
"@babel/preset-react: 'runtine' is not a valid top-level option.
|
|
- Did you mean 'runtime'?"
|
|
`);
|
|
});
|
|
it("throws when option is of incorrect type", () => {
|
|
expect(() => {
|
|
reactPreset({ assertVersion() {} }, { runtime: true });
|
|
}).toThrowErrorMatchingInlineSnapshot(
|
|
`"@babel/preset-react: 'runtime' option must be a string."`,
|
|
);
|
|
});
|
|
|
|
it("respects envName", () => {
|
|
expect(
|
|
babel.transformSync("<a />", {
|
|
configFile: false,
|
|
presets: [reactPreset],
|
|
envName: "development",
|
|
}).code,
|
|
).toMatchInlineSnapshot(`
|
|
"import { jsxDEV as _jsxDEV } from "react/jsx-dev-runtime";
|
|
/*#__PURE__*/_jsxDEV("a", {}, void 0, false);"
|
|
`);
|
|
|
|
expect(
|
|
babel.transformSync("<a />", {
|
|
configFile: false,
|
|
presets: [reactPreset],
|
|
envName: "production",
|
|
}).code,
|
|
).toMatchInlineSnapshot(`
|
|
"import { jsx as _jsx } from "react/jsx-runtime";
|
|
/*#__PURE__*/_jsx("a", {});"
|
|
`);
|
|
});
|
|
});
|