Skip to content

Commit

Permalink
Add test case for client sourcemaps (#49308)
Browse files Browse the repository at this point in the history
This PR adds a test case to ensure that the server reference doesn't expose actual content of the original file in its sourcemap.

Closes NEXT-1041.
  • Loading branch information
shuding authored May 5, 2023
1 parent 92ff2dd commit 9bd00a8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
20 changes: 20 additions & 0 deletions test/e2e/app-dir/actions/app-action.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { createNextDescribe } from 'e2e-utils'
import { check } from 'next-test-utils'
import { Request } from 'playwright-chromium'
import fs from 'fs-extra'
import { join } from 'path'

const GENERIC_RSC_ERROR =
'Error: An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details. A digest property is included on this error instance which may provide additional details about the nature of the error.'
Expand Down Expand Up @@ -170,6 +172,24 @@ createNextDescribe(
await check(() => browser.elementByCss('h1').text(), '3')
})

if (!isNextDev) {
it('should not expose action content in sourcemaps', async () => {
const sourcemap = (
await fs.readdir(
join(next.testDir, '.next', 'static', 'chunks', 'app', 'client')
)
).find((f) => f.endsWith('.js.map'))

expect(sourcemap).toBeDefined()

expect(
await next.readFile(
join('.next', 'static', 'chunks', 'app', 'client', sourcemap)
)
).not.toContain('this_is_sensitive_info')
})
}

if (isNextDev) {
describe('HMR', () => {
it('should support updating the action', async () => {
Expand Down
1 change: 1 addition & 0 deletions test/e2e/app-dir/actions/app/client/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export async function dec(value) {
}

export default async function (value) {
console.log('this_is_sensitive_info')
return value * 2
}

Expand Down
1 change: 1 addition & 0 deletions test/e2e/app-dir/actions/next.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/** @type {import('next').NextConfig} */
module.exports = {
productionBrowserSourceMaps: true,
experimental: {
serverActions: true,
},
Expand Down

0 comments on commit 9bd00a8

Please sign in to comment.