MCPcopy
hub / github.com/vercel/next.js / runTests

Function runTests

test/integration/script-loader/test/index.test.ts:23–327  ·  view source on GitHub ↗
(isDev)

Source from the content-addressed store, hash-verified

21let appPort
22
23const runTests = (isDev) => {
24 // TODO: We will refactor the next/script to be strict mode resilient
25 // Don't skip the test case for development mode (strict mode) once refactoring is finished
26 it('priority afterInteractive', async () => {
27 let browser: Playwright
28 try {
29 browser = await webdriver(appPort, '/')
30 await waitFor(1000)
31
32 async function test(scriptID: string) {
33 const script = await browser.elementByCss(`script#${scriptID}`)
34 const dataAttr = await script.getAttribute('data-nscript')
35 const endScripts = await browser.elementsByCss(
36 `#__NEXT_DATA__ ~ script#${scriptID}`
37 )
38
39 // Renders script tag
40 expect(script).toBeDefined()
41 expect(dataAttr).toBeDefined()
42
43 // Script is inserted at the end
44 expect(endScripts.length).toBe(1)
45 }
46
47 // afterInteractive script in page
48 await test('scriptAfterInteractive')
49 // afterInteractive script in _document
50 await test('documentAfterInteractive')
51 } finally {
52 if (browser) await browser.close()
53 }
54 })
55
56 it('priority lazyOnload', async () => {
57 let browser: Playwright
58 try {
59 browser = await webdriver(appPort, '/page3')
60
61 await browser.waitForElementByCss('#onload-div', { state: 'attached' })
62 await waitFor(1000)
63
64 async function test(scriptId: string, css?: string) {
65 const script = await browser.elementByCss(`script#${scriptId}`)
66 const dataAttr = await script.getAttribute('data-nscript')
67 const endScripts = await browser.elementsByCss(
68 `#__NEXT_DATA__ ~ #${scriptId}`
69 )
70
71 // Renders script tag
72 expect(script).toBeDefined()
73 expect(dataAttr).toBeDefined()
74
75 if (css) {
76 const cssTag = await browser.elementByCss(`link[href="${css}"]`)
77 expect(cssTag).toBeDefined()
78 }
79
80 // Script is inserted at the end

Callers 1

index.test.tsFile · 0.70

Calls 15

waitForFunction · 0.90
renderViaHTTPFunction · 0.90
nextBuildFunction · 0.90
webdriverFunction · 0.85
waitForElementByCssMethod · 0.80
elementsByCssMethod · 0.80
clickMethod · 0.80
elementByIdMethod · 0.80
includesMethod · 0.80
evalMethod · 0.80
testFunction · 0.70
closeMethod · 0.65

Tested by

no test coverage detected