Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion packages/nextjs/src/config/webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ function addValueInjectionLoader(
});
} else {
newConfig.module.rules.push({
test: /sentry\.client\.config\.(jsx?|tsx?)/,
test: /(?:sentry\.client\.config\.(jsx?|tsx?)|(?:src[\\/])?instrumentation-client\.(js|ts))$/,
use: [
{
loader: path.resolve(__dirname, 'loaders/valueInjectionLoader.js'),
Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs/test/config/loaders.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ describe('webpack loaders', () => {
});

expect(finalWebpackConfig.module.rules).toContainEqual({
test: /sentry\.client\.config\.(jsx?|tsx?)/,
test: /(?:sentry\.client\.config\.(jsx?|tsx?)|(?:src[\\/])?instrumentation-client\.(js|ts))$/,
use: [
{
loader: expect.stringMatching(/valueInjectionLoader\.js$/),
Expand Down
64 changes: 64 additions & 0 deletions packages/nextjs/test/config/valueInjectionLoader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,70 @@ describe('valueInjectionLoader', () => {
expect(result).toMatch(';globalThis["foo"] = "bar";');
});

it('should work with instrumentation-client.js files', () => {
const instrumentationLoaderThis = {
...loaderThis,
resourcePath: './instrumentation-client.js',
};

const userCode = `
import * as Sentry from '@sentry/nextjs';
Sentry.init();
`;

const result = valueInjectionLoader.call(instrumentationLoaderThis, userCode);

expect(result).toMatch(';globalThis["foo"] = "bar";');
});

it('should work with instrumentation-client.ts files', () => {
const instrumentationLoaderThis = {
...loaderThis,
resourcePath: './instrumentation-client.ts',
};

const userCode = `
import * as Sentry from '@sentry/nextjs';
Sentry.init();
`;

const result = valueInjectionLoader.call(instrumentationLoaderThis, userCode);

expect(result).toMatch(';globalThis["foo"] = "bar";');
});

it('should work with src/instrumentation-client.js files', () => {
const instrumentationLoaderThis = {
...loaderThis,
resourcePath: './src/instrumentation-client.js',
};

const userCode = `
import * as Sentry from '@sentry/nextjs';
Sentry.init();
`;

const result = valueInjectionLoader.call(instrumentationLoaderThis, userCode);

expect(result).toMatch(';globalThis["foo"] = "bar";');
});

it('should work with src/instrumentation-client.ts files', () => {
const instrumentationLoaderThis = {
...loaderThis,
resourcePath: './src/instrumentation-client.ts',
};

const userCode = `
import * as Sentry from '@sentry/nextjs';
Sentry.init();
`;

const result = valueInjectionLoader.call(instrumentationLoaderThis, userCode);

expect(result).toMatch(';globalThis["foo"] = "bar";');
});

it('should correctly insert values with directive', () => {
const userCode = `
"use client"
Expand Down
Loading