Skip to content

Commit

Permalink
ref(profiling) test local require
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasBa committed Nov 25, 2024
1 parent b271bc8 commit fc0e866
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
21 changes: 21 additions & 0 deletions dev-packages/e2e-tests/test-applications/node-profiling/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import * as Sentry from '@sentry/node';
import { nodeProfilingIntegration } from '@sentry/profiling-node';

const wait = ms => new Promise(resolve => setTimeout(resolve, ms));

Sentry.init({
dsn: 'https://[email protected]/6625302',
integrations: [nodeProfilingIntegration()],
tracesSampleRate: 1.0,
profilesSampleRate: 1.0,
});

Sentry.startSpan({ name: 'Precompile test' }, async () => {
await wait(500);
});

// Test that globalThis.require is not defined by any side effects of the profiling
// https://github.com/getsentry/sentry-javascript/issues/13662
if (globalThis.require !== undefined) {
throw new Error('globalThis.require should not be defined, check that profiling integration is not defining it');
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scripts": {
"typecheck": "tsc --noEmit",
"build": "node build.mjs && node build.shimmed.mjs",
"test": "node dist/index.js && node --experimental-require-module dist/index.js && node dist/index.shimmed.mjs",
"test": "node dist/index.js && node --experimental-require-module dist/index.js && node dist/index.shimmed.mjs && node index.mjs",
"clean": "npx rimraf node_modules dist",
"test:electron": "$(pnpm bin)/electron-rebuild && playwright test",
"test:build": "pnpm run typecheck && pnpm run build",
Expand Down
17 changes: 2 additions & 15 deletions packages/profiling-node/rollup.npm.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,9 @@ import commonjs from '@rollup/plugin-commonjs';
import { makeBaseNPMConfig, makeNPMConfigVariants } from '@sentry-internal/rollup-utils';

export const ESMShim = `
import cjsUrl from 'node:url';
import cjsPath from 'node:path';
import cjsModule from 'node:module';
if(typeof __filename === 'undefined'){
globalThis.__filename = cjsUrl.fileURLToPath(import.meta.url);
}
if(typeof __dirname === 'undefined'){
globalThis.__dirname = cjsPath.dirname(__filename);
}
if(typeof require === 'undefined'){
globalThis.require = cjsModule.createRequire(import.meta.url);
}
`;
const require = cjsModule.createRequire(import.meta.url);
`

function makeESMShimPlugin(shim) {
return {
Expand Down

0 comments on commit fc0e866

Please sign in to comment.