Skip to content

Commit

Permalink
lint rule to prevent imports in cypress
Browse files Browse the repository at this point in the history
  • Loading branch information
rsun19 committed Jul 3, 2024
1 parent 3d27281 commit aaa6bf3
Show file tree
Hide file tree
Showing 43 changed files with 134 additions and 88 deletions.
26 changes: 26 additions & 0 deletions frontend/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,32 @@
"rules": {
"no-restricted-imports": "off"
}
},
{
"files": ["src/__tests__/cypress/**"],
"rules": {
"@typescript-eslint/consistent-type-imports": "error",
"no-restricted-syntax": [
"error",
{
"selector":"ImportDeclaration[importKind!='type'][source.value=/^~\\u002F(?!(__tests__|__mocks__|.*(types|Types|getCorePipelineSpec|utils)).*)/]",
"message": "Must use 'import type' when importing. If you are importing enums that are flagged, please go to the .eslintrc file and add it to the regular expression."
}
],
"no-restricted-imports": [
"error",
{
"patterns": [
{
"group": [
"@patternfly/**"
],
"message": "Cypress tests should only import mocks and types from outside the Cypress test directory."
}
]
}
]
}
}
]
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ByRoleOptions } from '@testing-library/react';
import type { ByRoleOptions } from '@testing-library/react';
import { Modal } from '~/__tests__/cypress/cypress/pages/components/Modal';

export class DeleteModal extends Modal {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ByRoleOptions } from '@testing-library/react';
import type { ByRoleOptions } from '@testing-library/react';

export class Modal {
constructor(private title: ByRoleOptions['name']) {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { appChrome } from '~/__tests__/cypress/cypress/pages/appChrome';
import { RefreshIntervalTitle } from '~/concepts/metrics/types';
import type { RefreshIntervalTitle } from '~/concepts/metrics/types';

class GlobalDistributedWorkloads {
visit(wait = true) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
import {
modelVersionArchiveDetailsUrl,
modelVersionArchiveUrl,
modelVersionListUrl,
modelVersionUrl,
} from '~/pages/modelRegistry/screens/routeUtils';
import { TableRow } from '~/__tests__/cypress/cypress/pages/components/table';
import { Modal } from '~/__tests__/cypress/cypress/pages/components/Modal';

Expand Down Expand Up @@ -61,21 +55,37 @@ class ModelVersionArchive {
}

visit() {
cy.visitWithLogin(modelVersionArchiveUrl('1', 'modelregistry-sample'));
const rmId = '1';
const preferredModelRegistry = 'modelregistry-sample';
cy.visitWithLogin(
`/modelRegistry/${preferredModelRegistry}/registeredModels/${rmId}/versions/archive`,
);
this.wait();
}

visitArchiveVersionDetail() {
cy.visitWithLogin(modelVersionArchiveDetailsUrl('2', '1', 'modelregistry-sample'));
const mvId = '2';
const rmId = '1';
const preferredModelRegistry = 'modelregistry-sample';
cy.visitWithLogin(
`/modelRegistry/${preferredModelRegistry}/registeredModels/${rmId}/versions/archive/${mvId}`,
);
}

visitModelVersionList() {
cy.visitWithLogin(modelVersionListUrl('1', 'modelregistry-sample'));
const rmId = '1';
const preferredModelRegistry = 'modelregistry-sample';
cy.visitWithLogin(`/modelRegistry/${preferredModelRegistry}/registeredModels/${rmId}/versions`);
this.wait();
}

visitModelVersionDetails() {
cy.visitWithLogin(modelVersionUrl('3', '1', 'modelregistry-sample'));
const mvId = '3';
const rmId = '1';
const preferredModelRegistry = 'modelregistry-sample';
cy.visitWithLogin(
`/modelRegistry/${preferredModelRegistry}/registeredModels/${rmId}/versions/${mvId}`,
);
this.wait();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { modelVersionUrl } from '~/pages/modelRegistry/screens/routeUtils';

class ModelVersionDetails {
visit() {
cy.visitWithLogin(modelVersionUrl('1', '1', 'modelregistry-sample'));
const preferredModelRegistry = 'modelregistry-sample';
const rmId = '1';
const mvId = '1';
cy.visitWithLogin(
`/modelRegistry/${preferredModelRegistry}/registeredModels/${rmId}/versions/${mvId}`,
);
this.wait();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import {
registeredModelArchiveDetailsUrl,
registeredModelArchiveUrl,
registeredModelUrl,
} from '~/pages/modelRegistry/screens/routeUtils';
import { TableRow } from '~/__tests__/cypress/cypress/pages/components/table';
import { Modal } from '~/__tests__/cypress/cypress/pages/components/Modal';

Expand Down Expand Up @@ -60,12 +55,15 @@ class ModelArchive {
}

visit() {
cy.visit(registeredModelArchiveUrl('modelregistry-sample'));
const preferredModelRegistry = 'modelregistry-sample';
cy.visit(`/modelRegistry/${preferredModelRegistry}/registeredModels/archive`);
this.wait();
}

visitArchiveModelDetail() {
cy.visit(registeredModelArchiveDetailsUrl('2', 'modelregistry-sample'));
const rmId = '2';
const preferredModelRegistry = 'modelregistry-sample';
cy.visit(`/modelRegistry/${preferredModelRegistry}/registeredModels/archive/${rmId}`);
}

visitModelList() {
Expand All @@ -74,7 +72,9 @@ class ModelArchive {
}

visitModelDetails() {
cy.visit(registeredModelUrl('2', 'modelregistry-sample'));
const rmId = '2';
const preferredModelRegistry = 'modelregistry-sample';
cy.visit(`/modelRegistry/${preferredModelRegistry}/registeredModels/${rmId}`);
this.wait();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {
import type {
ExperimentKFv2,
PipelineKFv2,
PipelineRunJobKFv2,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable camelcase */
import {
import type {
ExperimentKFv2,
PipelineKFv2,
PipelineRunJobKFv2,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable camelcase */

import { ExperimentKFv2 } from '~/concepts/pipelines/kfTypes';
import type { ExperimentKFv2 } from '~/concepts/pipelines/kfTypes';
import { TableRow } from '~/__tests__/cypress/cypress/pages/components/table';

class ExperimentsTabs {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ExperimentKFv2 } from '~/concepts/pipelines/kfTypes';
import type { ExperimentKFv2 } from '~/concepts/pipelines/kfTypes';

class PipelineFilterBar {
find() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CreatePipelineAndVersionKFData, PipelineKFv2 } from '~/concepts/pipelines/kfTypes';
import type { CreatePipelineAndVersionKFData, PipelineKFv2 } from '~/concepts/pipelines/kfTypes';
import { buildMockPipelineV2 } from '~/__mocks__/mockPipelinesProxy';
import { Modal } from '~/__tests__/cypress/cypress/pages/components/Modal';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable camelcase */
import { PipelineRunJobKFv2, PipelineRunKFv2 } from '~/concepts/pipelines/kfTypes';
import type { PipelineRunJobKFv2, PipelineRunKFv2 } from '~/concepts/pipelines/kfTypes';
import { TableRow } from '~/__tests__/cypress/cypress/pages/components/table';

class PipelineRunsRow extends TableRow {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { PipelineRunSearchParam } from '~/concepts/pipelines/content/types';
import { DeleteModal } from '~/__tests__/cypress/cypress/pages/components/DeleteModal';

class PipelineRunsGlobal {
Expand All @@ -10,7 +9,7 @@ class PipelineRunsGlobal {
) {
cy.visitWithLogin(
`/pipelines/${projectName}/pipeline/runs/${pipelineId}/${versionId}${
runType ? `?${PipelineRunSearchParam.RunType}=${runType}` : ''
runType ? `?runType=${runType}` : ''
}`,
);
this.wait();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { CreatePipelineVersionKFData, PipelineVersionKFv2 } from '~/concepts/pipelines/kfTypes';
import type {
CreatePipelineVersionKFData,
PipelineVersionKFv2,
} from '~/concepts/pipelines/kfTypes';
import { buildMockPipelineVersionV2 } from '~/__mocks__/mockPipelineVersionsProxy';
import { Modal } from '~/__tests__/cypress/cypress/pages/components/Modal';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable camelcase */
import { PipelineKFv2, PipelineVersionKFv2 } from '~/concepts/pipelines/kfTypes';
import type { PipelineKFv2, PipelineVersionKFv2 } from '~/concepts/pipelines/kfTypes';
import { buildMockPipelines } from '~/__mocks__/mockPipelinesProxy';
import { buildMockPipelineVersionsV2 } from '~/__mocks__/mockPipelineVersionsProxy';
import { TableRow } from '~/__tests__/cypress/cypress/pages/components/table';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { appChrome } from '~/__tests__/cypress/cypress/pages/appChrome';
import { ServingRuntimeAPIProtocol } from '~/types';
import type { ServingRuntimeAPIProtocol } from '~/types';
import { DashboardCodeEditor } from './components/DashboardCodeEditor';

class ServingRuntimeRow {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MatcherOptions } from '@testing-library/cypress';
import { Matcher, MatcherOptions as DTLMatcherOptions } from '@testing-library/dom';
import type { MatcherOptions } from '@testing-library/cypress';
import type { Matcher, MatcherOptions as DTLMatcherOptions } from '@testing-library/dom';
/* eslint-disable @typescript-eslint/no-namespace */
declare global {
namespace Cypress {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Interception } from 'cypress/types/net-stubbing';
import { InterceptSnapshot, Snapshot } from '~/__tests__/cypress/cypress/types';
import type { Interception } from 'cypress/types/net-stubbing';
import type { InterceptSnapshot, Snapshot } from '~/__tests__/cypress/cypress/types';
import { interceptSnapshot, waitSnapshot } from '~/__tests__/cypress/cypress/utils/snapshotUtils';

/* eslint-disable @typescript-eslint/no-namespace */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import type {
K8sStatus,
Patch,
} from '@openshift/dynamic-plugin-sdk-utils';
import {
import type {
GenericStaticResponse,
RouteHandlerController,
RouteMatcherOptions,
} from 'cypress/types/net-stubbing';
import type { QueryOptions } from '~/__tests__/cypress/cypress/utils/k8s';
import {
getK8sAPIResourceURL,
getK8sWebSocketResourceURL,
QueryOptions,
} from '~/__tests__/cypress/cypress/utils/k8s';

type WsOptions = {
Expand Down
21 changes: 13 additions & 8 deletions frontend/src/__tests__/cypress/cypress/support/commands/odh.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { K8sResourceListResult } from '@openshift/dynamic-plugin-sdk-utils';
import type { K8sResourceListResult } from '@openshift/dynamic-plugin-sdk-utils';
import type { GenericStaticResponse, RouteHandlerController } from 'cypress/types/net-stubbing';
import { BaseMetricCreationResponse, BaseMetricListResponse } from '~/api';
import {
import type { BaseMetricCreationResponse, BaseMetricListResponse } from '~/api';
import type {
ModelArtifactList,
ModelVersion,
ModelVersionList,
Expand All @@ -20,9 +20,9 @@ import type {
ModelRegistryKind,
} from '~/k8sTypes';

import { StartNotebookData } from '~/pages/projects/types';
import { AllowedUser } from '~/pages/notebookController/screens/admin/types';
import { GroupsConfig } from '~/pages/groupSettings/groupTypes';
import type { StartNotebookData } from '~/pages/projects/types';
import type { AllowedUser } from '~/pages/notebookController/screens/admin/types';
import type { GroupsConfig } from '~/pages/groupSettings/groupTypes';
import type { StatusResponse } from '~/redux/types';
import type {
BYONImage,
Expand All @@ -33,7 +33,7 @@ import type {
PrometheusQueryRangeResponse,
PrometheusQueryResponse,
} from '~/types';
import {
import type {
ExperimentKFv2,
GoogleRpcStatusKF,
ListExperimentsResponseKF,
Expand All @@ -46,7 +46,7 @@ import {
PipelineRunKFv2,
PipelineVersionKFv2,
} from '~/concepts/pipelines/kfTypes';
import { GrpcResponse } from '~/__mocks__/mlmd/utils';
import type { GrpcResponse } from '~/__mocks__/mlmd/utils';

type SuccessErrorResponse = {
success: boolean;
Expand Down Expand Up @@ -298,6 +298,11 @@ declare global {
options: { path: { serviceName: string; apiVersion: string; registeredModelId: number } },
response: OdhResponse<RegisteredModel>,
) => Cypress.Chainable<null>) &
((
type: 'PATCH /api/service/modelregistry/:serviceName/api/model_registry/:apiVersion/registered_models/:registeredModelId',
options: { path: { serviceName: string; apiVersion: string; registeredModelId: number } },
response: OdhResponse<RegisteredModel>,
) => Cypress.Chainable<null>) &
((
type: 'GET /api/service/modelregistry/:serviceName/api/model_registry/:apiVersion/model_versions/:modelVersionId',
options: {
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/__tests__/cypress/cypress/support/websockets.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import WebSocket, { WebSocketServer } from 'ws';
import type WebSocket from 'ws';
import { WebSocketServer } from 'ws';

/* eslint-disable @typescript-eslint/no-namespace */
declare global {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { mockRoleBindingK8sResource } from '~/__mocks__/mockRoleBindingK8sResource';
import { mockK8sResourceList } from '~/__mocks__';
import { RoleBindingSubject } from '~/types';
import type { RoleBindingSubject } from '~/types';
import { mockAllowedUsers } from '~/__mocks__/mockAllowedUsers';
import { mockNotebookImageInfo } from '~/__mocks__/mockNotebookImageInfo';
import {
Expand All @@ -9,7 +9,7 @@ import {
} from '~/__tests__/cypress/cypress/pages/administration';
import { be } from '~/__tests__/cypress/cypress/utils/should';
import { asProductAdminUser, asProjectEditUser } from '~/__tests__/cypress/cypress/utils/users';
import { AllowedUser } from '~/pages/notebookController/screens/admin/types';
import type { AllowedUser } from '~/pages/notebookController/screens/admin/types';
import { testPagination } from '~/__tests__/cypress/cypress/utils/pagination';

const groupSubjects: RoleBindingSubject[] = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RoleBindingSubject } from '~/types';
import type { RoleBindingSubject } from '~/types';
import { mockComponents } from '~/__mocks__/mockComponents';
import { enabledPage } from '~/__tests__/cypress/cypress/pages/enabled';
import { jupyterCard } from '~/__tests__/cypress/cypress/pages/components/JupyterCard';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { mockRoleBindingK8sResource } from '~/__mocks__/mockRoleBindingK8sResource';
import { mockK8sResourceList, mockNotebookK8sResource } from '~/__mocks__';
import { RoleBindingSubject } from '~/types';
import type { RoleBindingSubject } from '~/types';
import { mockAllowedUsers } from '~/__mocks__/mockAllowedUsers';
import { mockNotebookImageInfo } from '~/__mocks__/mockNotebookImageInfo';
import { mockStartNotebookData } from '~/__mocks__/mockStartNotebookData';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,9 @@ import { mockK8sResourceList } from '~/__mocks__/mockK8sResourceList';
import { mockProjectK8sResource } from '~/__mocks__/mockProjectK8sResource';
import { mockDWUsageByOwnerPrometheusResponse } from '~/__mocks__/mockDWUsageByOwnerPrometheusResponse';
import { mockWorkloadK8sResource } from '~/__mocks__/mockWorkloadK8sResource';
import {
ClusterQueueKind,
LocalQueueKind,
WorkloadKind,
WorkloadPodSet,
WorkloadOwnerType,
} from '~/k8sTypes';
import { PodContainer } from '~/types';
import type { ClusterQueueKind, LocalQueueKind, WorkloadKind, WorkloadPodSet } from '~/k8sTypes';
import { WorkloadOwnerType } from '~/k8sTypes';
import type { PodContainer } from '~/types';
import { WorkloadStatusType } from '~/concepts/distributedWorkloads/utils';
import { mockClusterQueueK8sResource } from '~/__mocks__/mockClusterQueueK8sResource';
import { mockLocalQueueK8sResource } from '~/__mocks__/mockLocalQueueK8sResource';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@
import { mockK8sResourceList, mockRouteK8sResourceModelRegistry } from '~/__mocks__';
import { mockComponents } from '~/__mocks__/mockComponents';
import { mockDashboardConfig } from '~/__mocks__/mockDashboardConfig';
import { MODEL_REGISTRY_API_VERSION } from '~/concepts/modelRegistry/const';
import { mockModelRegistry } from '~/__mocks__/mockModelRegistry';
import { mockRegisteredModelList } from '~/__mocks__/mockRegisteredModelsList';
import { labelModal, modelRegistry } from '~/__tests__/cypress/cypress/pages/modelRegistry';
import { be } from '~/__tests__/cypress/cypress/utils/should';
import { ModelRegistryModel, RouteModel } from '~/__tests__/cypress/cypress/utils/models';
import { mockModelVersionList } from '~/__mocks__/mockModelVersionList';
import { mockModelVersion } from '~/__mocks__/mockModelVersion';
import { ModelVersion, RegisteredModel } from '~/concepts/modelRegistry/types';
import type { ModelVersion, RegisteredModel } from '~/concepts/modelRegistry/types';
import { mockRegisteredModel } from '~/__mocks__/mockRegisteredModel';

const MODEL_REGISTRY_API_VERSION = 'v1alpha3';

type HandlersProps = {
disableModelRegistryFeature?: boolean;
registeredModels?: RegisteredModel[];
Expand Down
Loading

0 comments on commit aaa6bf3

Please sign in to comment.