Skip to content

[mwa-fix-unit-tests] Fix MWA's unit tests and create a GH action that runs the tests on each change of the frontend code #65

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 23, 2023
Merged
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
37 changes: 36 additions & 1 deletion .github/workflows/test-node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- frontend/**

jobs:
test:
frontend-format-linting-check:
name: Code format and lint
runs-on: ubuntu-latest

Expand All @@ -28,3 +28,38 @@ jobs:
run: |
cd frontend
npm run lint-check

frontend-unit-tests:
name: Frontend Unit Tests
runs-on: ubuntu-latest

steps:
- name: Check out code
uses: actions/checkout@v3

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 12

- name: Fetch Kubeflow and install common code dependencies
run: |
COMMIT=$(cat frontend/COMMIT)
cd /tmp && git clone https://github.com/kubeflow/kubeflow.git
cd kubeflow
git checkout $COMMIT
cd components/crud-web-apps/common/frontend/kubeflow-common-lib
npm i
npm run build
npm link ./dist/kubeflow

- name: Install MWA dependencies
run: |
cd frontend
npm i
npm link kubeflow

- name: Run unit tests
run: |
cd frontend
npm run test:prod
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ FROM ubuntu AS fetch-kubeflow-kubeflow
RUN apt-get update && apt-get install git -y

WORKDIR /kf
COPY ./frontend/COMMIT ./
RUN git clone https://github.com/kubeflow/kubeflow.git && \
COMMIT=$(cat ./COMMIT) && \
cd kubeflow && \
git checkout 8dcfe792c
git checkout $COMMIT

# --- Build the backend kubeflow-wheel ---
FROM python:3.7-slim AS backend-kubeflow-wheel
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ Requirements:
### Frontend
```bash
# build the common library
COMMIT=$(cat ./frontend/COMMIT)
cd $KUBEFLOW_REPO/components/crud-web-apps/common/frontend/kubeflow-common-lib
git checkout 8dcfe792c
git checkout $COMMIT

npm i
npm run build
Expand Down
1 change: 1 addition & 0 deletions frontend/COMMIT
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8dcfe792c
30 changes: 8 additions & 22 deletions frontend/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,8 @@
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.app.json",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.scss"
],
"assets": ["src/favicon.ico", "src/assets"],
"styles": ["src/styles.scss"],
"scripts": [
"node_modules/ace-builds/src-min/ace.js",
"node_modules/ace-builds/src-min/mode-yaml.js",
Expand All @@ -56,9 +51,7 @@
},
"configurations": {
"fr": {
"localize": [
"fr"
]
"localize": ["fr"]
},
"production": {
"fileReplacements": [
Expand Down Expand Up @@ -123,14 +116,10 @@
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.spec.json",
"karmaConfig": "karma.conf.js",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.scss"
],
"scripts": []
"assets": ["src/favicon.ico", "src/assets"],
"styles": ["src/styles.scss"],
"scripts": [],
"preserveSymlinks": true
}
},
"e2e": {
Expand All @@ -148,10 +137,7 @@
"lint": {
"builder": "@angular-eslint/builder:lint",
"options": {
"lintFilePatterns": [
"src/**/*.ts",
"src/**/*.html"
]
"lintFilePatterns": ["src/**/*.ts", "src/**/*.html"]
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"format:write": "prettier --write 'src/**/*.{js,ts,html,scss,css}'",
"i18n:extract": "ng extract-i18n --output-path i18n",
"test": "ng test",
"test:prod": "ng test --browsers=ChromeHeadless --watch=false",
"lint-check": "ng lint",
"lint": "ng lint --fix",
"e2e": "ng e2e"
Expand Down Expand Up @@ -43,7 +44,7 @@
"js-yaml": "^4.0.0",
"lodash": "^4.17.20",
"lodash-es": "^4.17.11",
"material-icons": "^0.3.1",
"material-icons": "^0.7.7",
"rxjs": "~6.6.7",
"tslib": "^2.0.0",
"zone.js": "~0.11.4"
Expand Down
6 changes: 6 additions & 0 deletions frontend/scripts/check-format-error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
console.error();
console.error('-----------------------------------------------');
console.error('Please run `npm run format:write` to format your code.');
console.error('-----------------------------------------------');
console.error();
process.exit(1);
9 changes: 0 additions & 9 deletions frontend/src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,4 @@ describe('AppComponent', () => {
const app = fixture.debugElement.componentInstance;
expect(app.title).toEqual('frontend');
});

it('should render title', () => {
const fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges();
const compiled = fixture.debugElement.nativeElement;
expect(compiled.querySelector('.content span').textContent).toContain(
'frontend app is running!',
);
});
});
41 changes: 40 additions & 1 deletion frontend/src/app/pages/index/index.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';

import { HttpClientTestingModule } from '@angular/common/http/testing';
import { MatSnackBarModule } from '@angular/material/snack-bar';
import { RouterTestingModule } from '@angular/router/testing';
import { MWABackendService } from 'src/app/services/backend.service';
import { Clipboard } from '@angular/cdk/clipboard';
import {
NamespaceService,
ConfirmDialogService,
SnackBarService,
} from 'kubeflow';
import { CommonModule } from '@angular/common';
import { KubeflowModule } from 'kubeflow';
import { IndexComponent } from './index.component';
import { of } from 'rxjs';

let MWABackendServiceStub: Partial<MWABackendService>;
let NamespaceServiceStub: Partial<NamespaceService>;

MWABackendServiceStub = {
getInferenceServices: () => of(),
deleteInferenceService: () => of(),
};

NamespaceServiceStub = {
getSelectedNamespace: () => of(),
getSelectedNamespace2: () => of(),
};

describe('IndexComponent', () => {
let component: IndexComponent;
Expand All @@ -9,6 +34,20 @@ describe('IndexComponent', () => {
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [IndexComponent],
imports: [
HttpClientTestingModule,
MatSnackBarModule,
RouterTestingModule,
CommonModule,
KubeflowModule,
],
providers: [
{ provide: ConfirmDialogService, useValue: {} },
{ provide: MWABackendService, useValue: MWABackendServiceStub },
{ provide: NamespaceService, useValue: NamespaceServiceStub },
{ provide: SnackBarService, useValue: {} },
{ provide: Clipboard, useValue: {} },
],
}).compileComponents();
}));

Expand Down
Loading