2021-11-11 02:31:32 +01:00
|
|
|
import { createNext, FileRef } from 'e2e-utils'
|
|
|
|
import { check } from 'next-test-utils'
|
|
|
|
import webdriver from 'next-webdriver'
|
2024-04-09 00:25:43 +02:00
|
|
|
import { NextInstance } from 'e2e-utils'
|
2021-11-11 02:31:32 +01:00
|
|
|
import { join } from 'path'
|
|
|
|
|
2023-09-27 13:55:45 +02:00
|
|
|
describe('nonce head manager', () => {
|
2021-11-11 02:31:32 +01:00
|
|
|
let next: NextInstance
|
|
|
|
|
|
|
|
beforeAll(async () => {
|
|
|
|
next = await createNext({
|
|
|
|
files: {
|
|
|
|
pages: new FileRef(join(__dirname, 'app/pages')),
|
|
|
|
public: new FileRef(join(__dirname, 'app/public')),
|
|
|
|
},
|
|
|
|
nextConfig: new FileRef(join(__dirname, 'app/next.config.js')),
|
|
|
|
})
|
|
|
|
})
|
|
|
|
afterAll(() => next.destroy())
|
|
|
|
|
|
|
|
async function runTests(url) {
|
|
|
|
const browser = await webdriver(next.url, url)
|
|
|
|
await check(
|
|
|
|
async () =>
|
|
|
|
await browser.eval(`JSON.stringify(window.scriptExecutionIds)`),
|
|
|
|
'["src-1.js"]'
|
|
|
|
)
|
|
|
|
|
|
|
|
await browser.elementByCss('#force-rerender').click()
|
|
|
|
await check(
|
|
|
|
async () =>
|
|
|
|
await browser.eval(`document.getElementById('h1').textContent`),
|
|
|
|
'Count 1'
|
|
|
|
)
|
|
|
|
await check(
|
|
|
|
async () =>
|
|
|
|
await browser.eval(`JSON.stringify(window.scriptExecutionIds)`),
|
|
|
|
'["src-1.js"]'
|
|
|
|
)
|
|
|
|
|
|
|
|
await browser.elementByCss('#change-script').click()
|
|
|
|
await check(
|
|
|
|
async () =>
|
|
|
|
await browser.eval(`JSON.stringify(window.scriptExecutionIds)`),
|
|
|
|
'["src-1.js","src-2.js"]'
|
|
|
|
)
|
2024-05-07 18:18:32 +02:00
|
|
|
|
|
|
|
await browser.elementByCss('#change-script').click()
|
|
|
|
await check(
|
|
|
|
async () =>
|
|
|
|
await browser.eval(`JSON.stringify(window.scriptExecutionIds)`),
|
|
|
|
'["src-1.js","src-2.js","src-1.js"]'
|
|
|
|
)
|
2021-11-11 02:31:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
it('should not re-execute the script when re-rendering', async () => {
|
|
|
|
await runTests('/')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should not re-execute the script when re-rendering with CSP header', async () => {
|
|
|
|
await runTests('/csp')
|
|
|
|
})
|
|
|
|
})
|