mirror of
https://github.com/stablyai/orca.git
synced 2026-11-16 10:58:10 +00:00
test: include reached renderer images in native fixture assets
This commit is contained in:
@@ -1,41 +0,0 @@
|
||||
import { readdirSync, readFileSync } from 'node:fs'
|
||||
import { dirname, join, resolve } from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import { normalizePath, type Plugin } from 'vite'
|
||||
|
||||
export function localeCatalogTestAssets(): Plugin {
|
||||
const directory = fileURLToPath(new URL('../../src/renderer/src/i18n/locales/', import.meta.url))
|
||||
const filesById = new Map<string, string>()
|
||||
const idsByPath = new Map<string, string>()
|
||||
for (const filename of readdirSync(directory)) {
|
||||
if (/^[A-Za-z-]+\.json$/.test(filename)) {
|
||||
const id = `\0locale-catalog-test-assets:${filename}.js`
|
||||
const file = join(directory, filename)
|
||||
filesById.set(id, file)
|
||||
idsByPath.set(`${normalizePath(file)}?url`, id)
|
||||
}
|
||||
}
|
||||
return {
|
||||
name: 'locale-catalog-test-assets',
|
||||
enforce: 'pre',
|
||||
resolveId(source, importer) {
|
||||
if (filesById.has(source)) {
|
||||
return source
|
||||
}
|
||||
if (!source.endsWith('.json?url')) {
|
||||
return null
|
||||
}
|
||||
const file = importer ? resolve(dirname(importer.split('?')[0]), source) : source
|
||||
return idsByPath.get(normalizePath(file)) ?? null
|
||||
},
|
||||
load(id) {
|
||||
const file = filesById.get(id)
|
||||
if (!file) {
|
||||
return null
|
||||
}
|
||||
// Virtual modules retain real fetch(data:) parsing without exposing files outside the test root.
|
||||
const catalog = readFileSync(file).toString('base64')
|
||||
return `export default ${JSON.stringify(`data:application/json;base64,${catalog}`)}`
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import { readdirSync, readFileSync } from 'node:fs'
|
||||
import { dirname, join, resolve } from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import { normalizePath, type Plugin } from 'vite'
|
||||
|
||||
export function rendererTestAssets(
|
||||
additionalAssets: readonly { url: URL; contentType: string }[] = []
|
||||
): Plugin {
|
||||
const directory = fileURLToPath(new URL('../../src/renderer/src/i18n/locales/', import.meta.url))
|
||||
const filesById = new Map<string, { file: string; contentType: string }>()
|
||||
const idsByPath = new Map<string, string>()
|
||||
const assets = [
|
||||
...readdirSync(directory)
|
||||
.filter((filename) => /^[A-Za-z-]+\.json$/.test(filename))
|
||||
.map((filename) => ({ file: join(directory, filename), contentType: 'application/json' })),
|
||||
...additionalAssets.map(({ url, contentType }) => ({ file: fileURLToPath(url), contentType }))
|
||||
]
|
||||
for (const asset of assets) {
|
||||
const id = `\0renderer-test-asset:${filesById.size}.js`
|
||||
filesById.set(id, asset)
|
||||
idsByPath.set(`${normalizePath(asset.file)}?url`, id)
|
||||
}
|
||||
return {
|
||||
name: 'renderer-test-assets',
|
||||
enforce: 'pre',
|
||||
resolveId(source, importer) {
|
||||
if (filesById.has(source)) {
|
||||
return source
|
||||
}
|
||||
if (!source.endsWith('?url')) {
|
||||
return null
|
||||
}
|
||||
const file = importer ? resolve(dirname(importer.split('?')[0]), source) : source
|
||||
return idsByPath.get(normalizePath(file)) ?? null
|
||||
},
|
||||
load(id) {
|
||||
const asset = filesById.get(id)
|
||||
if (!asset) {
|
||||
return null
|
||||
}
|
||||
// Virtual modules retain real fetch(data:) parsing without exposing files outside the test root.
|
||||
const content = readFileSync(asset.file).toString('base64')
|
||||
return `export default ${JSON.stringify(`data:${asset.contentType};base64,${content}`)}`
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ import { nodeRuntimePool } from './scripts/vitest-node-runtime-pool'
|
||||
import { readRunFilters } from './scripts/vitest-run-filters.mjs'
|
||||
import { createWorkspaceSourceResolver } from './scripts/workspace-source-exports.mjs'
|
||||
import { moduleCacheResolutionKey } from './scripts/vitest-module-cache-resolution-key'
|
||||
import { localeCatalogTestAssets } from './scripts/locale-catalog-test-assets'
|
||||
import { rendererTestAssets } from './scripts/renderer-test-assets'
|
||||
|
||||
const nodeRuntimeInclude = process.versions.bun
|
||||
? getNodeRuntimeInclude({ filters: readRunFilters() })
|
||||
@@ -62,7 +62,7 @@ const transforms = {
|
||||
}
|
||||
} satisfies Plugin,
|
||||
...(moduleCachePath ? [moduleCacheResolutionKey()] : []),
|
||||
localeCatalogTestAssets()
|
||||
rendererTestAssets()
|
||||
],
|
||||
define: {
|
||||
ORCA_FEATURE_WALL_ENABLED: 'true',
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import { defineConfig } from 'vitest/config'
|
||||
import { localeCatalogTestAssets } from '../config/scripts/locale-catalog-test-assets'
|
||||
import { rendererTestAssets } from '../config/scripts/renderer-test-assets'
|
||||
|
||||
const vitestOxcConfig = { tsconfig: false } as never
|
||||
|
||||
@@ -8,7 +8,14 @@ export default defineConfig({
|
||||
root: import.meta.dirname,
|
||||
// Tests are excluded from the app tsconfig; disable that config for OXC so test modules still transform.
|
||||
oxc: vitestOxcConfig,
|
||||
plugins: [localeCatalogTestAssets()],
|
||||
plugins: [
|
||||
rendererTestAssets(
|
||||
['claude', 'opencode', 'gremlin'].map((name) => ({
|
||||
url: new URL(`../resources/${name}.webp`, import.meta.url),
|
||||
contentType: 'image/webp'
|
||||
}))
|
||||
)
|
||||
],
|
||||
resolve: {
|
||||
// A faithful Node stand-in for the native module, rather than a mock in every test that reaches it.
|
||||
alias: {
|
||||
|
||||
Reference in New Issue
Block a user