Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

vite.config.ts

87 lines3.1 KB

1import { createRequire } from 'node:module'
2import { dirname, resolve } from 'node:path'
3import { defineConfig } from 'vitest/config'
4import { octane } from 'octane/compiler/vite'
5import packageJson from './package.json'
6​
7const SELF = resolve(import.meta.dirname, 'src/index.ts')
8​
9// `@octanejs/testing-library` publishes uncompiled TypeScript (`main:
10// src/index.ts`), so Vitest has to transform it instead of externalizing it
11// the way it would a built dependency.
12const inlineDeps = ['@octanejs/testing-library']
13​
14// `act-environment` ships in the tarball but is missing from the package's
15// `exports`, so it can only be reached by path. Derive that path from the
16// resolved `.` entry rather than assuming a node_modules layout — pnpm
17// symlinks this package and the store path is not stable. (The upstream
18// Octane repo aliases the same subpath; worth exporting there instead.)
19const testingLibrarySrc = dirname(
20 createRequire(import.meta.url).resolve('@octanejs/testing-library'),
22​
23const octaneAliases = [
24 { find: /^@tanstack\/ai-octane$/, replacement: SELF },
25 {
26 find: /^@octanejs\/testing-library\/(.*)$/,
27 replacement: `${testingLibrarySrc}/$1.ts`,
28 },
30​
31export default defineConfig({
32 test: {
33 name: packageJson.name,
34 dir: './',
35 watch: false,
36 projects: [
37 {
38 // The hook modules are .tsrx, so both projects need the Octane
39 // compiler — this one with the default client renderer.
40 plugins: [octane()],
41 resolve: { alias: octaneAliases },
42 test: {
43 name: 'conformance',
44 // happy-dom, not the jsdom the upstream Octane repo used: this repo
45 // pins jsdom ^27, whose `Blob` predates `arrayBuffer()` (Octane
46 // pins ^29, which has it), and the recorder tests need it. Bumping
47 // jsdom for one package would break sherif's cross-package version
48 // consistency, and happy-dom is this repo's DOM-testing default.
49 environment: 'happy-dom',
50 globals: false,
51 include: [
52 'tests/conformance/**/*.test.ts',
53 'tests/conformance/**/*.test.tsx',
54 'tests/chat-ui/**/*.test.ts',
55 'tests/chat-ui/**/*.test.tsx',
56 ],
57 setupFiles: ['./tests/conformance/test-setup.ts'],
58 server: { deps: { inline: inlineDeps } },
59 },
60 },
61 {
62 plugins: [octane({ ssr: true })],
63 resolve: {
64 alias: [
65 ...octaneAliases,
66 // The compiled .tsrx output imports its runtime from bare
67 // `octane`; under SSR that has to resolve to the server runtime.
68 { find: /^octane$/, replacement: 'octane/server' },
69 ],
70 },
71 test: {
72 name: 'ssr',
73 environment: 'node',
74 globals: false,
75 include: ['tests/ssr/**/*.test.ts'],
76 server: { deps: { inline: inlineDeps } },
77 },
78 },
79 ],
80 coverage: {
81 provider: 'v8',
82 reporter: ['text', 'json', 'html', 'lcov'],
83 include: ['src/**'],
84 exclude: ['src/types.ts', 'src/realtime-types.ts', 'src/**/*.d.ts'],
85 },
86 },
87})