Skip to content
Draft
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
10 changes: 10 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,15 @@ jobs:
- name: Test
run: npm run test:coverage

# Fails the build if the fixture sanitizer stops refusing identity-bearing
# payloads or starts redacting whole recordings into empty ones.
- name: Test (sanitizer)
run: npm run test:sanitizer

# Renders real components against recorded cluster payloads, so it needs no
# cluster; the ESM flags msw 3 requires are set by the npm script.
- name: Test (integration)
run: npm run test:integration

- name: Build
run: npm run build
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ src/
types.ts # Shared TypeScript types
templates/ # YAML templates for resource creation (Ingress, NAD, Route, Service, UDN)
styles/ # Global SCSS
test/ # Jest integration harness: SDK shim, MSW server, fixtures
integration-tests/ # Cypress E2E tests
tests/ # Test specs (.cy.ts files)
fixtures/ # Test data
Expand Down
8 changes: 7 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,18 @@ PR.

- **Lint**: `npm run lint` (ESLint + Prettier)
- **i18n check**: `npm run i18n` then verify `git status --short locales` shows no changes
- **Unit tests**: `npm test` (or `npm run test:coverage` for a coverage report)
- **Integration tests**: `npm run test:integration` renders real components against the recorded cluster
payloads in `src/test/fixtures`, with the console SDK replaced by a fetch-based shim and MSW serving the
responses, so it needs no cluster
- **Cypress E2E**: `npm run test-cypress-headless` (requires a running OpenShift cluster)

E2E specs live in `integration-tests`. Tests run against http://localhost:9000 by default (override with
`BRIDGE_BASE_ADDRESS`).

CI runs `test-frontend.sh` (i18n validation) and `test-prow-e2e.sh` (Cypress against a live cluster) on every PR.
CI runs the `Test` workflow (`npm run lint`, `test-frontend.sh`, `npm run test:coverage`,
`npm run test:integration` and `npm run build`) and the `E2E Tests` workflow on every PR; Prow additionally
runs `test-prow-e2e.sh` (Cypress against a live cluster).

## Commit Conventions

Expand Down
191 changes: 191 additions & 0 deletions docs/e2e-coverage.md

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ const config: Config.InitialOptions = {
preset: 'ts-jest',
testEnvironment: 'jest-environment-jsdom',
testMatch: ['<rootDir>/src/**/*.{test,spec}.{ts,tsx}'],
// Integration tests need the SDK shim and MSW; they run under
// jest.integration.config.ts via `npm run test:integration`.
testPathIgnorePatterns: ['/node_modules/', '\\.integration\\.test\\.'],
transform: {
'^.+\\.[t|j]sx?$': [
'ts-jest',
Expand Down
78 changes: 78 additions & 0 deletions jest.integration.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { pathsToModuleNameMapper } from 'ts-jest';
import { readConfigFile, sys } from 'typescript';

import type { Config } from '@jest/types';

const { config: tsconfig } = readConfigFile('./tsconfig.json', sys.readFile);
const { compilerOptions } = tsconfig;

/* Integration tests render real components and hooks while the console SDK is
* replaced by a test shim that fetches over HTTP, so MSW can serve responses
* recorded from a live cluster. Unit tests keep using jest.config.ts.
*
* msw 3 is ESM-only and needs Node 22.12+, so this project runs under Jest's
* ESM runtime: start Jest with NODE_OPTIONS=--experimental-vm-modules (see the
* test:integration scripts), treat TypeScript as ESM with
* extensionsToTreatAsEsm and let ts-jest emit ESM. There is no CommonJS build
* mapping for msw and no transform for its ESM-only dependencies.
*
* `jest-fixed-jsdom` is a jsdom environment that keeps Node's WHATWG globals
* (fetch, Request, Response, MessagePort, streams), which MSW requires. */
const config: Config.InitialOptions = {
extensionsToTreatAsEsm: ['.ts', '.tsx'],
moduleFileExtensions: ['js', 'jsx', 'ts', 'tsx', 'mjs', 'cjs'],
moduleNameMapper: {
// Asset imports are matched before the @styles path alias, otherwise an scss
// file resolved through the alias would be loaded as JavaScript.
'\\.(css|scss|sass|svg|png|jpe?g|gif)$': '<rootDir>/src/test/style-mock.cjs',
...pathsToModuleNameMapper(compilerOptions.paths, { prefix: '<rootDir>/' }),
'^@openshift-console/dynamic-plugin-sdk-internal$':
'<rootDir>/src/test/console-sdk-internal-shim.tsx',
'^@openshift-console/dynamic-plugin-sdk/lib/app/components/status/Status$':
'<rootDir>/src/test/status-shim.tsx',
'^@openshift-console/dynamic-plugin-sdk$': '<rootDir>/src/test/console-sdk-shim.tsx',
// `@patternfly` ships ESM sources under dist/esm in packages that are not
// `"type": "module"`, so a deep import there is ESM syntax Jest reads as
// CommonJS. Point the deep paths at the published CommonJS builds, and d3
// (ESM-only) at its published UMD bundle.
'^@patternfly/react-charts/dist/esm/(.*)$':
'<rootDir>/node_modules/@patternfly/react-charts/dist/js/$1',
'^@patternfly/react-topology/dist/esm/(.*)$':
'<rootDir>/node_modules/@patternfly/react-topology/dist/js/$1',
// Resolve the published CJS build instead of the package's TS sources.
'^@patternfly/react-topology$':
'<rootDir>/node_modules/@patternfly/react-topology/dist/js/index.js',
// Every d3 package is ESM-only (`main` is dist/<name>.mjs) but publishes a
// UMD build under the same name; `exports.umd` selects it.
'^d3(-[a-z0-9-]+)?$': '<rootDir>/node_modules/d3$1/dist/d3$1.min.js',
},
setupFiles: ['<rootDir>/src/test/nodeGlobals.ts'],
setupFilesAfterEnv: ['<rootDir>/src/test/setup.ts'],
testEnvironment: 'jest-fixed-jsdom',
testMatch: ['<rootDir>/src/**/*.integration.test.{ts,tsx}'],
transform: {
'^.+\\.[t|j]sx?$': [
'ts-jest',
{
tsconfig: {
...compilerOptions,
allowJs: true,
checkJs: false,
isolatedModules: true,
jsx: 'react-jsx',
module: 'esnext',
},
useESM: true,
},
],
},
// `@patternfly` packages are CommonJS-typed yet ship ESM sources
// (`react-data-view`'s CommonJS build requires `react-tokens/dist/esm/*`), so
// they must be transformed rather than loaded as-is; ts-jest emits each file
// in the format Jest loads it in.
transformIgnorePatterns: [
'/node_modules/(?!(@patternfly|@openshift-console\\S*?|@kubevirt-ui-ext)/)',
],
};

export default config;
Loading
Loading