File size: 1,722 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
import stripAnsi from 'strip-ansi'
import { nextTestSetup } from 'e2e-utils'
describe('config validation - validation only runs once', () => {
const { next } = nextTestSetup({
files: {
'pages/index.js': `
export default function Page() {
return <p>hello world</p>
}
`,
'next.config.js': `
module.exports = {
invalidOption: 'shouldTriggerValidation',
anotherBadKey: 'anotherBadValue'
}
`,
},
})
it('should validate config only once in root process', async () => {
await next.fetch('/')
const output = stripAnsi(next.cliOutput)
const validationHeaderMatches = output.match(
/Invalid next\.config\.js options detected:/g
)
const validationHeaderCount = validationHeaderMatches
? validationHeaderMatches.length
: 0
// Count occurrences of specific invalid option mentions
const invalidOptionMatches = output.match(/invalidOption/g)
const invalidOptionCount = invalidOptionMatches
? invalidOptionMatches.length
: 0
const anotherBadKeyMatches = output.match(/anotherBadKey/g)
const anotherBadKeyCount = anotherBadKeyMatches
? anotherBadKeyMatches.length
: 0
// Expect validation to have occurred
expect(output).toContain('Invalid next.config.js options detected')
expect(output).toContain('invalidOption')
expect(output).toContain('anotherBadKey')
// Expect validation header to appear only once (not multiple times from different processes)
expect(validationHeaderCount).toBe(1)
// Each invalid option should also appear only once in the validation output
expect(invalidOptionCount).toBe(1)
expect(anotherBadKeyCount).toBe(1)
})
})
|