Nuxt/test/dev.test.ts

33 lines
1.0 KiB
TypeScript
Raw Normal View History

2023-03-06 00:26:09 +00:00
import { fileURLToPath } from 'node:url'
// eslint-disable-next-line import/order
import { setup, $fetch } from '@nuxt/test-utils'
import { describe, it, expect } from 'vitest'
await setup({
2023-03-06 02:02:11 +00:00
rootDir: fileURLToPath(new URL('./fixtures/minimal', import.meta.url)),
2023-03-06 00:26:09 +00:00
dev: true,
nuxtConfig: {
app: {
baseURL: '/test'
2023-03-06 02:02:11 +00:00
},
runtimeConfig: {
public: {
foo: 'bar',
}
2023-03-06 00:26:09 +00:00
}
}
})
describe('dev tests', () => {
2023-03-06 02:02:11 +00:00
it('config is overriden', async () => {
const html = await $fetch('/')
const expr = /window.__NUXT__=({.*})<\/script>/.exec(html)![1]
expect(expr).toMatchInlineSnapshot('"{data:{},state:{},_errors:{},serverRendered:true,config:{public:{foo:\\"bar\\"},app:{baseURL:\\"\\\\u002Ftest\\",buildAssetsDir:\\"\\\\u002F_nuxt\\\\u002F\\",cdnURL:\\"\\"}}}"')
// expr is a javascript object string, but not valid JSON, we need to turn it a real object
const obj = JSON.parse(expr.replace(/(\w+):/g, '"$1":'))
expect(obj.config.public.foo).toBe('bar')
expect(obj.config.app.baseURL).toBe('/test')
2023-03-06 00:26:09 +00:00
})
})