Skip to content

Commit

Permalink
Fix local tests env and plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
JoseLion committed Jul 2, 2024
1 parent c02d2aa commit ce81079
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
14 changes: 14 additions & 0 deletions test/env.ts
Original file line number Diff line number Diff line change
@@ -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;
24 changes: 24 additions & 0 deletions test/plugin.ts
Original file line number Diff line number Diff line change
@@ -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",
};
}
2 changes: 1 addition & 1 deletion vitest.config.ts
Original file line number Diff line number Diff line change
@@ -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()],
Expand Down

0 comments on commit ce81079

Please sign in to comment.