rsnext/test/unit/warn-removed-experimental-config.test.ts
Sukka c728575599
refactor: add warning helper for removed experimental option (#44213)
Continues #44202, implements
https://github.com/vercel/next.js/pull/44202#discussion_r1053678383.

cc @styfle 

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the
feature request has been accepted for implementation before opening a
PR.
- [ ] Related issues linked using `fixes #number`
- [ ]
[e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
2023-01-03 12:17:00 -08:00

98 lines
2.6 KiB
TypeScript

import { warnOptionHasBeenMovedOutOfExperimental } from 'next/dist/server/config'
describe('warnOptionHasBeenMovedOutOfExperimental', () => {
let spy: jest.SpyInstance
beforeAll(() => {
spy = jest.spyOn(console, 'warn').mockImplementation(() => {})
})
it('should not log warning message without experimental config', () => {
warnOptionHasBeenMovedOutOfExperimental(
{},
'skipTrailingSlashRedirect',
'skipTrailingSlashRedirect',
'next.config.js'
)
warnOptionHasBeenMovedOutOfExperimental(
{
experimental: {},
},
'skipTrailingSlashRedirect',
'skipTrailingSlashRedirect',
'next.config.js'
)
expect(spy).not.toBeCalled()
})
it('should log warning message with removed experimental config', () => {
warnOptionHasBeenMovedOutOfExperimental(
{
experimental: {
skipTrailingSlashRedirect: true,
},
} as any,
'skipTrailingSlashRedirect',
'skipTrailingSlashRedirect',
'next.config.js'
)
expect(spy).toHaveBeenCalledWith(
expect.stringContaining('warn'),
'`skipTrailingSlashRedirect` has been moved out of `experimental`. Please update your next.config.js file accordingly.'
)
})
it('should log warning message with removed experimental config - complex key', () => {
warnOptionHasBeenMovedOutOfExperimental(
{
experimental: {
relay: true,
},
} as any,
'relay',
'compiler.relay',
'next.config.js'
)
expect(spy).toHaveBeenCalledWith(
expect.stringContaining('warn'),
'`relay` has been moved out of `experimental` and into `compiler.relay`. Please update your next.config.js file accordingly.'
)
})
it('should update removed experimental config into new config', () => {
const config = {
experimental: {
skipTrailingSlashRedirect: true,
},
} as any
warnOptionHasBeenMovedOutOfExperimental(
config,
'skipTrailingSlashRedirect',
'skipTrailingSlashRedirect',
'next.config.js'
)
expect(config.experimental.skipTrailingSlashRedirect).toBe(true)
expect(config.skipTrailingSlashRedirect).toBe(true)
})
it('should update removed experimental config into new config - complex key', () => {
const config = {
experimental: {
foo: 'bar',
},
} as any
warnOptionHasBeenMovedOutOfExperimental(
config,
'foo',
'deep.prop.baz',
'next.config.js'
)
expect(config.experimental.foo).toBe('bar')
expect(config.deep.prop.baz).toBe('bar')
})
})