useStorage not working properly
Closed this issue · 3 comments
Problem description:
When using nitro-test-utils and trying to get something from Nitro JS storage I always get null
.
const code = await useStorage('assets:views').getItem(path);
const tailwindConfig = await useStorage('assets:views').getItem('mail/tailwindConfig.ts');
Both code
and tailwindConfig
are null.
The problem does not occur when running API in dev mode (bun run dev
), without vitest enabled.
It happens only with nitro-test-utils
vitest.config.mts
export default defineConfig({
nitro: {
global: {
rootDir: 'src',
mode: 'development'
}
}
});
Can you please provide a reproducible example and give more context how the storage is populated? Thanks!
For my projects, I usually populate the data during tests and provide a separate unstorage
cache driver to get reproducible test results:
import process from 'node:process'
export default defineNitroConfig({
storage: {
telemetry: {
driver: 'cloudflareKVBinding',
binding: 'KV_TELEMETRY',
},
},
devStorage: {
telemetry: {
driver: process.env.VITEST === 'true' ? 'memory' : 'fs',
base: '.data/telemetry',
},
},
})
Yes, of course. I use storage for serverAssets:
export default defineNitroConfig({
/////
serverAssets: [
{
baseName: 'views',
dir: './views'
}
],
/////
}
As simple as that.
No way, it was not working due to error in my vite config...
rootDir key had wrong path to project...
export default defineConfig({
nitro: {
global: {
rootDir: 'src', // ----> I removed this and now everything works :)
mode: 'development'
}
}
});
Sorry for the confusion and thanks for help!