rsnext/test/e2e/styled-jsx/index.test.ts
Jiachi Liu b508fef218
Merge e2e test node_modules (#40926)
Merge e2e tests customized `node_modules` with installed `node_modules`,
to let you debug easily locally without moving folder between
`node_modules` and `node_modules_bak`

Also add `optoutServerComponentsBundle` to config schema.
2022-09-27 15:18:08 +02:00

70 lines
2.1 KiB
TypeScript

import path from 'path'
import { createNext, FileRef } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base'
import { renderViaHTTP } from 'next-test-utils'
import webdriver from 'next-webdriver'
const appDir = path.join(__dirname, 'app')
function runTest() {
describe(`styled-jsx`, () => {
let next: NextInstance
beforeAll(async () => {
next = await createNext({
files: {
node_modules: new FileRef(path.join(appDir, 'node_modules')),
pages: new FileRef(path.join(appDir, 'pages')),
'.npmrc': new FileRef(path.join(appDir, '.npmrc')),
},
packageJson: {
scripts: {
build: 'next build',
dev: 'next dev',
start: 'next start',
},
},
dependencies: {
// A different version of styled-jsx on user side,
// using a different patch version comparing to the one from next.js
'styled-jsx': '5.0.0',
},
startCommand: 'yarn ' + ((global as any).isNextDev ? 'dev' : 'start'),
buildCommand: 'yarn build',
installCommand: 'yarn',
})
})
afterAll(() => next.destroy())
it('should contain styled-jsx styles during SSR', async () => {
const html = await renderViaHTTP(next.url, '/')
expect(html).toMatch(/color:.*?red/)
expect(html).toMatch(/color:.*?cyan/)
})
it('should render styles during CSR', async () => {
const browser = await webdriver(next.url, '/')
const color = await browser.eval(
`getComputedStyle(document.querySelector('button')).color`
)
expect(color).toMatch('0, 255, 255')
})
it('should render styles during CSR (AMP)', async () => {
const browser = await webdriver(next.url, '/amp')
const color = await browser.eval(
`getComputedStyle(document.querySelector('button')).color`
)
expect(color).toMatch('0, 255, 255')
})
it('should render styles during SSR (AMP)', async () => {
const html = await renderViaHTTP(next.url, '/amp')
expect(html).toMatch(/color:.*?cyan/)
})
})
}
runTest()