Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 11 additions & 0 deletions examples/app-vitest-full/tests/paths.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/** @vitest-environment happy-dom */
import { describe, expect, it } from 'vitest'
// @ts-expect-error virtual module
import { baseURL, buildAssetsDir } from '#internal/nuxt/paths'

describe('generated paths module', () => {
it('resolves outside the nuxt environment', () => {
expect(() => baseURL()).not.toThrow()
expect(() => buildAssetsDir()).not.toThrow()
})
})
2 changes: 1 addition & 1 deletion examples/app-vitest-full/tests/resolved-files.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ test('it should include nuxt spec files', { timeout: 30000 }, async ({ onTestFin
const regularSpecFiles = testFiles.filter(file => file.project.name === 'node')

expect(nuxtSpecFiles.length).toEqual(26)
expect(regularSpecFiles.length).toEqual(2)
expect(regularSpecFiles.length).toEqual(3)
})
18 changes: 18 additions & 0 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,24 @@
await setupImportMocking(nuxt)
}

// inline runtime config the way dev builds do
if (nuxt.options.test && !nuxt.options.dev) {
nuxt.hook('app:templates', (app) => {
const template = app.templates.find(t => t.filename === 'paths.mjs')
if (!template?.getContents) {
return
}
const original = template.getContents
const inlineAppConfig = JSON.stringify(nuxt.options.app)
template.getContents = async (data) => {
const contents = await original(data)
return contents
.replace(/^import \{ useRuntimeConfig \} from ['"]nitropack\/runtime['"]\n?/m, '')
.replace(/const getAppConfig = \(\) => useRuntimeConfig\(\)\.app/, () => `const getAppConfig = () => (${inlineAppConfig})`)

Check warning

Code scanning / CodeQL

Improper code sanitization Medium

Code construction depends on an
improperly sanitized value
.
Comment thread
danielroe marked this conversation as resolved.
Dismissed
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
})
}

const { addVitePlugin } = await loadKit(nuxt.options.rootDir)

const resolver = createResolver(import.meta.url)
Expand Down
Loading