File size: 1,612 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 56 57 58 59 60 61 62 63 |
/* eslint-env jest */
import { transformSync } from '@babel/core'
const babel = (code) =>
transformSync(code, {
filename: 'page.tsx',
presets: ['@babel/preset-typescript'],
plugins: [require('next/dist/build/babel/plugins/next-page-config')],
babelrc: false,
configFile: false,
sourceType: 'module',
compact: true,
caller: {
name: 'tests',
isDev: false,
},
} as any).code
describe('babel plugin (next-page-config)', () => {
test('export config with type annotation', () => {
const output = babel('export const config: PageConfig = {};')
expect(output).toMatch(`export const config={};`)
})
test('export config with AsExpression', () => {
const output = babel('export const config = {} as PageConfig;')
expect(output).toMatch('export const config={};')
})
test('amp enabled', () => {
jest.spyOn(Date, 'now').mockReturnValue(1234)
const output = babel(`
export const config = { amp: true }
function About(props) {
return <h3>My AMP About Page!</h3>
}
export default About`)
expect(output).toMatch(
'const __NEXT_DROP_CLIENT_FILE__="__NEXT_DROP_CLIENT_FILE__ 1234";'
)
})
test('amp hybrid enabled', () => {
const output = babel(`
export const config = { amp: 'hybrid' }
function About(props) {
return <h3>My AMP About Page!</h3>
}
export default About`)
expect(output).toMatch(
"export const config={amp:'hybrid'};function About(props){return<h3>My AMP About Page!</h3>;}export default About;"
)
})
})
|