From ce81079e64e3dfbfdac865088efcbb70aea6a322 Mon Sep 17 00:00:00 2001 From: JoseLion Date: Mon, 1 Jul 2024 23:59:24 -0500 Subject: [PATCH] Fix local tests env and plugin --- test/env.ts | 14 ++++++++++++++ test/plugin.ts | 24 ++++++++++++++++++++++++ vitest.config.ts | 2 +- 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 test/env.ts create mode 100644 test/plugin.ts diff --git a/test/env.ts b/test/env.ts new file mode 100644 index 0000000..206c2fb --- /dev/null +++ b/test/env.ts @@ -0,0 +1,14 @@ +import type { Environment } from "vitest"; + +const reactNativeEnv: Environment = { + name: "react-native", + setup: async () => { + await import("../src/lib/babelRegister"); + await import("../src/load"); + + return { teardown: () => undefined }; + }, + transformMode: "ssr", +}; + +export default reactNativeEnv; diff --git a/test/plugin.ts b/test/plugin.ts new file mode 100644 index 0000000..2c0e23d --- /dev/null +++ b/test/plugin.ts @@ -0,0 +1,24 @@ +import type { Plugin } from "vite"; + +export function reactNativePlugin(): Plugin { + return { + config: { + handler: () => ({ + test: { + environment: "./test/env.ts", + globals: true, + server: { + deps: { + external: [ + "react-native", + "@react-native", + ], + }, + }, + }, + }), + }, + enforce: "pre", + name: "react-native-vite-plugin", + }; +} diff --git a/vitest.config.ts b/vitest.config.ts index 09957af..b20736a 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -1,6 +1,6 @@ import { defineConfig } from "vitest/config"; -import { reactNativePlugin } from "./src/vitest/plugin"; +import { reactNativePlugin } from "./test/plugin"; export default defineConfig({ plugins: [reactNativePlugin()],