Skip to content

Commit 76e52bd

Browse files
Broken tests fix and Github Action update to run the Cypress tests (#32)
Co-authored-by: Andreas Kienle <[email protected]>
1 parent dec5c5b commit 76e52bd

File tree

5 files changed

+40
-13
lines changed

5 files changed

+40
-13
lines changed

.github/workflows/build.yaml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
name: Build
1+
name: Build and Test
22

33
on:
44
workflow_call:
55

66
jobs:
7-
build:
7+
build-and-test:
88
runs-on: ubuntu-latest
99
permissions:
1010
contents: read
@@ -16,9 +16,24 @@ jobs:
1616
uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0
1717
with:
1818
node-version: 22
19+
cache: 'npm' # Added caching for faster installs
1920

2021
- name: Install dependencies
2122
run: npm ci
2223

2324
- name: Build
2425
run: npm run build
26+
27+
- name: Run Cypress Tests
28+
run: npm run test
29+
30+
- name: Upload Cypress Screenshots
31+
if: always() # Run this step even if tests fail
32+
uses: actions/upload-artifact@v4
33+
with:
34+
name: cypress-screenshots
35+
path: |
36+
cypress/screenshots/
37+
retention-days: 7 # Keep artifacts for 7 days
38+
if-no-files-found: warn # Warn instead of fail if no screenshots found
39+

cypress/support/component.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ import { ThemeProvider } from '@ui5/webcomponents-react';
2020
import { mount } from 'cypress/react';
2121
// Import commands.js using ES2015 syntax:
2222
import './commands';
23-
import { FrontendConfigProvider, Landscape } from "../../src/context/FrontendConfigContext";
23+
import { FrontendConfigContext } from '../../src/context/FrontendConfigContext';
24+
import { mockedFrontendConfig } from '../../src/utils/testing';
2425

2526
// Augment the Cypress namespace to include type definitions for
2627
// your custom command.
@@ -36,12 +37,11 @@ declare global {
3637
}
3738

3839

39-
4040
Cypress.Commands.add('mount', (component, options) => {
41-
return mount(<ThemeProvider><FrontendConfigProvider config={{
42-
"backendUrl": "http://localhost:3000",
43-
"landscape": "DEV" as Landscape,
44-
"documentationBaseUrl": "http://localhost:3000"
45-
}}>{component} </FrontendConfigProvider></ThemeProvider>, options);
41+
return mount(<ThemeProvider>
42+
<FrontendConfigContext value={mockedFrontendConfig}>
43+
{component}
44+
</FrontendConfigContext>
45+
</ThemeProvider>, options);
4646
});
4747

src/context/FrontendConfigContext.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export enum Landscape {
66
Canary = 'CANARY',
77
Staging = 'STAGING',
88
Development = 'DEV',
9+
Local = 'LOCAL',
910
}
1011

1112
interface FrontendConfigContextProps {
@@ -15,19 +16,18 @@ interface FrontendConfigContextProps {
1516
links: DocLinkCreator;
1617
}
1718

18-
const FrontendConfigContext = createContext<FrontendConfigContextProps | null>(
19+
export const FrontendConfigContext = createContext<FrontendConfigContextProps | null>(
1920
null,
2021
);
2122

23+
2224
const fetchPromise = fetch('/frontend-config.json').then((res) => res.json());
2325

2426
interface FrontendConfigProviderProps {
2527
children: ReactNode;
2628
}
2729

28-
export function FrontendConfigProvider({
29-
children,
30-
}: FrontendConfigProviderProps) {
30+
export function FrontendConfigProvider({ children }: FrontendConfigProviderProps) {
3131
const config = use(fetchPromise);
3232
const docLinks = new DocLinkCreator(config.documentationBaseUrl);
3333
const value: FrontendConfigContextProps = {

src/utils/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ export const extractWorkspaceNameFromNamespace = (namespace: string) => {
1010
export const projectnameToNamespace = (projectname: string) => {
1111
return `project-${projectname}`;
1212
};
13+

src/utils/testing.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { DocLinkCreator } from '../lib/shared/links.ts';
2+
import { Landscape } from '../context/FrontendConfigContext.tsx';
3+
4+
export const isInTestingMode: Boolean = !!window.Cypress;
5+
const documentationBaseUrl = 'http://localhost:3000';
6+
export const mockedFrontendConfig = {
7+
backendUrl: 'http://localhost:3000',
8+
landscape: Landscape.Local,
9+
documentationBaseUrl: 'http://localhost:3000',
10+
links: new DocLinkCreator(documentationBaseUrl),
11+
};

0 commit comments

Comments
 (0)