diff --git a/package.json b/package.json index feb5be7839d0..36bb6500c23a 100644 --- a/package.json +++ b/package.json @@ -25,9 +25,9 @@ "lint:eslint": "lerna run lint:eslint", "validate:es5": "lerna run validate:es5", "postpublish": "lerna run --stream --concurrency 1 postpublish", - "test": "lerna run --ignore @sentry-internal/* test", - "test:unit": "lerna run --ignore @sentry-internal/* test:unit", - "test-ci-browser": "lerna run test --ignore \"@sentry/{node,opentelemetry-node,serverless,nextjs,remix,gatsby,sveltekit}\" --ignore @sentry-internal/*", + "test": "lerna run --ignore \"@sentry-internal/{browser-integration-tests,e2e-tests,integration-shims,node-integration-tests,overhead-metrics}\" test", + "test:unit": "lerna run --ignore \"@sentry-internal/{browser-integration-tests,e2e-tests,integration-shims,node-integration-tests,overhead-metrics}\" test:unit", + "test-ci-browser": "lerna run test --ignore \"@sentry/{node,opentelemetry-node,serverless,nextjs,remix,gatsby,sveltekit}\" --ignore \"@sentry-internal/{browser-integration-tests,e2e-tests,integration-shims,node-integration-tests,overhead-metrics}\"", "test-ci-node": "ts-node ./scripts/node-unit-tests.ts", "test:update-snapshots": "lerna run test:update-snapshots", "yalc:publish": "lerna run yalc:publish" diff --git a/packages/tracing-internal/test/browser/backgroundtab.test.ts b/packages/tracing-internal/test/browser/backgroundtab.test.ts index 436d63aab36c..5ce370e6690f 100644 --- a/packages/tracing-internal/test/browser/backgroundtab.test.ts +++ b/packages/tracing-internal/test/browser/backgroundtab.test.ts @@ -2,11 +2,11 @@ import { Hub, makeMain } from '@sentry/core'; import { JSDOM } from 'jsdom'; import { addExtensionMethods } from '../../../tracing/src'; -import { getDefaultBrowserClientOptions } from '../../../tracing/test/testutils'; +import { conditionalTest, getDefaultBrowserClientOptions } from '../../../tracing/test/testutils'; import { registerBackgroundTabDetection } from '../../src/browser/backgroundtab'; import { TestClient } from '../utils/TestClient'; -describe('registerBackgroundTabDetection', () => { +conditionalTest({ min: 10 })('registerBackgroundTabDetection', () => { let events: Record = {}; let hub: Hub; beforeEach(() => { diff --git a/packages/tracing-internal/test/browser/browsertracing.test.ts b/packages/tracing-internal/test/browser/browsertracing.test.ts index 156203dc40e0..fa5e575e8ada 100644 --- a/packages/tracing-internal/test/browser/browsertracing.test.ts +++ b/packages/tracing-internal/test/browser/browsertracing.test.ts @@ -7,7 +7,7 @@ import { JSDOM } from 'jsdom'; import type { IdleTransaction } from '../../../tracing/src'; import { getActiveTransaction } from '../../../tracing/src'; -import { getDefaultBrowserClientOptions } from '../../../tracing/test/testutils'; +import { conditionalTest, getDefaultBrowserClientOptions } from '../../../tracing/test/testutils'; import type { BrowserTracingOptions } from '../../src/browser/browsertracing'; import { BrowserTracing, getMetaContent } from '../../src/browser/browsertracing'; import { defaultRequestInstrumentationOptions } from '../../src/browser/request'; @@ -58,7 +58,7 @@ beforeAll(() => { WINDOW.location = dom.window.location; }); -describe('BrowserTracing', () => { +conditionalTest({ min: 10 })('BrowserTracing', () => { let hub: Hub; beforeEach(() => { jest.useFakeTimers(); diff --git a/packages/tracing-internal/test/browser/router.test.ts b/packages/tracing-internal/test/browser/router.test.ts index cfa2179386d9..8ad414a97b80 100644 --- a/packages/tracing-internal/test/browser/router.test.ts +++ b/packages/tracing-internal/test/browser/router.test.ts @@ -1,6 +1,7 @@ import type { InstrumentHandlerCallback, InstrumentHandlerType } from '@sentry/utils'; import { JSDOM } from 'jsdom'; +import { conditionalTest } from '../../../tracing/test/testutils'; import { instrumentRoutingWithDefaults } from '../../src/browser/router'; let mockChangeHistory: ({ to, from }: { to: string; from?: string }) => void = () => undefined; @@ -16,7 +17,7 @@ jest.mock('@sentry/utils', () => { }; }); -describe('instrumentRoutingWithDefaults', () => { +conditionalTest({ min: 16 })('instrumentRoutingWithDefaults', () => { const mockFinish = jest.fn(); const customStartTransaction = jest.fn().mockReturnValue({ finish: mockFinish }); beforeEach(() => { diff --git a/packages/tracing/test/testutils.ts b/packages/tracing/test/testutils.ts index 071ecdf5111a..484e3bf3cc35 100644 --- a/packages/tracing/test/testutils.ts +++ b/packages/tracing/test/testutils.ts @@ -1,6 +1,6 @@ import { createTransport } from '@sentry/browser'; import type { Client, ClientOptions } from '@sentry/types'; -import { GLOBAL_OBJ, resolvedSyncPromise } from '@sentry/utils'; +import { GLOBAL_OBJ, parseSemver, resolvedSyncPromise } from '@sentry/utils'; import { JSDOM } from 'jsdom'; /** @@ -58,6 +58,23 @@ export const testOnlyIfNodeVersionAtLeast = (minVersion: number): jest.It => { return it; }; +/** + * Returns`describe` or `describe.skip` depending on allowed major versions of Node. + * + * @param {{ min?: number; max?: number }} allowedVersion + * @return {*} {jest.Describe} + */ +export const conditionalTest = (allowedVersion: { min?: number; max?: number }): jest.Describe => { + const NODE_VERSION = parseSemver(process.versions.node).major; + if (!NODE_VERSION) { + return describe.skip; + } + + return NODE_VERSION < (allowedVersion.min || -Infinity) || NODE_VERSION > (allowedVersion.max || Infinity) + ? describe.skip + : describe; +}; + export function getDefaultBrowserClientOptions(options: Partial = {}): ClientOptions { return { integrations: [], diff --git a/scripts/node-unit-tests.ts b/scripts/node-unit-tests.ts index e5efc7c2ebd3..c32fa6376d38 100644 --- a/scripts/node-unit-tests.ts +++ b/scripts/node-unit-tests.ts @@ -22,6 +22,7 @@ const NODE_8_SKIP_TESTS_PACKAGES = [ '@sentry/nextjs', '@sentry/remix', '@sentry/sveltekit', + '@sentry-internal/replay-worker', ]; // We have to downgrade some of our dependencies in order to run tests in Node 8 and 10. @@ -34,7 +35,7 @@ const NODE_8_LEGACY_DEPENDENCIES = [ 'lerna@3.13.4', ]; -const NODE_10_SKIP_TESTS_PACKAGES = ['@sentry/remix', '@sentry/sveltekit']; +const NODE_10_SKIP_TESTS_PACKAGES = ['@sentry/remix', '@sentry/sveltekit', '@sentry-internal/replay-worker']; const NODE_10_LEGACY_DEPENDENCIES = ['jsdom@16.x', 'lerna@3.13.4']; const NODE_12_SKIP_TESTS_PACKAGES = ['@sentry/remix', '@sentry/sveltekit'];