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
2 changes: 1 addition & 1 deletion packages/browser-utils/src/performance/interactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import {
getComponentName,
getRootSpan,
spanToJSON,
startIdleSpan,
} from '@sentry/core';
import { startIdleSpan } from '@sentry/core/browser';
import { DEBUG_BUILD } from '../debug-build';
import { htmlTreeAsString } from '../htmlTreeAsString';
import { addPerformanceInstrumentationHandler } from '../instrumentation/performanceObserver';
Expand Down
60 changes: 20 additions & 40 deletions packages/nuxt/test/vite/sourceMaps-nuxtHooks.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
import type { Nuxt } from '@nuxt/schema';
import type { Plugin, UserConfig } from 'vite';
import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
import type { SourceMapSetting } from '../../src/vite/sourceMaps';
import { afterAll, beforeEach, describe, expect, it, vi } from 'vitest';
import { setupSourceMaps, type SourceMapSetting } from '../../src/vite/sourceMaps';

const { mockSentryVitePlugin, mockSentryRollupPlugin, mockDeleteArtifacts, mockCreateSentryBuildPluginManager } =
vi.hoisted(() => {
const deleteArtifacts = vi.fn().mockResolvedValue(undefined);

return {
mockSentryVitePlugin: vi.fn(() => [{ name: 'sentry-vite-plugin' }]),
mockSentryRollupPlugin: vi.fn(() => ({ name: 'sentry-rollup-plugin' })),
mockDeleteArtifacts: deleteArtifacts,
mockCreateSentryBuildPluginManager: vi.fn(() => ({ deleteArtifacts })),
};
});

vi.mock('@sentry/bundler-plugins/core', () => ({
createSentryBuildPluginManager: mockCreateSentryBuildPluginManager,
}));
vi.mock('@sentry/bundler-plugins/vite', () => ({ sentryVitePlugin: mockSentryVitePlugin }));
vi.mock('@sentry/bundler-plugins/rollup', () => ({ sentryRollupPlugin: mockSentryRollupPlugin }));

function createMockAddVitePlugin() {
let capturedPlugins: Plugin[] | null = null;
Expand Down Expand Up @@ -54,32 +72,12 @@ describe('setupSourceMaps hooks', () => {
'.*/**/function/**/*.map',
];

const mockSentryVitePlugin = vi.fn(() => [{ name: 'sentry-vite-plugin' }]);
const mockSentryRollupPlugin = vi.fn(() => ({ name: 'sentry-rollup-plugin' }));
const mockDeleteArtifacts = vi.fn().mockResolvedValue(undefined);
const mockCreateSentryBuildPluginManager = vi.fn(() => ({ deleteArtifacts: mockDeleteArtifacts }));

const consoleLogSpy = vi.spyOn(console, 'log');
const consoleWarnSpy = vi.spyOn(console, 'warn');

beforeAll(() => {
vi.doMock('@sentry/bundler-plugins/core', () => ({
createSentryBuildPluginManager: mockCreateSentryBuildPluginManager,
}));
vi.doMock('@sentry/bundler-plugins/vite', () => ({
sentryVitePlugin: mockSentryVitePlugin,
}));
vi.doMock('@sentry/bundler-plugins/rollup', () => ({
sentryRollupPlugin: mockSentryRollupPlugin,
}));
});

afterAll(() => {
consoleLogSpy.mockRestore();
consoleWarnSpy.mockRestore();
vi.doUnmock('@sentry/bundler-plugins/core');
vi.doUnmock('@sentry/bundler-plugins/vite');
vi.doUnmock('@sentry/bundler-plugins/rollup');
});

beforeEach(() => {
Expand All @@ -95,7 +93,6 @@ describe('setupSourceMaps hooks', () => {
// `getPluginOptions` runs once per bundler (Vite and Nitro's Rollup), so warning there emitted
// the same message twice. This pins it to exactly one.
it('warns exactly once, even though both bundler plugins are set up', async () => {
const { setupSourceMaps } = await import('../../src/vite/sourceMaps');
const mockNuxt = createMockNuxt({});
const { mockAddVitePlugin } = createMockAddVitePlugin();

Expand All @@ -114,7 +111,6 @@ describe('setupSourceMaps hooks', () => {
});

it('does not warn for a config without removed options', async () => {
const { setupSourceMaps } = await import('../../src/vite/sourceMaps');
const mockNuxt = createMockNuxt({});
const { mockAddVitePlugin } = createMockAddVitePlugin();

Expand All @@ -126,7 +122,6 @@ describe('setupSourceMaps hooks', () => {

describe('vite plugin registration', () => {
it('calls `addVitePlugin` when setupSourceMaps is called', async () => {
const { setupSourceMaps } = await import('../../src/vite/sourceMaps');
const mockNuxt = createMockNuxt({ _prepare: false, dev: false });
const { mockAddVitePlugin, getCapturedPlugin } = createMockAddVitePlugin();

Expand All @@ -147,7 +142,6 @@ describe('setupSourceMaps hooks', () => {
nuxtOptions: { dev: true },
},
])('does not add plugins to vite config in $label', async ({ nuxtOptions }) => {
const { setupSourceMaps } = await import('../../src/vite/sourceMaps');
const mockNuxt = createMockNuxt(nuxtOptions);
const { mockAddVitePlugin } = createMockAddVitePlugin();

Expand All @@ -158,7 +152,6 @@ describe('setupSourceMaps hooks', () => {
});

it('does not add plugins when source maps are disabled via `sourcemaps.disable`', async () => {
const { setupSourceMaps } = await import('../../src/vite/sourceMaps');
const mockNuxt = createMockNuxt({});
const { mockAddVitePlugin } = createMockAddVitePlugin();

Expand All @@ -172,7 +165,6 @@ describe('setupSourceMaps hooks', () => {
{ label: 'server (SSR) build', buildConfig: { build: { ssr: true }, plugins: [] } },
{ label: 'client build', buildConfig: { build: { ssr: false }, plugins: [] } },
])('adds sentry vite plugin to vite config for $label in production', async () => {
const { setupSourceMaps } = await import('../../src/vite/sourceMaps');
const mockNuxt = createMockNuxt({ _prepare: false, dev: false });
const { mockAddVitePlugin, getCapturedPlugins } = createMockAddVitePlugin();

Expand All @@ -187,7 +179,6 @@ describe('setupSourceMaps hooks', () => {

describe('sentry vite plugin calls', () => {
it('calls sentryVitePlugin in production mode', async () => {
const { setupSourceMaps } = await import('../../src/vite/sourceMaps');
const mockNuxt = createMockNuxt({ _prepare: false, dev: false });
const { mockAddVitePlugin } = createMockAddVitePlugin();

Expand All @@ -200,7 +191,6 @@ describe('setupSourceMaps hooks', () => {
{ label: 'prepare mode', nuxtOptions: { _prepare: true }, viteMode: 'production' as const },
{ label: 'dev mode', nuxtOptions: { dev: true }, viteMode: 'development' as const },
])('does not call sentryVitePlugin in $label', async ({ nuxtOptions }) => {
const { setupSourceMaps } = await import('../../src/vite/sourceMaps');
const mockNuxt = createMockNuxt(nuxtOptions);
const { mockAddVitePlugin } = createMockAddVitePlugin();

Expand All @@ -212,7 +202,6 @@ describe('setupSourceMaps hooks', () => {

describe('shouldDeleteFilesFallback passed to getPluginOptions in Vite plugin', () => {
it('does not pass fallback deletion patterns to the Vite plugin', async () => {
const { setupSourceMaps } = await import('../../src/vite/sourceMaps');
const mockNuxt = createMockNuxt({
_prepare: false,
dev: false,
Expand Down Expand Up @@ -247,7 +236,6 @@ describe('setupSourceMaps hooks', () => {
});

it('sentryRollupPlugin is called without filesToDeleteAfterUpload when source maps are explicitly enabled', async () => {
const { setupSourceMaps } = await import('../../src/vite/sourceMaps');
const mockNuxt = createMockNuxt({
_prepare: false,
dev: false,
Expand All @@ -271,7 +259,6 @@ describe('setupSourceMaps hooks', () => {

describe('close hook', () => {
it('deletes source maps after the build using fallback patterns', async () => {
const { setupSourceMaps } = await import('../../src/vite/sourceMaps');
const mockNuxt = createMockNuxt({
_prepare: false,
dev: false,
Expand All @@ -293,7 +280,6 @@ describe('setupSourceMaps hooks', () => {
});

it('uses user-provided deletion patterns after the build', async () => {
const { setupSourceMaps } = await import('../../src/vite/sourceMaps');
const mockNuxt = createMockNuxt({
_prepare: false,
dev: false,
Expand All @@ -316,7 +302,6 @@ describe('setupSourceMaps hooks', () => {
});

it('does not create a manager when deletion is not configured', async () => {
const { setupSourceMaps } = await import('../../src/vite/sourceMaps');
const mockNuxt = createMockNuxt({
_prepare: false,
dev: false,
Expand All @@ -336,7 +321,6 @@ describe('setupSourceMaps hooks', () => {
{ label: 'prepare mode', nuxtOptions: { _prepare: true, dev: false } },
{ label: 'dev mode', nuxtOptions: { _prepare: false, dev: true } },
])('does not delete source maps in $label', async ({ nuxtOptions }) => {
const { setupSourceMaps } = await import('../../src/vite/sourceMaps');
const mockNuxt = createMockNuxt(nuxtOptions);
const { mockAddVitePlugin } = createMockAddVitePlugin();

Expand All @@ -353,7 +337,6 @@ describe('setupSourceMaps hooks', () => {

describe('nitro:config hook', () => {
it('adds sentryRollupPlugin to nitro rollup config in production mode', async () => {
const { setupSourceMaps } = await import('../../src/vite/sourceMaps');
const mockNuxt = createMockNuxt({ _prepare: false, dev: false });
const { mockAddVitePlugin } = createMockAddVitePlugin();

Expand All @@ -375,7 +358,6 @@ describe('setupSourceMaps hooks', () => {
},
{ label: 'dev mode', nuxtOptions: { dev: true }, nitroConfig: { rollupConfig: { plugins: [] }, dev: true } },
])('does not add sentryRollupPlugin to nitro rollup config in $label', async ({ nuxtOptions, nitroConfig }) => {
const { setupSourceMaps } = await import('../../src/vite/sourceMaps');
const mockNuxt = createMockNuxt(nuxtOptions);
const { mockAddVitePlugin } = createMockAddVitePlugin();

Expand All @@ -389,7 +371,6 @@ describe('setupSourceMaps hooks', () => {

describe('debug logging', () => {
it('logs a [Sentry] message in production mode', async () => {
const { setupSourceMaps } = await import('../../src/vite/sourceMaps');
const mockNuxt = createMockNuxt({ _prepare: false, dev: false });
const { mockAddVitePlugin, getCapturedPlugin } = createMockAddVitePlugin();

Expand All @@ -413,7 +394,6 @@ describe('setupSourceMaps hooks', () => {
});

it('does not log a [Sentry] messages in prepare mode', async () => {
const { setupSourceMaps } = await import('../../src/vite/sourceMaps');
const mockNuxt = createMockNuxt({ _prepare: true });
const { mockAddVitePlugin, getCapturedPlugin } = createMockAddVitePlugin();

Expand Down
8 changes: 0 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12559,14 +12559,6 @@ chalk@4.1.2, chalk@^4.0.0, chalk@^4.1.0, chalk@^4.1.1, chalk@^4.1.2:
ansi-styles "^4.1.0"
supports-color "^7.1.0"

chalk@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-3.0.0.tgz#3f73c2bf526591f574cc492c51e2456349f844e4"
integrity sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg==
dependencies:
ansi-styles "^4.1.0"
supports-color "^7.1.0"

chalk@^5.3.0, chalk@^5.6.2:
version "5.6.2"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-5.6.2.tgz#b1238b6e23ea337af71c7f8a295db5af0c158aea"
Expand Down
Loading