@aamini/config 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/dist/msw.d.mts +3 -0
  2. package/dist/msw.mjs +3 -0
  3. package/dist/playwright.shared.config.d.mts +8 -0
  4. package/dist/playwright.shared.config.mjs +47 -0
  5. package/dist/playwright.shared.config.mjs.map +1 -0
  6. package/dist/setup/styles.d.mts +1 -0
  7. package/dist/setup/styles.mjs +3 -0
  8. package/dist/test/browser.d.mts +15 -0
  9. package/dist/test/browser.mjs +26 -0
  10. package/dist/test/browser.mjs.map +1 -0
  11. package/dist/test/database.d.mts +22 -0
  12. package/dist/test/database.mjs +18 -0
  13. package/dist/test/database.mjs.map +1 -0
  14. package/dist/test/db.d.mts +21 -0
  15. package/dist/test/db.mjs +53 -0
  16. package/dist/test/db.mjs.map +1 -0
  17. package/dist/test/playwright.d.mts +7 -0
  18. package/dist/test/playwright.mjs +15 -0
  19. package/dist/test/playwright.mjs.map +1 -0
  20. package/dist/test/postgres.d.mts +14 -0
  21. package/dist/test/postgres.mjs +25 -0
  22. package/dist/test/postgres.mjs.map +1 -0
  23. package/dist/test/server.d.mts +15 -0
  24. package/dist/test/server.mjs +23 -0
  25. package/dist/test/server.mjs.map +1 -0
  26. package/dist/test/visual-page.d.mts +36 -0
  27. package/dist/test/visual-page.mjs +30 -0
  28. package/dist/test/visual-page.mjs.map +1 -0
  29. package/dist/vite.shared.d.mts +14 -0
  30. package/dist/vite.shared.mjs +232 -0
  31. package/dist/vite.shared.mjs.map +1 -0
  32. package/dist/vitest.shared.d.mts +12 -0
  33. package/dist/vitest.shared.mjs +122 -0
  34. package/dist/vitest.shared.mjs.map +1 -0
  35. package/msw.ts +5 -0
  36. package/package.json +99 -0
  37. package/playwright.shared.config.ts +71 -0
  38. package/setup/styles.ts +4 -0
  39. package/test/browser.ts +31 -0
  40. package/test/database.ts +38 -0
  41. package/test/db.ts +80 -0
  42. package/test/playwright.ts +17 -0
  43. package/test/postgres.ts +43 -0
  44. package/test/server.ts +31 -0
  45. package/test/visual-page.ts +57 -0
  46. package/tsconfig/tsconfig.astro.json +34 -0
  47. package/tsconfig/tsconfig.lib.json +19 -0
  48. package/tsconfig/tsconfig.react.json +16 -0
  49. package/tsconfig/tsconfig.strict.json +16 -0
  50. package/tsconfig/tsconfig.tanstack.json +17 -0
  51. package/virtual-modules.d.ts +6 -0
  52. package/vite.config.ts +53 -0
  53. package/vite.shared.ts +298 -0
  54. package/vitest.shared.ts +183 -0
@@ -0,0 +1,183 @@
1
+ import tailwindcss from '@tailwindcss/vite'
2
+ import viteReact from '@vitejs/plugin-react'
3
+ import { playwright } from '@vitest/browser-playwright'
4
+ import { existsSync } from 'node:fs'
5
+ import { resolve } from 'node:path'
6
+ import type { Plugin } from 'vite'
7
+ import svgr from 'vite-plugin-svgr'
8
+ import {
9
+ defineConfig,
10
+ mergeConfig,
11
+ type TestProjectConfiguration,
12
+ type TestProjectInlineConfiguration,
13
+ type ViteUserConfig,
14
+ } from 'vitest/config'
15
+
16
+ const HANDLER_LOCATIONS = [
17
+ '__mocks__/handlers.ts',
18
+ '__mocks__/handlers.js',
19
+ 'src/mocks/handlers.ts',
20
+ 'src/mocks/handlers.js',
21
+ ]
22
+
23
+ const STYLES_LOCATIONS = ['src/styles.css', 'src/index.css', 'src/app.css']
24
+
25
+ function mswHandlersPlugin(): Plugin {
26
+ const virtualModuleId = '@test/handlers'
27
+ const resolvedVirtualModuleId = '\0' + virtualModuleId
28
+
29
+ return {
30
+ name: 'msw-handlers-resolver',
31
+ resolveId(id) {
32
+ if (id === virtualModuleId) {
33
+ return resolvedVirtualModuleId
34
+ }
35
+ return undefined
36
+ },
37
+ load(id) {
38
+ if (id === resolvedVirtualModuleId) {
39
+ const cwd = process.cwd()
40
+ for (const location of HANDLER_LOCATIONS) {
41
+ const fullPath = resolve(cwd, location)
42
+ if (existsSync(fullPath)) {
43
+ return `export { default } from '${fullPath}'`
44
+ }
45
+ }
46
+ throw new Error(
47
+ `No MSW handlers found. Expected one of:\n${HANDLER_LOCATIONS.map((l) => ` - ${resolve(cwd, l)}`).join('\n')}`,
48
+ )
49
+ }
50
+ return undefined
51
+ },
52
+ }
53
+ }
54
+
55
+ function stylesPlugin(): Plugin {
56
+ const virtualModuleId = '@test/styles'
57
+ const resolvedVirtualModuleId = '\0' + virtualModuleId
58
+
59
+ return {
60
+ name: 'styles-resolver',
61
+ resolveId(id) {
62
+ if (id === virtualModuleId) {
63
+ return resolvedVirtualModuleId
64
+ }
65
+ return undefined
66
+ },
67
+ load(id) {
68
+ if (id === resolvedVirtualModuleId) {
69
+ const cwd = process.cwd()
70
+ for (const location of STYLES_LOCATIONS) {
71
+ const fullPath = resolve(cwd, location)
72
+ if (existsSync(fullPath)) {
73
+ return `import '${fullPath}'`
74
+ }
75
+ }
76
+ throw new Error(
77
+ `No styles file found. Expected one of:\n${STYLES_LOCATIONS.map((l) => ` - ${resolve(cwd, l)}`).join('\n')}`,
78
+ )
79
+ }
80
+ return undefined
81
+ },
82
+ }
83
+ }
84
+
85
+ const stylesSetup = new URL('setup/styles.ts', import.meta.url).pathname
86
+
87
+ function asPlugins(plugins: unknown[]): NonNullable<ViteUserConfig['plugins']> {
88
+ return plugins as NonNullable<ViteUserConfig['plugins']>
89
+ }
90
+
91
+ function mergeProjectConfig(
92
+ base: TestProjectConfiguration,
93
+ overrides: TestProjectConfiguration = {},
94
+ ): TestProjectConfiguration {
95
+ return mergeConfig(
96
+ base as Record<string, any>,
97
+ overrides as Record<string, any>,
98
+ ) as TestProjectConfiguration
99
+ }
100
+
101
+ // Auto-detect app-level vitest.setup.ts for custom setup (e.g., MSW server)
102
+ const localSetup = resolve(process.cwd(), 'vitest.setup.ts')
103
+ const hasLocalSetup = existsSync(localSetup)
104
+
105
+ interface ProjectOverrides {
106
+ server?: TestProjectConfiguration
107
+ browser?: TestProjectConfiguration
108
+ }
109
+
110
+ export const createBaseConfig = (
111
+ overrides: TestProjectInlineConfiguration,
112
+ projectOverrides: ProjectOverrides = {},
113
+ ) =>
114
+ mergeConfig(
115
+ defineConfig({
116
+ resolve: {
117
+ tsconfigPaths: true,
118
+ },
119
+ plugins: asPlugins([
120
+ tailwindcss(),
121
+ viteReact({
122
+ babel: {
123
+ plugins: ['babel-plugin-react-compiler'],
124
+ },
125
+ } as Parameters<typeof viteReact>[0]),
126
+ svgr({
127
+ include: '**/*.svg',
128
+ svgrOptions: { exportType: 'default' },
129
+ }),
130
+ ]),
131
+ test: {
132
+ passWithNoTests: true,
133
+ projects: [
134
+ {
135
+ extends: true,
136
+ test: {
137
+ name: 'unit',
138
+ include: ['src/**/*.test.unit.ts'],
139
+ },
140
+ },
141
+ mergeProjectConfig(
142
+ {
143
+ extends: true,
144
+ plugins: [mswHandlersPlugin()],
145
+ test: {
146
+ name: 'server',
147
+ include: ['src/**/*.test.ts'],
148
+ testTimeout: 30_000,
149
+ fileParallelism: false,
150
+ setupFiles: hasLocalSetup ? [localSetup] : [],
151
+ },
152
+ } satisfies TestProjectConfiguration,
153
+ projectOverrides.server ?? {},
154
+ ),
155
+ mergeProjectConfig(
156
+ {
157
+ extends: true,
158
+ plugins: [mswHandlersPlugin(), stylesPlugin()],
159
+ test: {
160
+ name: 'browser',
161
+ include: ['src/**/*.test.tsx', 'tests/**/*.test.tsx'],
162
+ setupFiles: [stylesSetup],
163
+ browser: {
164
+ instances: [
165
+ {
166
+ browser: 'chromium',
167
+ },
168
+ ],
169
+ provider: playwright(),
170
+ enabled: true,
171
+ headless: true,
172
+ },
173
+ },
174
+ } satisfies TestProjectConfiguration,
175
+ projectOverrides.browser ?? {},
176
+ ),
177
+ ],
178
+ },
179
+ }),
180
+ overrides,
181
+ )
182
+
183
+ export const baseConfig = createBaseConfig({})