one
Version:
One is a new React Framework that makes Vite serve both native and web.
62 lines (61 loc) • 2.15 kB
JavaScript
import fs from "node:fs";
import path from "node:path";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import { getViteMetroPluginOptions } from "./getViteMetroPluginOptions.mjs";
describe("getViteMetroPluginOptions babel-config coexistence", () => {
let tmpDir;
beforeAll(() => {
const workspaceRoot = path.resolve(__dirname, "../../../../");
tmpDir = fs.mkdtempSync(path.join(workspaceRoot, ".tmp-one-vite-metro-test-"));
fs.writeFileSync(path.join(tmpDir, "tsconfig.json"), JSON.stringify({
compilerOptions: {
paths: {}
}
}));
fs.writeFileSync(path.join(tmpDir, "package.json"), JSON.stringify({
name: "tmp"
}));
});
afterAll(() => {
fs.rmSync(tmpDir, {
recursive: true,
force: true
});
});
it("injects plugins when there is no user babel.config", () => {
const opts = getViteMetroPluginOptions({
projectRoot: tmpDir,
relativeRouterRoot: "app"
});
expect(opts?.babelConfig?.plugins).toBeDefined();
expect(opts?.oneViteMetroBabelConfig).toBe(true);
expect(opts?.babelConfig?.plugins?.length).toBe(5);
});
it("still injects One plugins when the user has a babel.config.cjs", () => {
const cfgPath = path.join(tmpDir, "babel.config.cjs");
fs.writeFileSync(cfgPath, "module.exports = require('one/babel-preset')\n");
try {
const opts = getViteMetroPluginOptions({
projectRoot: tmpDir,
relativeRouterRoot: "app"
});
expect(opts?.babelConfig?.plugins?.length).toBe(5);
} finally {
fs.unlinkSync(cfgPath);
}
});
it("still injects One plugins when the user has a babel.config.js", () => {
const cfgPath = path.join(tmpDir, "babel.config.js");
fs.writeFileSync(cfgPath, "module.exports = require('one/babel-preset')\n");
try {
const opts = getViteMetroPluginOptions({
projectRoot: tmpDir,
relativeRouterRoot: "app"
});
expect(opts?.babelConfig?.plugins?.length).toBe(5);
} finally {
fs.unlinkSync(cfgPath);
}
});
});
//# sourceMappingURL=getViteMetroPluginOptions.integration.test.mjs.map