Browse Source

test(ui): Prevent importing from .spec files (#82584)

Scott Cooper 2 months ago
parent
commit
4172f7b514

+ 5 - 0
.eslintrc.js

@@ -546,6 +546,11 @@ const appRules = {
           group: ['sentry/components/devtoolbar/*'],
           message: 'Do not depend on toolbar internals',
         },
+        {
+          group: ['*.spec*'],
+          message:
+            'Do not import from test files. This causes tests to be executed multiple times.',
+        },
       ],
       paths: [
         {

+ 2 - 4
static/app/components/events/highlights/editHighlightsModal.spec.tsx

@@ -14,14 +14,12 @@ import {openModal} from 'sentry/actionCreators/modal';
 import EditHighlightsModal, {
   type EditHighlightsModalProps,
 } from 'sentry/components/events/highlights/editHighlightsModal';
-import {
-  TEST_EVENT_CONTEXTS,
-  TEST_EVENT_TAGS,
-} from 'sentry/components/events/highlights/util.spec';
 import ModalStore from 'sentry/stores/modalStore';
 import type {Project} from 'sentry/types/project';
 import * as analytics from 'sentry/utils/analytics';
 
+import {TEST_EVENT_CONTEXTS, TEST_EVENT_TAGS} from './testUtils';
+
 describe('EditHighlightsModal', function () {
   const organization = OrganizationFixture();
   const project = ProjectFixture();

+ 2 - 4
static/app/components/events/highlights/highlightsDataSection.spec.tsx

@@ -7,13 +7,11 @@ import {render, screen, userEvent, within} from 'sentry-test/reactTestingLibrary
 import * as modal from 'sentry/actionCreators/modal';
 import HighlightsDataSection from 'sentry/components/events/highlights/highlightsDataSection';
 import {EMPTY_HIGHLIGHT_DEFAULT} from 'sentry/components/events/highlights/util';
-import {
-  TEST_EVENT_CONTEXTS,
-  TEST_EVENT_TAGS,
-} from 'sentry/components/events/highlights/util.spec';
 import ProjectsStore from 'sentry/stores/projectsStore';
 import * as analytics from 'sentry/utils/analytics';
 
+import {TEST_EVENT_CONTEXTS, TEST_EVENT_TAGS} from './testUtils';
+
 describe('HighlightsDataSection', function () {
   const organization = OrganizationFixture();
   const project = ProjectFixture();

+ 2 - 4
static/app/components/events/highlights/highlightsIconSummary.spec.tsx

@@ -5,10 +5,8 @@ import {OrganizationFixture} from 'sentry-fixture/organization';
 import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
 
 import {HighlightsIconSummary} from 'sentry/components/events/highlights/highlightsIconSummary';
-import {
-  TEST_EVENT_CONTEXTS,
-  TEST_EVENT_TAGS,
-} from 'sentry/components/events/highlights/util.spec';
+
+import {TEST_EVENT_CONTEXTS, TEST_EVENT_TAGS} from './testUtils';
 
 jest.mock('sentry/components/events/contexts/contextIcon', () => ({
   ...jest.requireActual('sentry/components/events/contexts/contextIcon'),

+ 64 - 0
static/app/components/events/highlights/testUtils.tsx

@@ -0,0 +1,64 @@
+export const TEST_EVENT_CONTEXTS = {
+  keyboard: {
+    type: 'default',
+    brand: 'keychron',
+    percent: 75,
+    switches: {
+      form: 'tactile',
+      brand: 'wuque studios',
+    },
+  },
+  client_os: {
+    type: 'os',
+    name: 'Mac OS X',
+    version: '10.15',
+  },
+  runtime: {
+    type: 'runtime',
+    name: 'CPython',
+    version: '3.8.13',
+  },
+};
+
+export const TEST_EVENT_TAGS = [
+  {
+    key: 'browser',
+    value: 'Chrome 1.2.3',
+  },
+  {
+    key: 'browser.name',
+    value: 'Chrome',
+  },
+  {
+    key: 'device.family',
+    value: 'Mac',
+  },
+  {
+    key: 'environment',
+    value: 'production',
+  },
+  {
+    key: 'handled',
+    value: 'no',
+  },
+  {
+    key: 'level',
+    value: 'error',
+  },
+  {
+    key: 'release',
+    value: '1.8',
+  },
+  {
+    key: 'runtime',
+    value: 'CPython 3.8.13',
+  },
+  {
+    key: 'runtime.name',
+    value: 'CPython',
+  },
+  {
+    key: 'url',
+    value: 'https://example.com',
+  },
+];

+ 1 - 64
static/app/components/events/highlights/util.spec.tsx

@@ -9,70 +9,7 @@ import {
   getHighlightTagData,
 } from 'sentry/components/events/highlights/util';
 
-export const TEST_EVENT_CONTEXTS = {
-  keyboard: {
-    type: 'default',
-    brand: 'keychron',
-    percent: 75,
-    switches: {
-      form: 'tactile',
-      brand: 'wuque studios',
-    },
-  },
-  client_os: {
-    type: 'os',
-    name: 'Mac OS X',
-    version: '10.15',
-  },
-  runtime: {
-    type: 'runtime',
-    name: 'CPython',
-    version: '3.8.13',
-  },
-};
-
-export const TEST_EVENT_TAGS = [
-  {
-    key: 'browser',
-    value: 'Chrome 1.2.3',
-  },
-  {
-    key: 'browser.name',
-    value: 'Chrome',
-  },
-  {
-    key: 'device.family',
-    value: 'Mac',
-  },
-  {
-    key: 'environment',
-    value: 'production',
-  },
-  {
-    key: 'handled',
-    value: 'no',
-  },
-  {
-    key: 'level',
-    value: 'error',
-  },
-  {
-    key: 'release',
-    value: '1.8',
-  },
-  {
-    key: 'runtime',
-    value: 'CPython 3.8.13',
-  },
-  {
-    key: 'runtime.name',
-    value: 'CPython',
-  },
-  {
-    key: 'url',
-    value: 'https://example.com',
-  },
-];
+import {TEST_EVENT_CONTEXTS, TEST_EVENT_TAGS} from './testUtils';
 
 describe('getHighlightContextData', function () {
   it('returns only highlight context data', function () {

+ 1 - 38
static/app/utils/profiling/profile/continuousProfile.spec.tsx

@@ -1,44 +1,7 @@
-import merge from 'lodash/merge';
-
-import type {DeepPartial} from 'sentry/types/utils';
 import {ContinuousProfile} from 'sentry/utils/profiling/profile/continuousProfile';
 import {createContinuousProfileFrameIndex} from 'sentry/utils/profiling/profile/utils';
 
-import {makeTestingBoilerplate} from './profile.spec';
-
-export function makeSentryContinuousProfile(
-  profile?: DeepPartial<Profiling.SentryContinousProfileChunk>
-): Profiling.SentryContinousProfileChunk {
-  return merge(
-    {
-      chunk_id: 'chunk_id',
-      environment: '',
-      project_id: 0,
-      received: 0,
-      release: '',
-      organization_id: 0,
-      retention_days: 0,
-      version: '2',
-      platform: 'node',
-      profile: {
-        samples: [
-          {timestamp: Date.now() / 1e3, stack_id: 0, thread_id: '0'},
-          // 10ms later
-          {timestamp: Date.now() / 1e3 + 0.01, stack_id: 1, thread_id: '0'},
-        ],
-        frames: [
-          {function: 'foo', in_app: true},
-          {function: 'bar', in_app: true},
-        ],
-        stacks: [
-          [0, 1],
-          [0, 1],
-        ],
-      },
-    },
-    profile
-  ) as Profiling.SentryContinousProfileChunk;
-}
+import {makeSentryContinuousProfile, makeTestingBoilerplate} from './testUtils';
 
 describe('ContinuousProfile', () => {
   it('imports the base properties', () => {

+ 1 - 1
static/app/utils/profiling/profile/eventedProfile.spec.tsx

@@ -3,7 +3,7 @@ import {createFrameIndex} from 'sentry/utils/profiling/profile/utils';
 
 import {Frame} from '../frame';
 
-import {firstCallee, makeTestingBoilerplate} from './profile.spec';
+import {firstCallee, makeTestingBoilerplate} from './testUtils';
 
 describe('EventedProfile', () => {
   it('imports the base properties', () => {

+ 1 - 2
static/app/utils/profiling/profile/importProfile.spec.tsx

@@ -7,9 +7,8 @@ import {
 import {JSSelfProfile} from 'sentry/utils/profiling/profile/jsSelfProfile';
 import {SampledProfile} from 'sentry/utils/profiling/profile/sampledProfile';
 
-import {makeSentryContinuousProfile} from './continuousProfile.spec';
 import {SentrySampledProfile} from './sentrySampledProfile';
-import {makeSentrySampledProfile} from './sentrySampledProfile.spec';
+import {makeSentryContinuousProfile, makeSentrySampledProfile} from './testUtils';
 
 describe('importProfile', () => {
   it('imports evented profile', () => {

+ 1 - 1
static/app/utils/profiling/profile/jsSelfProfile.spec.tsx

@@ -1,7 +1,7 @@
 import {JSSelfProfile} from 'sentry/utils/profiling/profile/jsSelfProfile';
 import {createFrameIndex} from 'sentry/utils/profiling/profile/utils';
 
-import {firstCallee, makeTestingBoilerplate, nthCallee} from './profile.spec';
+import {firstCallee, makeTestingBoilerplate, nthCallee} from './testUtils';
 
 describe('jsSelfProfile', () => {
   it('imports the base properties', () => {

Some files were not shown because too many files changed in this diff