Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@
"lint:db": "eslint packages/db/src packages/db/tests",
"lint:fix": "node scripts/run-eslint.mjs --fix && node scripts/run-generated-eslint.mjs --fix",
"lint:generated": "node scripts/run-generated-eslint.mjs",
"typecheck": "bun run --workspaces --if-present --sequential typecheck",
"typecheck": "bun run typecheck:libraries && bun run typecheck:tests",
"typecheck:libraries": "bun run --workspaces --if-present --sequential typecheck",
"typecheck:tests": "node scripts/run-test-typecheck.mjs",
"typecheck:db": "bun run --filter @holo-js/db typecheck",
"test": "bun run --workspaces --if-present --sequential test",
"test:watch": "vitest --workspace vitest.workspace.ts",
Expand Down
59 changes: 43 additions & 16 deletions packages/adapter-nuxt/tests/setup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,24 @@ let adapterBuildPromise: Promise<{ adapterOutDir: string }> | null = null
const dbRuntimeDependencyNames = ['better-sqlite3', 'mysql2', 'pg', 'ulid', 'uuid'] as const

type RuntimeConfigShape = Record<string, unknown>
type NuxtHarnessOptions = {
rootDir?: string
srcDir: string
runtimeConfig?: RuntimeConfigShape & {
holoStorage?: unknown
}
build: {
transpile: string[]
}
nitro?: {
storage?: Record<string, unknown>
}
}

type NuxtHarness = {
options: NuxtHarnessOptions
hook: ReturnType<typeof vi.fn>
}

async function createTempBuildRoot(prefix: string): Promise<string> {
const baseDir = resolve(repoRoot, '.vitest-builds')
Expand All @@ -39,13 +57,14 @@ async function provisionTempPackage(sourcePackageDir: string, tempPackageDir: st
}

async function runPackageBuild(command: string, args: string[], targetPackageDir: string, outDir?: string): Promise<void> {
const env = outDir ? {
...process.env,
HOLO_BUILD_OUT_DIR: outDir,
} : {
const env: NodeJS.ProcessEnv = {
...process.env,
}

if (outDir) {
env.HOLO_BUILD_OUT_DIR = outDir
}

env.PATH = `${resolve(repoRoot, 'node_modules/.bin')}:${env.PATH ?? ''}`

execFileSync(command, args, {
Expand Down Expand Up @@ -130,7 +149,7 @@ async function runAdapterStub(): Promise<{ adapterOutDir: string }> {
return adapterBuildPromise
}

function createNuxtHarness(rootDir: string, runtimeConfig: RuntimeConfigShape = {}) {
function createNuxtHarness(rootDir: string, runtimeConfig: RuntimeConfigShape = {}): NuxtHarness {
return {
options: {
rootDir,
Expand All @@ -145,13 +164,21 @@ function createNuxtHarness(rootDir: string, runtimeConfig: RuntimeConfigShape =
}

function runHook(
nuxt: ReturnType<typeof createNuxtHarness>,
nuxt: NuxtHarness,
name: string,
): void {
const callback = nuxt.hook.mock.calls.find(([hookName]) => hookName === name)?.[1]
callback?.()
}

function getNitroStorage(nuxt: NuxtHarness): Record<string, unknown> | undefined {
return nuxt.options.nitro?.storage
}

function getHoloStorageRuntimeConfig(nuxt: NuxtHarness): Record<string, unknown> | undefined {
return nuxt.options.runtimeConfig?.holoStorage as Record<string, unknown> | undefined
}

async function createProject(): Promise<string> {
const root = await mkdtemp(join(tmpdir(), 'holo-storage-module-'))
tempDirs.push(root)
Expand Down Expand Up @@ -359,7 +386,7 @@ export default defineStorageConfig({
await module.setup({}, nuxt as never)
runHook(nuxt, 'modules:done')

expect((nuxt.options as { nitro: { storage: Record<string, unknown> } }).nitro.storage).toEqual({
expect(getNitroStorage(nuxt)).toEqual({
'holo:local': {
driver: 'fs',
base: './storage/app',
Expand All @@ -383,8 +410,8 @@ export default defineStorageConfig({
forcePathStyleEndpoint: true,
},
})
expect((nuxt.options.runtimeConfig.holoStorage as Record<string, unknown>).defaultDisk).toBe('media')
expect((nuxt.options.runtimeConfig.holoStorage as Record<string, unknown>).routePrefix).toBe('/files')
expect(getHoloStorageRuntimeConfig(nuxt)?.defaultDisk).toBe('media')
expect(getHoloStorageRuntimeConfig(nuxt)?.routePrefix).toBe('/files')
expect(nuxt.options.build.transpile).toContain('./runtime')
expect(addImports).toHaveBeenCalledTimes(1)
expect(addImports.mock.calls[0]?.[0]).toHaveLength(6)
Expand Down Expand Up @@ -417,7 +444,7 @@ export default defineStorageConfig({
await module.setup({}, nuxt as never)
runHook(nuxt, 'modules:done')

expect((nuxt.options as { nitro: { storage: Record<string, unknown> } }).nitro.storage).toEqual({
expect(getNitroStorage(nuxt)).toEqual({
'holo:local': {
driver: 'fs',
base: './storage/app',
Expand All @@ -427,8 +454,8 @@ export default defineStorageConfig({
base: './storage/app/public',
},
})
expect((nuxt.options.runtimeConfig.holoStorage as Record<string, unknown>).defaultDisk).toBe('local')
expect((nuxt.options.runtimeConfig.holoStorage as Record<string, unknown>).routePrefix).toBe('/storage')
expect(getHoloStorageRuntimeConfig(nuxt)?.defaultDisk).toBe('local')
expect(getHoloStorageRuntimeConfig(nuxt)?.routePrefix).toBe('/storage')
expect(addServerHandler).toHaveBeenCalledWith({
route: '/storage/**',
handler: './runtime/server/routes/storage.get',
Expand Down Expand Up @@ -473,7 +500,7 @@ export default defineStorageConfig({
process.chdir(previousCwd)
}

expect((nuxt.options as { nitro: { storage: Record<string, unknown> } }).nitro.storage).toEqual({
expect(getNitroStorage(nuxt)).toEqual({
'holo:legacy': {
driver: 'fs',
base: './legacy',
Expand All @@ -483,8 +510,8 @@ export default defineStorageConfig({
delete (nuxt.options as { runtimeConfig?: Record<string, unknown> }).runtimeConfig
runHook(nuxt, 'modules:done')

expect((nuxt.options.runtimeConfig.holoStorage as Record<string, unknown>).defaultDisk).toBe('media')
expect((nuxt.options as { nitro: { storage: Record<string, unknown> } }).nitro.storage).toEqual({
expect(getHoloStorageRuntimeConfig(nuxt)?.defaultDisk).toBe('media')
expect(getNitroStorage(nuxt)).toEqual({
'holo:local': {
driver: 'fs',
base: './storage/app',
Expand Down Expand Up @@ -533,7 +560,7 @@ export default defineStorageConfig({

await module.setup({}, nuxt as never)

expect((nuxt.options as { nitro: { storage: Record<string, unknown> } }).nitro.storage).toMatchObject({
expect(getNitroStorage(nuxt)).toMatchObject({
'holo:local': {
driver: 'fs',
base: './storage/app',
Expand Down
11 changes: 11 additions & 0 deletions packages/adapter-nuxt/tsconfig.tests.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "./tsconfig.json",
"include": [
"src/**/*",
"tests/**/*.ts"
],
"exclude": [
"node_modules",
"dist"
]
}
Loading