Skip to content

test(astro): Switch to explicit vitest imports #13093

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 30, 2024
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
15 changes: 8 additions & 7 deletions packages/astro/test/client/sdk.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { afterEach, describe, expect, it, vi } from 'vitest';

import type { BrowserClient } from '@sentry/browser';
import {
browserTracingIntegration,
Expand All @@ -8,9 +10,8 @@ import {
} from '@sentry/browser';
import * as SentryBrowser from '@sentry/browser';
import { SDK_VERSION, getClient } from '@sentry/browser';
import { vi } from 'vitest';

import { init } from '../../../astro/src/client/sdk';
import { init } from '../../src/client/sdk';

const browserInit = vi.spyOn(SentryBrowser, 'init');

Expand Down Expand Up @@ -66,7 +67,7 @@ describe('Sentry client SDK', () => {
...tracingOptions,
});

const integrationsToInit = browserInit.mock.calls[0][0]?.defaultIntegrations;
const integrationsToInit = browserInit.mock.calls[0]![0]?.defaultIntegrations;
const browserTracing = getClient<BrowserClient>()?.getIntegrationByName('BrowserTracing');

expect(integrationsToInit).toContainEqual(expect.objectContaining({ name: 'BrowserTracing' }));
Expand All @@ -82,28 +83,28 @@ describe('Sentry client SDK', () => {
...tracingOptions,
});

const integrationsToInit = browserInit.mock.calls[0][0]?.defaultIntegrations || [];
const integrationsToInit = browserInit.mock.calls[0]![0]?.defaultIntegrations || [];
const browserTracing = getClient<BrowserClient>()?.getIntegrationByName('BrowserTracing');

expect(integrationsToInit).not.toContainEqual(expect.objectContaining({ name: 'BrowserTracing' }));
expect(browserTracing).toBeUndefined();
});

it("doesn't add browserTracingIntegration if `__SENTRY_TRACING__` is set to false", () => {
globalThis.__SENTRY_TRACING__ = false;
(globalThis as any).__SENTRY_TRACING__ = false;

init({
dsn: 'https://[email protected]/1337',
enableTracing: true,
});

const integrationsToInit = browserInit.mock.calls[0][0]?.defaultIntegrations || [];
const integrationsToInit = browserInit.mock.calls[0]![0]?.defaultIntegrations || [];
const browserTracing = getClient<BrowserClient>()?.getIntegrationByName('BrowserTracing');

expect(integrationsToInit).not.toContainEqual(expect.objectContaining({ name: 'BrowserTracing' }));
expect(browserTracing).toBeUndefined();

delete globalThis.__SENTRY_TRACING__;
delete (globalThis as any).__SENTRY_TRACING__;
});

it('Overrides the automatically default browserTracingIntegration instance with a a user-provided browserTracingIntegration instance', () => {
Expand Down
8 changes: 3 additions & 5 deletions packages/astro/test/integration/index.files.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { vi } from 'vitest';
import { afterEach, describe, expect, it, vi } from 'vitest';

import { sentryAstro } from '../../src/integration';

vi.mock('fs', async () => {
const actual = await vi.importActual('fs');
vi.mock('fs', async requireActual => {
return {
// @ts-expect-error - just mocking around
...actual,
...(await requireActual<any>()),
existsSync: vi.fn(p => p.endsWith('js')),
};
});
Expand Down
4 changes: 2 additions & 2 deletions packages/astro/test/integration/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { vi } from 'vitest';
import { afterEach, describe, expect, it, vi } from 'vitest';

import { sentryAstro } from '../../src/integration';

Expand Down Expand Up @@ -294,7 +294,7 @@ describe('sentryAstro integration', () => {

it.each([{ output: 'static' }, { output: undefined }])(
"doesn't add middleware if in static mode (config %s)",
async config => {
async (config: any) => {
const integration = sentryAstro({});
const addMiddleware = vi.fn();
const updateConfig = vi.fn();
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/test/integration/middleware/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { vi } from 'vitest';
import { describe, expect, it, vi } from 'vitest';

import { onRequest } from '../../../src/integration/middleware';

Expand Down
2 changes: 2 additions & 0 deletions packages/astro/test/integration/snippets.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, expect, it } from 'vitest';

import { buildClientSnippet, buildSdkInitFileImportSnippet, buildServerSnippet } from '../../src/integration/snippets';

const allSdkOptions = {
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/tsconfig.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@

"compilerOptions": {
// should include all types from `./tsconfig.json` plus types for all test frameworks used
"types": ["node", "vitest/globals"]
"types": ["node"]
}
}
1 change: 0 additions & 1 deletion packages/astro/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ export default {
...baseConfig,
test: {
...baseConfig.test,
environment: 'jsdom',
},
};
Loading