Skip to content

Commit

Permalink
add import.meta.url test case
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Dec 5, 2024
1 parent 7a3dbd1 commit 621016a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const text = import.meta.url

export default function Page() {
return <p>{text}</p>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use client'

const text = import.meta.url

export default function Page() {
return <p>{text}</p>
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,38 @@ describe('non-root-project-monorepo', () => {
})
})

describe('import.meta.url', () => {
it('should work during RSC', async () => {
const $ = await next.render$('/import-meta-url-rsc')
expect($('p').text()).toMatch(
/^file:\/\/.*\/next-install-[^/]+\/apps\/web\/app\/import-meta-url-rsc\/page.tsx$/
)
})

it('should work during SSR', async () => {
const $ = await next.render$('/import-meta-url-ssr')
expect($('p').text()).toMatch(
/^file:\/\/.*\/next-install-[^/]+\/apps\/web\/app\/import-meta-url-ssr\/page.tsx$/
)
})

it('should work on client-side', async () => {
const browser = await next.browser('/import-meta-url-ssr')
await assertNoRedbox(browser)
if (isTurbopack) {
// Turbopack intentionally doesn't expose the full path to the browser bundles
expect(await browser.elementByCss('p').text()).toBe(
'file:///ROOT/apps/web/app/import-meta-url-ssr/page.tsx'
)
} else {
expect(await browser.elementByCss('p').text()).toMatch(
/^file:\/\/.*\/next-install-[^/]+\/apps\/web\/app\/import-meta-url-ssr\/page.tsx$/
)
}
await browser.close()
})
})

if (isNextDev) {
describe('source-maps', () => {
function normalizeStackTrace(stack: string): string {
Expand Down

0 comments on commit 621016a

Please sign in to comment.