Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as fs from 'fs';
import * as path from 'path';
import * as assert from 'assert/strict';
import { findSourceMapFiles } from '@sentry-internal/test-utils';

const nextPackageJson = require('next/package.json');
const nextjsVersion = nextPackageJson.version;
Expand Down Expand Up @@ -41,12 +42,9 @@ const getLatestNextVersion = async () => {
assert.match(buildStdout, /(λ|ƒ) \/server-component\/parameter\/\[\.\.\.parameters\]/);
assert.match(buildStdout, /(λ|ƒ) \/server-component\/parameter\/\[parameter\]/);

// Read the contents of the directory
const files = fs.readdirSync(path.join(process.cwd(), '.next', 'static'));
const mapFiles = files.filter(file => path.extname(file) === '.map');
if (mapFiles.length > 0) {
throw new Error(
'Client bundle .map files found even though `sourcemaps.deleteSourcemapsAfterUpload` option is set!',
);
}
assert.deepEqual(
findSourceMapFiles({ outputDir: path.join('.next', 'static') }),
[],
'Client bundle .map files found even though `sourcemaps.deleteSourcemapsAfterUpload` option is set!',
);
})();
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as fs from 'fs';
import * as path from 'path';
import * as assert from 'assert/strict';
import { findSourceMapFiles } from '@sentry-internal/test-utils';

const nextPackageJson = require('next/package.json');
const nextjsVersion = nextPackageJson.version;
Expand Down Expand Up @@ -33,12 +34,9 @@ const getLatestNextVersion = async () => {
);
}

// Read the contents of the directory
const files = fs.readdirSync(path.join(process.cwd(), '.next', 'static'));
const mapFiles = files.filter(file => path.extname(file) === '.map');
if (mapFiles.length > 0) {
throw new Error(
'Client bundle .map files found even though `sourcemaps.deleteSourcemapsAfterUpload` option is set!',
);
}
assert.deepEqual(
findSourceMapFiles({ outputDir: path.join('.next', 'static') }),
[],
'Client bundle .map files found even though `sourcemaps.deleteSourcemapsAfterUpload` option is set!',
);
})();
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
getSourcemapSources,
getChunkUploadPosts,
getAssembleRequests,
findSourceMapFiles,
findSourceMappingUrlComments,
} from '@sentry-internal/test-utils';

const requests = loadMockServerResults();
Expand Down Expand Up @@ -76,4 +78,15 @@ for (const req of assembleReqs) {
assert.ok((req.assembleBody?.chunks?.length ?? 0) > 0, 'Expected assemble request to have chunk checksums');
}

// The browser loads everything under `.next/static`, so a map left there hands out the source.
if (process.env.E2E_DELETE_SOURCEMAPS) {
const staticDir = '.next/static';
assert.deepEqual(findSourceMapFiles({ outputDir: staticDir }), [], `Expected no source maps in ${staticDir}`);
assert.deepEqual(
findSourceMappingUrlComments({ outputDir: staticDir }),
[],
`Expected no sourceMappingURL comments in ${staticDir}`,
);
}

console.log('All sourcemap upload assertions passed!');
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ module.exports = withSentryConfig(nextConfig, {
name: 'test-release',
},
sourcemaps: {
deleteSourcemapsAfterUpload: false,
// The delete variants use the SDK default, which removes the client maps after the upload.
deleteSourcemapsAfterUpload: process.env.E2E_DELETE_SOURCEMAPS ? undefined : false,
},
debug: true,
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
"version": "0.1.0",
"private": true,
"scripts": {
"build": "node start-mock-sentry-server.mjs & next build > .tmp_build_stdout 2> .tmp_build_stderr; BUILD_EXIT=$?; kill %1 2>/dev/null; exit $BUILD_EXIT",
"build": "node start-mock-sentry-server.mjs & next build ${E2E_NEXT_WEBPACK:+--webpack} > .tmp_build_stdout 2> .tmp_build_stderr; BUILD_EXIT=$?; kill %1 2>/dev/null; exit $BUILD_EXIT",
"clean": "npx rimraf node_modules pnpm-lock.yaml",
"test:build": "pnpm install && pnpm build",
"test:assert": "pnpm ts-node --script-mode assert-build.ts"
"test:assert": "pnpm ts-node --script-mode assert-build.ts",
"test:build:delete": "pnpm install && E2E_DELETE_SOURCEMAPS=1 pnpm build",
"test:build:delete-webpack": "pnpm install && E2E_DELETE_SOURCEMAPS=1 E2E_NEXT_WEBPACK=1 pnpm build",
"test:assert:delete": "E2E_DELETE_SOURCEMAPS=1 pnpm test:assert"
},
"dependencies": {
"@sentry/nextjs": "file:../../packed/sentry-nextjs-packed.tgz",
Expand All @@ -22,5 +25,19 @@
"@types/react": "^19",
"@types/react-dom": "^19",
"ts-node": "10.9.1"
},
"sentryTest": {
"variants": [
{
"build-command": "pnpm test:build:delete",
"assert-command": "pnpm test:assert:delete",
"label": "nextjs-sourcemaps (delete, turbopack)"
},
{
"build-command": "pnpm test:build:delete-webpack",
"assert-command": "pnpm test:assert:delete",
"label": "nextjs-sourcemaps (delete, webpack)"
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
findFilesWithForeignSourcemaps,
findFilesWithMultipleDebugIds,
findInjectedDebugIds,
findSourceMappingUrlComments,
getArtifactBundles,
getChunkUploadPosts,
getDebugIdPairs,
Expand Down Expand Up @@ -146,6 +147,13 @@ for (const outputDir of [CLIENT_OUTPUT, SERVER_OUTPUT]) {
assert.deepEqual(sourceMapsIn(outputDir), [], `Expected no source maps in ${outputDir}`);
}

// A surviving comment points browsers at a map that no longer exists.
assert.deepEqual(
findSourceMappingUrlComments({ outputDir: CLIENT_OUTPUT }),
[],
`Expected no sourceMappingURL comments in ${CLIENT_OUTPUT}`,
);

const clientChunkUrls = emittedJsFiles(CLIENT_OUTPUT).map(
file => `/${path.relative(CLIENT_OUTPUT, file).split(path.sep).join('/')}`,
);
Expand Down
9 changes: 9 additions & 0 deletions packages/gatsby/test/gatsby-node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,15 @@ describe('onCreateWebpackConfig', () => {
deleteSourceMaps: true,
},
},
{
name: 'replaces disabled source maps with hidden ones and deletes them',
initialConfig: { devtool: false },
options: {},
expected: {
devtool: 'hidden-source-map',
deleteSourceMaps: true,
},
},
{
name: 'explicit deleteSourcemapsAfterUpload true',
initialConfig: { devtool: 'source-map' },
Expand Down
Loading