mirror of
https://github.com/vercel/next.js.git
synced 2026-09-20 02:25:18 +08:00
efc0905db3
Expand `config.compiler.define` to support number and boolean primitives as well. The support is already in Turbopack's rewrite engine, as well as Webpack's DefinePlugin. We just need to modify the zod schema to actually support passing numbers and bools. Added an E2E test that should check all supported types.
70 lines
2.3 KiB
TypeScript
70 lines
2.3 KiB
TypeScript
import { nextTestSetup } from 'e2e-utils'
|
|
|
|
describe('compiler.define', () => {
|
|
const { next } = nextTestSetup({
|
|
files: __dirname,
|
|
})
|
|
|
|
describe('compiler.define', () => {
|
|
let loadedText
|
|
beforeEach(async () => {
|
|
let browser = await next.browser('/')
|
|
loadedText = await browser.elementByCss('body').text()
|
|
})
|
|
|
|
it('should render the magic variable on server side', async () => {
|
|
expect(loadedText).toContain('Server value: foobar')
|
|
expect(loadedText).toContain('Client value: foobar')
|
|
})
|
|
|
|
it('should render the magic variable on client side', async () => {
|
|
expect(loadedText).toContain('Server value: foobar')
|
|
expect(loadedText).toContain('Client value: foobar')
|
|
})
|
|
|
|
it('should render the magic expression on server side', async () => {
|
|
expect(loadedText).toContain('Server expr: barbaz')
|
|
expect(loadedText).toContain('Client expr: barbaz')
|
|
})
|
|
|
|
it('should render the magic expression on client side', async () => {
|
|
expect(loadedText).toContain('Server expr: barbaz')
|
|
expect(loadedText).toContain('Client expr: barbaz')
|
|
})
|
|
|
|
it('should render a number variable on server and client side', async () => {
|
|
expect(loadedText).toContain('Server number: 42')
|
|
expect(loadedText).toContain('Client number: 42')
|
|
})
|
|
|
|
it('should render a boolean variable on server and client side', async () => {
|
|
expect(loadedText).toContain('Server boolean: true')
|
|
expect(loadedText).toContain('Client boolean: true')
|
|
})
|
|
})
|
|
|
|
describe('compiler.defineServer', () => {
|
|
let loadedText
|
|
beforeEach(async () => {
|
|
let browser = await next.browser('/with-server-only')
|
|
loadedText = await browser.elementByCss('body').text()
|
|
})
|
|
|
|
it('should render the inlined variable on server side', async () => {
|
|
expect(loadedText).toContain('Server value: server')
|
|
})
|
|
|
|
it('should not render the inlined variable on client side', async () => {
|
|
expect(loadedText).toContain('Client value: not set')
|
|
})
|
|
|
|
it('should render the inlined expression on server side', async () => {
|
|
expect(loadedText).toContain('Server expr: serverbarbaz')
|
|
})
|
|
|
|
it('should not render the inlined expression on client side', async () => {
|
|
expect(loadedText).toContain('Client expr: not set')
|
|
})
|
|
})
|
|
})
|