UNPKG

one

Version:

One is a new React Framework that makes Vite serve both native and web.

65 lines (64 loc) 3.29 kB
import fs from "fs"; import path from "path"; import { afterAll, beforeAll, describe, expect, it } from "vitest"; import { getViteMetroPluginOptions } from "./getViteMetroPluginOptions.native.js"; describe("getViteMetroPluginOptions babel-config coexistence", function () { var tmpDir; beforeAll(function () { var 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(function () { fs.rmSync(tmpDir, { recursive: true, force: true }); }); it("injects plugins when there is no user babel.config", function () { var _opts_babelConfig, _opts_babelConfig_plugins, _opts_babelConfig1; var opts = getViteMetroPluginOptions({ projectRoot: tmpDir, relativeRouterRoot: "app" }); expect(opts === null || opts === void 0 ? void 0 : (_opts_babelConfig = opts.babelConfig) === null || _opts_babelConfig === void 0 ? void 0 : _opts_babelConfig.plugins).toBeDefined(); expect(opts === null || opts === void 0 ? void 0 : opts.oneViteMetroBabelConfig).toBe(true); expect(opts === null || opts === void 0 ? void 0 : (_opts_babelConfig1 = opts.babelConfig) === null || _opts_babelConfig1 === void 0 ? void 0 : (_opts_babelConfig_plugins = _opts_babelConfig1.plugins) === null || _opts_babelConfig_plugins === void 0 ? void 0 : _opts_babelConfig_plugins.length).toBe(5); }); it("still injects One plugins when the user has a babel.config.cjs", function () { var cfgPath = path.join(tmpDir, "babel.config.cjs"); fs.writeFileSync(cfgPath, "module.exports = require('one/babel-preset')\n"); try { var _opts_babelConfig_plugins, _opts_babelConfig; var opts = getViteMetroPluginOptions({ projectRoot: tmpDir, relativeRouterRoot: "app" }); expect(opts === null || opts === void 0 ? void 0 : (_opts_babelConfig = opts.babelConfig) === null || _opts_babelConfig === void 0 ? void 0 : (_opts_babelConfig_plugins = _opts_babelConfig.plugins) === null || _opts_babelConfig_plugins === void 0 ? void 0 : _opts_babelConfig_plugins.length).toBe(5); } finally { fs.unlinkSync(cfgPath); } }); it("still injects One plugins when the user has a babel.config.js", function () { var cfgPath = path.join(tmpDir, "babel.config.js"); fs.writeFileSync(cfgPath, "module.exports = require('one/babel-preset')\n"); try { var _opts_babelConfig_plugins, _opts_babelConfig; var opts = getViteMetroPluginOptions({ projectRoot: tmpDir, relativeRouterRoot: "app" }); expect(opts === null || opts === void 0 ? void 0 : (_opts_babelConfig = opts.babelConfig) === null || _opts_babelConfig === void 0 ? void 0 : (_opts_babelConfig_plugins = _opts_babelConfig.plugins) === null || _opts_babelConfig_plugins === void 0 ? void 0 : _opts_babelConfig_plugins.length).toBe(5); } finally { fs.unlinkSync(cfgPath); } }); }); //# sourceMappingURL=getViteMetroPluginOptions.integration.test.native.js.map