Skip to content

Commit

Permalink
fix: unit test and test pipeline (#140)
Browse files Browse the repository at this point in the history
* test: update unit tests

Signed-off-by: Nam Hoang <[email protected]>
(cherry picked from commit 409f07a)

* chore: configure jest for lerna

Signed-off-by: Nam Hoang <[email protected]>
(cherry picked from commit ee2f61c)

* chore: trigger the CI test

Signed-off-by: Nam Hoang <[email protected]>
(cherry picked from commit 3a58133)

* fix: json import file

Signed-off-by: Nam Hoang <[email protected]>
(cherry picked from commit de6ce16)

* chore: update jest config

(cherry picked from commit ec32152)

* chore: update yarn lock

(cherry picked from commit 8820932)

* chore: update CI to built previous test

(cherry picked from commit 86da91e)

* chore: remove git ignore app-config

(cherry picked from commit df88f72)

* chore: update CI test

Signed-off-by: Nam Hoang <[email protected]>
(cherry picked from commit a97f7c0)

* chore: update version

Signed-off-by: Nam Hoang <[email protected]>
(cherry picked from commit 1520ab4)

* chore: log the coverage file

Signed-off-by: Nam Hoang <[email protected]>
(cherry picked from commit e91c0ef)

* chore: change coverage CI

Signed-off-by: Nam Hoang <[email protected]>
(cherry picked from commit 34fcfbc)

* chore: adjust test script

Signed-off-by: Nam Hoang <[email protected]>

* chore: remove debug step in CI

Signed-off-by: Nam Hoang <[email protected]>

---------

Signed-off-by: Nam Hoang <[email protected]>
  • Loading branch information
namhoang1604 authored Oct 29, 2024
1 parent 31ed1e5 commit ee48260
Show file tree
Hide file tree
Showing 26 changed files with 13,069 additions and 1,338 deletions.
24 changes: 14 additions & 10 deletions .github/workflows/build_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,21 @@ jobs:
- name: Check linting
run: yarn lint

- name: Build
run: yarn build

- name: Run tests
run: |
yarn jest --changedSince=origin/next --ci --json --coverage --testLocationInResults --outputFile=report.json
yarn test:coverage
- name: Coverage
uses: artiomtr/jest-coverage-report-action@v2
- name: Jest Coverage Comment
uses: MishaKav/jest-coverage-comment@main
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
coverage-file: report.json
base-coverage-file: report.json
threshold: 80

- name: Build
run: yarn build
title: Code Coverage Report
multiple-files: |
All packages, ./coverage/coverage-summary.json
Components, ./packages/components/coverage/coverage-summary.json
Mock app, ./packages/mock-app/coverage/coverage-summary.json
Services, ./packages/services/coverage/coverage-summary.json
UNTP test suite, ./packages/untp-test-suite/coverage/coverage-summary.json
VC test suite, ./packages/vc-test-suite/coverage/coverage-summary.json
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ tmp/
# logs
/logs
packages/services/tsconfig.tsbuildinfo
packages/mock-app/src/constants/app-config.json
packages/untp-test-suite/credentials.json
packages/untp-test-suite/data
# vc-test-suite
Expand Down
7 changes: 7 additions & 0 deletions jest.config.base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
collectCoverageFrom: ['<rootDir>/src/**/*.{ts,tsx}', '<rootDir>/src/**/*.{js,jsx}', '!**/*.d.ts'],
coverageDirectory: '<rootDir>/coverage',
coverageReporters: ['json', 'json-summary', 'text', 'lcov'],
verbose: true,
};
87 changes: 0 additions & 87 deletions jest.config.mjs

This file was deleted.

3 changes: 1 addition & 2 deletions lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@
"gitRemote": "origin",
"message": "chore(release): %s [skip ci]"
}
},
"useWorkspaces": true
}
}
11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@
"name": "mock-app",
"version": "1.0.0",
"private": true,
"workspaces": ["packages/*"],
"workspaces": [
"packages/*"
],
"scripts": {
"start": "cp app-config.json packages/mock-app/src/constants/app-config.json && cd packages/mock-app && yarn start",
"build": "yarn build:services && yarn build:components && yarn build:untp-test-suite",
"build:services": "cd packages/services && yarn run build",
"build:components": "cd packages/components && yarn run build",
"build:untp-test-suite": "cd packages/untp-test-suite && yarn run build",
"build-clean": "rimraf --glob ./yarn.lock ./node_modules ./packages/*/tsconfig.tsbuildinfo ./packages/*/build ./packages/*/node_modules",
"test": "yarn run test:services && yarn run test:components && yarn run test:mock-app",
"test": "lerna exec -- yarn jest",
"test:coverage": "lerna exec -- yarn jest --coverage && rm -rf coverage && istanbul-merge --out coverage/coverage-final.json packages/*/coverage/coverage-final.json && nyc report --temp-dir=./coverage --reporter=html --reporter=json-summary",
"test:components": "cd packages/components && yarn run test",
"test:services": "cd packages/services && yarn run test",
"test:mock-app": "cd packages/mock-app && yarn run test",
Expand Down Expand Up @@ -57,6 +60,8 @@
"node": ">= 20.12.2"
},
"dependencies": {
"rimraf": "^5.0.5"
"rimraf": "^5.0.5",
"istanbul-merge": "2.0.0",
"nyc": "17.1.0"
}
}
2 changes: 2 additions & 0 deletions packages/components/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import base from '../../jest.config.base.js';
const jestConfig = {
...base,
preset: 'ts-jest',
testEnvironment: 'jsdom',
extensionsToTreatAsEsm: ['.ts'],
Expand Down
4 changes: 2 additions & 2 deletions packages/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"build:watch": "tsc -b --watch",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build",
"test": "jest --ci --env=jest-environment-jsdom",
"coverage": "jest --coverage"
"test": "jest",
"test:coverage": "jest --coverage"
},
"eslintConfig": {
"extends": [
Expand Down
12 changes: 0 additions & 12 deletions packages/events/package.json

This file was deleted.

2 changes: 2 additions & 0 deletions packages/mock-app/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const base = require('../../jest.config.base');
const jestConfig = {
...base,
preset: 'ts-jest',
testEnvironment: 'jsdom',
extensionsToTreatAsEsm: ['.ts'],
Expand Down
6 changes: 3 additions & 3 deletions packages/mock-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
"start": "craco start",
"build": "craco build",
"storybook": "storybook dev -p 6006",
"test": "jest --ci --env=jest-environment-jsdom",
"test:watch": "jest --ci --watch --env=jest-environment-jsdom",
"coverage": "jest --coverage"
"test": "jest",
"test:watch": "jest --watch",
"test:coverage": "jest --coverage"
},
"eslintConfig": {
"extends": [
Expand Down
29 changes: 0 additions & 29 deletions packages/mock-app/src/__tests__/DynamicComponentRenderer.test.tsx

This file was deleted.

31 changes: 13 additions & 18 deletions packages/mock-app/src/__tests__/GenericFeature.test.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
import React from 'react';
import { fireEvent, render, screen } from '@testing-library/react';
import { GenericFeature } from '../components/GenericFeature/GenericFeature';
import {
ComponentType,
DynamicComponentRenderer,
IDynamicComponentRendererProps,
} from '../components/GenericFeature/DynamicComponentRenderer';
import { ComponentType, DynamicComponentRenderer, IDynamicComponentRendererProps } from '@mock-app/components';

jest.mock('@mock-app/components', () => ({
JsonForm: jest.fn(),
Button: jest.fn(),
}));

jest.mock('@mock-app/services', () => ({
logService: jest.fn().mockImplementation((value) => value),
logServiceTwo: jest.fn(),
}));

jest.mock('../components/GenericFeature/DynamicComponentRenderer', () => ({
DynamicComponentRenderer: jest.fn(),
toastMessage: jest.fn(),
ComponentType: {
EntryData: 'EntryData',
Void: 'Void',
Submit: 'Submit',
},
Status: {
success: 'success',
error: 'error',
},
}));

jest.mock('@mock-app/services', () => ({
logService: jest.fn().mockImplementation(() => 'logService'),
}));

describe('GenericFeature', () => {
Expand Down Expand Up @@ -93,11 +90,11 @@ describe('GenericFeature', () => {
});

test('should render UI with componentsData and call onClick to trigger services', () => {
const mock = jest.fn().mockImplementation(() => 'logService');
const mock = jest.fn().mockImplementation((value) => expect(value).toBe('logService'));
const services = [
{
name: 'logService',
parameters: [mock()],
parameters: [],
},
];

Expand All @@ -106,7 +103,7 @@ describe('GenericFeature', () => {
<div>
<p>{name}</p>

{name === 'Button' && <button onClick={props.onClick}>Click me!</button>}
{name === 'Button' && <button onClick={() => props.onClick(mock)}>Click me!</button>}
</div>
),
);
Expand All @@ -115,7 +112,5 @@ describe('GenericFeature', () => {
fireEvent.click(screen.getByText('Click me!'));

expect(screen.getByText('Button')).not.toBeNull();
expect(mock).toHaveBeenCalled();
expect(mock).toHaveReturnedWith('logService');
});
});
Loading

0 comments on commit ee48260

Please sign in to comment.