Nuxt/test/dev/runtime-config.test.js
Pooya Parsa 0337932115
feat: runtime config and built-in dotenv support (#7312)
Co-authored-by: Sébastien Chopin <seb@nuxtjs.com>
Co-authored-by: Alexander Lichter <manniL@gmx.net>
2020-05-18 10:21:15 +02:00

46 lines
1.0 KiB
JavaScript

import { loadFixture, getPort, Nuxt } from '../utils'
let port
const url = route => 'http://localhost:' + port + route
let nuxt = null
describe('basic ssr', () => {
beforeAll(async () => {
const options = await loadFixture('runtime-config')
nuxt = new Nuxt(options)
await nuxt.ready()
port = await getPort()
await nuxt.server.listen(port, '0.0.0.0')
})
test('SSR payload', async () => {
const window = await nuxt.server.renderAndGetWindow(url('/'))
const payload = window.__NUXT__
expect(payload.config).toMatchObject({
baseURL: '/api'
})
expect(payload.data[0].serverConfig).toMatchObject({
baseURL: 'https://google.com/api',
API_SECRET: '1234'
})
})
test('SPA payload ', async () => {
const window = await nuxt.server.renderAndGetWindow(url('/?spa'))
const payload = window.__NUXT__
expect(payload.config).toMatchObject({
baseURL: '/api'
})
})
// Close server and ask nuxt to stop listening to file changes
afterAll(async () => {
await nuxt.close()
})
})