Skip to content
This repository was archived by the owner on Apr 18, 2024. It is now read-only.

Commit 98f0617

Browse files
chore: DEV-3855: Fix Jest tests (#1037)
* Fix Jest tests * Fix keymaster issue * Rename workflows * Upload coverage reports (test) * Fix coverage path * Properly upload coverage * Use token from secrets * Organize the workflow * Set version * Rename jobs * Rename workflows * Rename test jobs * Setup triggers * Allow all branches * Cleanup * Restrict run on push * Switch version
1 parent 5db6aec commit 98f0617

15 files changed

+2298
-1298
lines changed

Diff for: .babelrc

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"presets": [
3+
["@babel/preset-react", {
4+
"runtime": "automatic"
5+
}],
6+
"@babel/preset-typescript",
7+
["@babel/preset-env", {
8+
"targets": {
9+
"browsers": ["last 2 Chrome versions"],
10+
"node": "current"
11+
}
12+
}]
13+
],
14+
"plugins": [
15+
["babel-plugin-import", { "libraryName": "antd" }],
16+
"@babel/plugin-proposal-class-properties",
17+
"@babel/plugin-proposal-private-methods",
18+
"@babel/plugin-proposal-optional-chaining",
19+
"@babel/plugin-proposal-nullish-coalescing-operator"
20+
]
21+
}

Diff for: .github/workflows/build_bundle.yml

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Build bundle
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
sha:
7+
required: true
8+
type: string
9+
branch_name:
10+
required: true
11+
type: string
12+
13+
env:
14+
# increment it in case if you need to reset cache
15+
CACHE_NAME_PREFIX: v3
16+
NODE: '14'
17+
18+
jobs:
19+
build:
20+
runs-on: ubuntu-latest
21+
22+
# ci can be skipped with `[skip ci]` prefix in message
23+
if: "!contains(github.event.head_commit.message, 'skip ci')"
24+
25+
steps:
26+
- uses: actions/checkout@v3
27+
- uses: actions/setup-node@v3
28+
with:
29+
node-version: "${{ env.NODE }}"
30+
31+
- name: Get CPU info
32+
id: "cpu-info"
33+
run: echo "cores-count=$(cat /proc/cpuinfo | grep processor | wc -l)" >> $GITHUB_OUTPUT
34+
35+
- name: Upgrade Yarn
36+
run: npm install -g [email protected]
37+
38+
- name: Get yarn cache directory path
39+
id: yarn-cache-dir-path
40+
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
41+
42+
- name: Configure yarn cache
43+
uses: actions/cache@v3
44+
with:
45+
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
46+
key: ${{ env.CACHE_NAME_PREFIX }}-${{ runner.os }}-node-${{ env.NODE }}-${{ hashFiles('**/yarn.lock') }}
47+
restore-keys: |
48+
yarn-${{ env.CACHE_NAME_PREFIX }}-${{ runner.os }}-node-${{ env.NODE }}-
49+
50+
- name: Print Yarn cache size
51+
run: du -d 0 -h ${{ steps.yarn-cache-dir-path.outputs.dir }}
52+
53+
- name: Install dependencies
54+
run: yarn install --frozen-lockfile
55+
56+
- name: Unit tests
57+
run: yarn test && yarn test:coverage
58+
59+
- name: Build distribution package
60+
timeout-minutes: 10
61+
run: yarn run build:module
62+
env:
63+
CI: false # on true webpack breaks on warnings, and we have them a lot
64+
NODE_ENV: 'production'
65+
66+
# upload this build as artifact to current Action
67+
- name: Upload bundle
68+
uses: actions/upload-artifact@v3
69+
with:
70+
name: LSF-${{ github.event.pull_request.head.sha || github.sha }}
71+
path: build/

Diff for: .github/workflows/cicd_pipeline.yml

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: "CI/CD Pipleline"
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- 'lse-release/**'
8+
pull_request_target:
9+
types:
10+
- opened
11+
- synchronize
12+
- reopened
13+
- ready_for_review
14+
branches:
15+
- master
16+
- 'lse-release/**'
17+
18+
jobs:
19+
build_bundle:
20+
name: "Build JS Bundle"
21+
if: github.event_name == 'push' || github.event.pull_request.draft == false
22+
uses: heartexlabs/label-studio-frontend/.github/workflows/build_bundle.yml@master
23+
with:
24+
sha: ${{ github.event.pull_request.head.sha || github.event.after }}
25+
branch_name: ${{ github.event.pull_request.head.ref || github.ref_name }}
26+
secrets: inherit
27+
28+
run_e2e:
29+
name: "Run Tests"
30+
if: github.event_name == 'push' || github.event.pull_request.draft == false
31+
uses: heartexlabs/label-studio-frontend/.github/workflows/e2e_tests.yml@master
32+
needs:
33+
- build_bundle
34+
with:
35+
sha: ${{ github.event.pull_request.head.sha || github.event.after }}
36+
branch_name: ${{ github.event.pull_request.head.ref || github.ref_name }}
37+
secrets: inherit
38+
39+
run_unit:
40+
name: "Run Tests"
41+
if: github.event_name == 'push' || github.event.pull_request.draft == false
42+
uses: heartexlabs/label-studio-frontend/.github/workflows/unit_tests.yml@master
43+
with:
44+
sha: ${{ github.event.pull_request.head.sha || github.event.after }}
45+
branch_name: ${{ github.event.pull_request.head.ref || github.ref_name }}
46+
secrets: inherit

Diff for: .github/workflows/build.yml renamed to .github/workflows/e2e_tests.yml

+18-39
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
1-
name: Build and Test
1+
name: "Run E2E"
22

33
on:
4-
push:
5-
branches: [master, "**"]
4+
workflow_call:
5+
inputs:
6+
sha:
7+
required: true
8+
type: string
9+
branch_name:
10+
required: true
11+
type: string
612

713
env:
814
# increment it in case if you need to reset cache
915
CACHE_NAME_PREFIX: v3
1016
NODE: '14'
1117

1218
jobs:
13-
build:
19+
run:
20+
name: "Run E2E"
21+
runs-on: ubuntu-latest
22+
1423
# ci can be skipped with `[skip ci]` prefix in message
1524
if: "!contains(github.event.head_commit.message, 'skip ci')"
16-
runs-on: ubuntu-latest
1725

1826
steps:
1927
- uses: actions/checkout@v3
@@ -43,18 +51,11 @@ jobs:
4351
- name: Print Yarn cache size
4452
run: du -d 0 -h ${{ steps.yarn-cache-dir-path.outputs.dir }}
4553

46-
- name: Install dependencies
47-
run: yarn install --frozen-lockfile
48-
49-
- name: Unit tests
50-
run: yarn test && yarn test:coverage
51-
52-
- name: Build distribution package
53-
timeout-minutes: 10
54-
run: yarn run build:module
55-
env:
56-
CI: false # on true webpack breaks on warnings, and we have them a lot
57-
NODE_ENV: 'production'
54+
- name: "Download bundle"
55+
uses: actions/download-artifact@v3
56+
with:
57+
name: LSF-${{ github.event.pull_request.head.sha || github.sha }}
58+
path: build/
5859

5960
# run http-server with build in background (will be killed after job ends)
6061
# do this only for master branch (so only for push event)
@@ -91,30 +92,8 @@ jobs:
9192
cd e2e
9293
yarn run test:ci ${{ steps.cpu-info.outputs.cores-count }}
9394
94-
# - name: "Convert coverage report to Istanbul"
95-
# if: github.event_name == 'push'
96-
# run: |
97-
# set -euo pipefail
98-
# cd e2e
99-
# yarn run coverage:istanbul
100-
# yarn run coverage:report
101-
102-
# - name: "Upload e2e coverage to Codecov"
103-
# uses: codecov/[email protected]
104-
# with:
105-
# name: codecov-general
106-
# directory: ./e2e/output/coverage
107-
# token: ${{ secrets.CODECOV_TOKEN }}
108-
# fail_ci_if_error: true
109-
11095
- uses: actions/upload-artifact@v3
11196
if: ${{ failure() }}
11297
with:
11398
name: e2e output
11499
path: e2e/output/
115-
116-
# upload this build as artifact to current Action
117-
- uses: actions/upload-artifact@v3
118-
with:
119-
name: build ${{ github.event.pull_request.head.sha || github.sha }}
120-
path: build/

Diff for: .github/workflows/unit_tests.yml

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: "Component/Unit Tests"
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
sha:
7+
required: true
8+
type: string
9+
branch_name:
10+
required: true
11+
type: string
12+
13+
env:
14+
# increment it in case if you need to reset cache
15+
CACHE_NAME_PREFIX: v3
16+
NODE: '14'
17+
18+
jobs:
19+
run:
20+
name: "Run Component/Unit Tests"
21+
runs-on: ubuntu-latest
22+
23+
# ci can be skipped with `[skip ci]` prefix in message
24+
if: "!contains(github.event.head_commit.message, 'skip ci')"
25+
26+
steps:
27+
- name: "Checlout codebase"
28+
uses: actions/checkout@v3
29+
30+
- name: "Setup NodeJS"
31+
uses: actions/setup-node@v3
32+
with:
33+
node-version: "${{ env.NODE }}"
34+
35+
- name: Upgrade Yarn
36+
run: npm install -g [email protected]
37+
38+
- name: Get yarn cache directory path
39+
id: yarn-cache-dir-path
40+
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
41+
42+
- name: Configure yarn cache
43+
uses: actions/cache@v3
44+
with:
45+
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
46+
key: ${{ env.CACHE_NAME_PREFIX }}-${{ runner.os }}-node-${{ env.NODE }}-${{ hashFiles('**/yarn.lock') }}
47+
restore-keys: |
48+
yarn-${{ env.CACHE_NAME_PREFIX }}-${{ runner.os }}-node-${{ env.NODE }}-
49+
50+
- name: Run unit tests
51+
run: yarn install --frozen-lockfile && yarn test:coverage
52+
53+
- name: Upload coverage to Codecov
54+
uses: codecov/[email protected]
55+
with:
56+
fail_ci_if_error: true
57+
# files: ./label-studio-frontend/coverage/coverage.xml
58+
# verbose: true
59+
# name: codecov-lsf-${{ matrix.python-version }}
60+
token: ${{ secrets.CODECOV_TOKEN }}
61+
1.18 MB
Loading

Diff for: jest.config.js

+54-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,65 @@
11
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
22
module.exports = {
3+
"bail": true,
4+
"roots": [
5+
"<rootDir>/src",
6+
],
7+
"preset": "ts-jest",
38
"testEnvironment": "jsdom",
9+
"verbose": false,
10+
"coverageDirectory": "coverage",
11+
"coverageReporters": ['json', 'lcov', 'clover'],
12+
"coverageThreshold": {
13+
"global": {
14+
"branches": 1,
15+
"functions": 1,
16+
"lines": 1,
17+
"statements": 1,
18+
},
19+
},
420
"transform": {
5-
"\\.[jt]sx?$": 'babel-jest',
6-
"node_modules/.*konva.*/": "babel-jest",
21+
"^.+\\.[tj]sx?$": ['babel-jest', {
22+
"presets": [
23+
["@babel/preset-react", {
24+
"runtime": "automatic",
25+
}],
26+
"@babel/preset-typescript",
27+
["@babel/preset-env", {
28+
"targets": {
29+
"browsers": ["last 2 Chrome versions"],
30+
"node": "current",
31+
},
32+
}],
33+
],
34+
"plugins": [
35+
["babel-plugin-import", { "libraryName": "antd" }],
36+
"@babel/plugin-proposal-class-properties",
37+
"@babel/plugin-proposal-private-methods",
38+
"@babel/plugin-proposal-optional-chaining",
39+
"@babel/plugin-proposal-nullish-coalescing-operator",
40+
],
41+
}],
742
},
43+
"moduleFileExtensions": [
44+
"js",
45+
"ts",
46+
"jsx",
47+
"tsx",
48+
],
49+
"moduleDirectories": [
50+
"node_modules",
51+
],
852
"moduleNameMapper": {
953
"^konva": "konva/konva",
54+
"^keymaster": "identity-obj-proxy",
1055
"^react-konva-utils": "identity-obj-proxy",
1156
"\\.(s[ac]ss|css|styl|svg|png|jpe?g)$": "identity-obj-proxy",
1257
},
58+
"testPathIgnorePatterns": [
59+
"/node_modules/",
60+
"/e2e/",
61+
],
62+
"transformIgnorePatterns": [
63+
"node_modules/?!(nanoid|konva)",
64+
],
1365
};

0 commit comments

Comments
 (0)