Skip to content

Commit 16a29c0

Browse files
authored
chore: Make sure we run sentry-internal unit tests (#8431)
Building on top of #8430, this PR makes a quick fix to make sure we are running unit tests for `@sentry-internal/eslint-plugin`, `@sentry-internal/tracing`, and `@sentry-internal/replay-worker`. This was found not to be running before because we had a blanket `--ignore @sentry-internal/*` when making lerna run tests.
1 parent 9006287 commit 16a29c0

File tree

6 files changed

+29
-10
lines changed

6 files changed

+29
-10
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
"lint:eslint": "lerna run lint:eslint",
2626
"validate:es5": "lerna run validate:es5",
2727
"postpublish": "lerna run --stream --concurrency 1 postpublish",
28-
"test": "lerna run --ignore @sentry-internal/* test",
29-
"test:unit": "lerna run --ignore @sentry-internal/* test:unit",
30-
"test-ci-browser": "lerna run test --ignore \"@sentry/{node,opentelemetry-node,serverless,nextjs,remix,gatsby,sveltekit}\" --ignore @sentry-internal/*",
28+
"test": "lerna run --ignore \"@sentry-internal/{browser-integration-tests,e2e-tests,integration-shims,node-integration-tests,overhead-metrics}\" test",
29+
"test:unit": "lerna run --ignore \"@sentry-internal/{browser-integration-tests,e2e-tests,integration-shims,node-integration-tests,overhead-metrics}\" test:unit",
30+
"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}\"",
3131
"test-ci-node": "ts-node ./scripts/node-unit-tests.ts",
3232
"test:update-snapshots": "lerna run test:update-snapshots",
3333
"yalc:publish": "lerna run yalc:publish"

packages/tracing-internal/test/browser/backgroundtab.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { Hub, makeMain } from '@sentry/core';
22
import { JSDOM } from 'jsdom';
33

44
import { addExtensionMethods } from '../../../tracing/src';
5-
import { getDefaultBrowserClientOptions } from '../../../tracing/test/testutils';
5+
import { conditionalTest, getDefaultBrowserClientOptions } from '../../../tracing/test/testutils';
66
import { registerBackgroundTabDetection } from '../../src/browser/backgroundtab';
77
import { TestClient } from '../utils/TestClient';
88

9-
describe('registerBackgroundTabDetection', () => {
9+
conditionalTest({ min: 10 })('registerBackgroundTabDetection', () => {
1010
let events: Record<string, any> = {};
1111
let hub: Hub;
1212
beforeEach(() => {

packages/tracing-internal/test/browser/browsertracing.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { JSDOM } from 'jsdom';
77

88
import type { IdleTransaction } from '../../../tracing/src';
99
import { getActiveTransaction } from '../../../tracing/src';
10-
import { getDefaultBrowserClientOptions } from '../../../tracing/test/testutils';
10+
import { conditionalTest, getDefaultBrowserClientOptions } from '../../../tracing/test/testutils';
1111
import type { BrowserTracingOptions } from '../../src/browser/browsertracing';
1212
import { BrowserTracing, getMetaContent } from '../../src/browser/browsertracing';
1313
import { defaultRequestInstrumentationOptions } from '../../src/browser/request';
@@ -58,7 +58,7 @@ beforeAll(() => {
5858
WINDOW.location = dom.window.location;
5959
});
6060

61-
describe('BrowserTracing', () => {
61+
conditionalTest({ min: 10 })('BrowserTracing', () => {
6262
let hub: Hub;
6363
beforeEach(() => {
6464
jest.useFakeTimers();

packages/tracing-internal/test/browser/router.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { InstrumentHandlerCallback, InstrumentHandlerType } from '@sentry/utils';
22
import { JSDOM } from 'jsdom';
33

4+
import { conditionalTest } from '../../../tracing/test/testutils';
45
import { instrumentRoutingWithDefaults } from '../../src/browser/router';
56

67
let mockChangeHistory: ({ to, from }: { to: string; from?: string }) => void = () => undefined;
@@ -16,7 +17,7 @@ jest.mock('@sentry/utils', () => {
1617
};
1718
});
1819

19-
describe('instrumentRoutingWithDefaults', () => {
20+
conditionalTest({ min: 16 })('instrumentRoutingWithDefaults', () => {
2021
const mockFinish = jest.fn();
2122
const customStartTransaction = jest.fn().mockReturnValue({ finish: mockFinish });
2223
beforeEach(() => {

packages/tracing/test/testutils.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createTransport } from '@sentry/browser';
22
import type { Client, ClientOptions } from '@sentry/types';
3-
import { GLOBAL_OBJ, resolvedSyncPromise } from '@sentry/utils';
3+
import { GLOBAL_OBJ, parseSemver, resolvedSyncPromise } from '@sentry/utils';
44
import { JSDOM } from 'jsdom';
55

66
/**
@@ -58,6 +58,23 @@ export const testOnlyIfNodeVersionAtLeast = (minVersion: number): jest.It => {
5858
return it;
5959
};
6060

61+
/**
62+
* Returns`describe` or `describe.skip` depending on allowed major versions of Node.
63+
*
64+
* @param {{ min?: number; max?: number }} allowedVersion
65+
* @return {*} {jest.Describe}
66+
*/
67+
export const conditionalTest = (allowedVersion: { min?: number; max?: number }): jest.Describe => {
68+
const NODE_VERSION = parseSemver(process.versions.node).major;
69+
if (!NODE_VERSION) {
70+
return describe.skip;
71+
}
72+
73+
return NODE_VERSION < (allowedVersion.min || -Infinity) || NODE_VERSION > (allowedVersion.max || Infinity)
74+
? describe.skip
75+
: describe;
76+
};
77+
6178
export function getDefaultBrowserClientOptions(options: Partial<ClientOptions> = {}): ClientOptions {
6279
return {
6380
integrations: [],

scripts/node-unit-tests.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const NODE_8_SKIP_TESTS_PACKAGES = [
2222
'@sentry/nextjs',
2323
'@sentry/remix',
2424
'@sentry/sveltekit',
25+
'@sentry-internal/replay-worker',
2526
];
2627

2728
// 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 = [
3435
3536
];
3637

37-
const NODE_10_SKIP_TESTS_PACKAGES = ['@sentry/remix', '@sentry/sveltekit'];
38+
const NODE_10_SKIP_TESTS_PACKAGES = ['@sentry/remix', '@sentry/sveltekit', '@sentry-internal/replay-worker'];
3839
const NODE_10_LEGACY_DEPENDENCIES = ['[email protected]', '[email protected]'];
3940

4041
const NODE_12_SKIP_TESTS_PACKAGES = ['@sentry/remix', '@sentry/sveltekit'];

0 commit comments

Comments
 (0)