Skip to content

Commit

Permalink
add tests for app dir scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
zbauman3 committed Jan 3, 2024
1 parent 6f8a439 commit e923551
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/next/src/client/script.tsx
Expand Up @@ -353,7 +353,7 @@ function Script(props: ScriptProps): JSX.Element | null {
dangerouslySetInnerHTML={{
__html: `(self.__next_s=self.__next_s||[]).push(${JSON.stringify([
src,
{ ...restProps, id }
{ ...restProps, id },
])})`,
}}
/>
Expand Down
16 changes: 16 additions & 0 deletions test/e2e/app-dir/app/app/script/page.js
Expand Up @@ -33,6 +33,22 @@ export default function Page() {
`,
}}
/>
<Script
strategy="beforeInteractive"
src="/noop-test.js"
id="script-with-src-noop-test"
data-extra-prop="script-with-src"
/>
<Script
strategy="beforeInteractive"
dangerouslySetInnerHTML={{
__html: `
console.log('noop-test-dangerouslySetInnerHTML')
`,
}}
id="script-without-src-noop-test-dangerouslySetInnerHTML"
data-extra-prop="script-without-src"
/>
</div>
)
}
20 changes: 20 additions & 0 deletions test/e2e/app-dir/app/index.test.ts
Expand Up @@ -1751,6 +1751,26 @@ createNextDescribe(
return 'yes'
}, 'yes')
})

it('should pass on extra props for beforeInteractive scripts with a src prop', async () => {
const browser = await next.browser('/script')

const foundProps = await browser.eval(
`document.querySelector('#script-with-src-noop-test').getAttribute('data-extra-prop')`
)

expect(foundProps).toBe('script-with-src')
})

it('should pass on extra props for beforeInteractive scripts without a src prop', async () => {
const browser = await next.browser('/script')

const foundProps = await browser.eval(
`document.querySelector('#script-without-src-noop-test-dangerouslySetInnerHTML').getAttribute('data-extra-prop')`
)

expect(foundProps).toBe('script-without-src')
})
}

it('should insert preload tags for beforeInteractive and afterInteractive scripts', async () => {
Expand Down
1 change: 1 addition & 0 deletions test/e2e/app-dir/app/public/noop-test.js
@@ -0,0 +1 @@
console.log('test-noop')

0 comments on commit e923551

Please sign in to comment.