Skip to content

Commit ea606a2

Browse files
anbratenlukashass
andauthored
ci: add some tests (#36)
* ci: add some tests * test: format with prettier * ci: run tests on pull-requests and pushes * improve ci flow * ci: fix unit test * Update package.json Co-authored-by: Lukas <[email protected]> * test: disable some type warnings * test: disable some type warnings * fix: improve rollup config * build: remove unused deps Co-authored-by: Lukas <[email protected]>
1 parent 75ae285 commit ea606a2

File tree

9 files changed

+173
-66
lines changed

9 files changed

+173
-66
lines changed

.github/workflows/tests.yml

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
name: Tests
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
push:
8+
branches:
9+
- main
10+
11+
env:
12+
YARN_CACHE_FOLDER: ~/.yarn
13+
14+
jobs:
15+
unit-tests:
16+
name: Unit tests
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v2
21+
with:
22+
fetch-depth: 0
23+
24+
- name: Setup Node.js
25+
uses: actions/setup-node@v1
26+
with:
27+
node-version: 12
28+
29+
- name: Caching
30+
uses: actions/cache@v2
31+
with:
32+
path: ${{ env.YARN_CACHE_FOLDER }}
33+
key: ${{ runner.OS }}-yarn-${{ hashFiles('**/yarn.lock') }}
34+
restore-keys: |
35+
${{ runner.OS }}-yarn-${{ env.cache-name }}
36+
${{ runner.OS }}-yarn-
37+
38+
- name: Installing dependencies
39+
run: yarn install --frozen-lockfile
40+
41+
- name: Unit test
42+
run: yarn test
43+
44+
- uses: artiomtr/[email protected]
45+
if: "github.event_name == 'pull_request'"
46+
with:
47+
github-token: ${{ secrets.GITHUB_TOKEN }}
48+
skip-step: all
49+
50+
typecheck:
51+
name: Typecheck
52+
runs-on: ubuntu-latest
53+
steps:
54+
- name: Checkout
55+
uses: actions/checkout@v2
56+
with:
57+
fetch-depth: 0
58+
59+
- name: Setup Node.js
60+
uses: actions/setup-node@v1
61+
with:
62+
node-version: 12
63+
64+
- name: Caching
65+
uses: actions/cache@v2
66+
with:
67+
path: ${{ env.YARN_CACHE_FOLDER }}
68+
key: ${{ runner.OS }}-yarn-${{ hashFiles('**/yarn.lock') }}
69+
restore-keys: |
70+
${{ runner.OS }}-yarn-${{ env.cache-name }}
71+
${{ runner.OS }}-yarn-
72+
73+
- name: Installing dependencies
74+
run: yarn install --frozen-lockfile
75+
76+
- name: Typecheck
77+
run: yarn typecheck
78+
79+
lint:
80+
name: Lint
81+
runs-on: ubuntu-latest
82+
steps:
83+
- name: Checkout
84+
uses: actions/checkout@v2
85+
with:
86+
fetch-depth: 0
87+
88+
- name: Setup Node.js
89+
uses: actions/setup-node@v1
90+
with:
91+
node-version: 12
92+
93+
- name: Caching
94+
uses: actions/cache@v2
95+
with:
96+
path: ${{ env.YARN_CACHE_FOLDER }}
97+
key: ${{ runner.OS }}-yarn-${{ hashFiles('**/yarn.lock') }}
98+
restore-keys: |
99+
${{ runner.OS }}-yarn-${{ env.cache-name }}
100+
${{ runner.OS }}-yarn-
101+
102+
- name: Installing dependencies
103+
run: yarn install --frozen-lockfile
104+
105+
- name: Lint
106+
run: yarn lint
107+
108+
check-format:
109+
name: Check format
110+
runs-on: ubuntu-latest
111+
steps:
112+
- name: Checkout
113+
uses: actions/checkout@v2
114+
with:
115+
fetch-depth: 0
116+
117+
- name: Setup Node.js
118+
uses: actions/setup-node@v1
119+
with:
120+
node-version: 12
121+
122+
- name: Caching
123+
uses: actions/cache@v2
124+
with:
125+
path: ${{ env.YARN_CACHE_FOLDER }}
126+
key: ${{ runner.OS }}-yarn-${{ hashFiles('**/yarn.lock') }}
127+
restore-keys: |
128+
${{ runner.OS }}-yarn-${{ env.cache-name }}
129+
${{ runner.OS }}-yarn-
130+
131+
- name: Installing dependencies
132+
run: yarn install --frozen-lockfile
133+
134+
- name: Check format
135+
run: yarn lint:format

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ dist
33
coverage/
44
junit.xml
55
*.tgz
6+
report.json

jest.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ const config: Config.InitialOptions = {
1414
roots: ['<rootDir>/test'],
1515
moduleNameMapper,
1616
testEnvironment: 'jest-environment-jsdom',
17-
reporters: ['default', 'jest-junit'],
1817
collectCoverage: true,
19-
coverageReporters: ['json', 'text', 'cobertura'],
18+
coverageReporters: ['json'],
19+
testLocationInResults: true,
2020
setupFilesAfterEnv: ['<rootDir>/test/__setup__/console.ts'],
2121
};
2222

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@
1818
"/dist"
1919
],
2020
"scripts": {
21-
"build": "rollup -c rollup.config.js",
21+
"build": "rollup -c rollup.config.ts --configPlugin rollup-plugin-typescript2",
2222
"clean": "rm -rf dist/ node_modules/",
23-
"lint": "prettier --check . && eslint --max-warnings 0 .",
24-
"start": "rollup -c rollup.config.js --watch",
25-
"test": "NODE_OPTIONS=--experimental-vm-modules jest --forceExit --detectOpenHandles",
23+
"lint": "eslint --max-warnings 0 .",
24+
"lint:format": "prettier --check .",
25+
"start": "yarn build --watch",
26+
"test": "NODE_OPTIONS=--experimental-vm-modules jest --forceExit --detectOpenHandles --testLocationInResults --json --outputFile=report.json",
2627
"test:watch": "yarn test --watch",
28+
"typecheck": "tsc --noEmit",
2729
"release": "semantic-release"
2830
},
2931
"dependencies": {
@@ -43,10 +45,8 @@
4345
"@types/node": "15.12.4",
4446
"@vue/test-utils": "2.0.0-rc.6",
4547
"esbuild": "0.12.9",
46-
"esbuild-register": "2.6.0",
4748
"eslint": "7.29.0",
4849
"jest": "26.6.3",
49-
"jest-junit": "12.2.0",
5050
"prettier": "2.3.1",
5151
"rollup": "2.52.2",
5252
"rollup-plugin-dts": "3.0.2",

renovate.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
{
2-
"extends": [
3-
"config:base"
4-
]
2+
"extends": ["config:base"]
53
}

rollup.config.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/useFind.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ function loadServiceEventHandlers<
88
CustomApplication extends Application,
99
T extends keyof ServiceTypes<CustomApplication>,
1010
M,
11-
>(
12-
service: FeathersService<CustomApplication, ServiceTypes<CustomApplication>[T]>,
13-
params: Ref<Params>,
14-
data: Ref<M[]>,
11+
>(
12+
service: FeathersService<CustomApplication, ServiceTypes<CustomApplication>[T]>,
13+
params: Ref<Params>,
14+
data: Ref<M[]>,
1515
): () => void {
1616
const onCreated = (item: M): void => {
1717
// ignore items which are not matching the query
@@ -43,15 +43,23 @@ function loadServiceEventHandlers<
4343
});
4444
};
4545

46+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
4647
service.on('created', onCreated);
48+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
4749
service.on('removed', onRemoved);
50+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
4851
service.on('patched', onItemChanged);
52+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
4953
service.on('updated', onItemChanged);
5054

5155
const unloadEventHandlers = () => {
56+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
5257
service.off('created', onCreated);
58+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
5359
service.off('removed', onRemoved);
60+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
5461
service.off('patched', onItemChanged);
62+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
5563
service.off('updated', onItemChanged);
5664
};
5765

@@ -67,7 +75,7 @@ export type UseFind<T> = {
6775
export type UseFindFunc<CustomApplication> = <
6876
T extends keyof ServiceTypes<CustomApplication>,
6977
M = ServiceModel<CustomApplication, T>,
70-
>(
78+
>(
7179
serviceName: T,
7280
params?: Ref<Params>,
7381
) => UseFind<M>;

src/useGet.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ function loadServiceEventHandlers<
77
CustomApplication extends Application,
88
T extends keyof ServiceTypes<CustomApplication>,
99
M,
10-
>(
11-
service: FeathersService<CustomApplication, ServiceTypes<CustomApplication>[T]>,
12-
_id: Ref<Id | undefined>,
13-
data: Ref<M | undefined>,
10+
>(
11+
service: FeathersService<CustomApplication, ServiceTypes<CustomApplication>[T]>,
12+
_id: Ref<Id | undefined>,
13+
data: Ref<M | undefined>,
1414
): () => void {
1515
const onCreated = (item: M): void => {
1616
if (_id.value === getId(item)) {
@@ -30,15 +30,23 @@ function loadServiceEventHandlers<
3030
}
3131
};
3232

33+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
3334
service.on('created', onCreated);
35+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
3436
service.on('removed', onRemoved);
37+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
3538
service.on('patched', onItemChanged);
39+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
3640
service.on('updated', onItemChanged);
3741

3842
const unloadEventHandlers = () => {
43+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
3944
service.off('created', onCreated);
45+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
4046
service.off('removed', onRemoved);
47+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
4148
service.off('patched', onItemChanged);
49+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
4250
service.off('updated', onItemChanged);
4351
};
4452

@@ -54,7 +62,7 @@ export type UseGet<T> = {
5462
export type UseGetFunc<CustomApplication> = <
5563
T extends keyof ServiceTypes<CustomApplication>,
5664
M = ServiceModel<CustomApplication, T>,
57-
>(
65+
>(
5866
serviceName: T,
5967
_id: Ref<Id | undefined>,
6068
) => UseGet<M>;

yarn.lock

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1422,11 +1422,6 @@ ansi-regex@^3.0.0:
14221422
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-3.0.0.tgz#ed0317c322064f79466c02966bddb605ab37d998"
14231423
integrity sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=
14241424

1425-
ansi-regex@^4.1.0:
1426-
version "4.1.0"
1427-
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-4.1.0.tgz#8b9f8f08cf1acb843756a839ca8c7e3168c51997"
1428-
integrity sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==
1429-
14301425
ansi-regex@^5.0.0:
14311426
version "5.0.0"
14321427
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.0.tgz#388539f55179bf39339c81af30a654d69f87cb75"
@@ -2612,15 +2607,7 @@ es-to-primitive@^1.2.1:
26122607
is-date-object "^1.0.1"
26132608
is-symbol "^1.0.2"
26142609

2615-
2616-
version "2.6.0"
2617-
resolved "https://registry.yarnpkg.com/esbuild-register/-/esbuild-register-2.6.0.tgz#9f19a54c82be751dd87673d6a66d7b9e1cdd8498"
2618-
integrity sha512-2u4AtnCXP5nivtIxZryiZOUcEQkOzFS7UhAqibUEmaTAThJ48gDLYTBF/Fsz+5r0hbV1jrFE6PQvPDUrKZNt/Q==
2619-
dependencies:
2620-
esbuild "^0.12.8"
2621-
jsonc-parser "^3.0.0"
2622-
2623-
[email protected], esbuild@^0.12.8:
2610+
26242611
version "0.12.9"
26252612
resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.12.9.tgz#bed4e7087c286cd81d975631f77d47feb1660070"
26262613
integrity sha512-MWRhAbMOJ9RJygCrt778rz/qNYgA4ZVj6aXnNPxFjs7PmIpb0fuB9Gmg5uWrr6n++XKwwm/RmSz6RR5JL2Ocsw==
@@ -4168,16 +4155,6 @@ jest-jasmine2@^26.6.3:
41684155
pretty-format "^26.6.2"
41694156
throat "^5.0.0"
41704157

4171-
4172-
version "12.2.0"
4173-
resolved "https://registry.yarnpkg.com/jest-junit/-/jest-junit-12.2.0.tgz#cff7f9516e84f8e30f6bdea04cd84db6b095a376"
4174-
integrity sha512-ecGzF3KEQwLbMP5xMO7wqmgmyZlY/5yWDvgE/vFa+/uIT0KsU5nluf0D2fjIlOKB+tb6DiuSSpZuGpsmwbf7Fw==
4175-
dependencies:
4176-
mkdirp "^1.0.4"
4177-
strip-ansi "^5.2.0"
4178-
uuid "^8.3.2"
4179-
xml "^1.0.1"
4180-
41814158
jest-leak-detector@^26.6.2:
41824159
version "26.6.2"
41834160
resolved "https://registry.yarnpkg.com/jest-leak-detector/-/jest-leak-detector-26.6.2.tgz#7717cf118b92238f2eba65054c8a0c9c653a91af"
@@ -4521,11 +4498,6 @@ jsonc-eslint-parser@^0.6.2:
45214498
eslint-visitor-keys "^1.3.0"
45224499
espree "^6.0.0 || ^7.2.0"
45234500

4524-
jsonc-parser@^3.0.0:
4525-
version "3.0.0"
4526-
resolved "https://registry.yarnpkg.com/jsonc-parser/-/jsonc-parser-3.0.0.tgz#abdd785701c7e7eaca8a9ec8cf070ca51a745a22"
4527-
integrity sha512-fQzRfAbIBnR0IQvftw9FJveWiHp72Fg20giDrHz6TdfB12UH/uue0D3hm57UB5KgAVuniLMCaS8P1IMj9NR7cA==
4528-
45294501
jsonfile@^4.0.0:
45304502
version "4.0.0"
45314503
resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-4.0.0.tgz#8771aae0799b64076b76640fca058f9c10e33ecb"
@@ -6774,13 +6746,6 @@ strip-ansi@^4.0.0:
67746746
dependencies:
67756747
ansi-regex "^3.0.0"
67766748

6777-
strip-ansi@^5.2.0:
6778-
version "5.2.0"
6779-
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-5.2.0.tgz#8c9a536feb6afc962bdfa5b104a5091c1ad9c0ae"
6780-
integrity sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==
6781-
dependencies:
6782-
ansi-regex "^4.1.0"
6783-
67846749
strip-ansi@^6.0.0:
67856750
version "6.0.0"
67866751
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.0.tgz#0b1571dd7669ccd4f3e06e14ef1eed26225ae532"
@@ -7289,7 +7254,7 @@ uuid@^3.3.2:
72897254
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.4.0.tgz#b23e4358afa8a202fe7a100af1f5f883f02007ee"
72907255
integrity sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==
72917256

7292-
uuid@^8.3.0, uuid@^8.3.2:
7257+
uuid@^8.3.0:
72937258
version "8.3.2"
72947259
resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2"
72957260
integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==
@@ -7507,11 +7472,6 @@ xml-name-validator@^3.0.0:
75077472
resolved "https://registry.yarnpkg.com/xml-name-validator/-/xml-name-validator-3.0.0.tgz#6ae73e06de4d8c6e47f9fb181f78d648ad457c6a"
75087473
integrity sha512-A5CUptxDsvxKJEU3yO6DuWBSJz/qizqzJKOMIfUJHETbBw/sFaDxgd6fxm1ewUaM0jZ444Fc5vC5ROYurg/4Pw==
75097474

7510-
xml@^1.0.1:
7511-
version "1.0.1"
7512-
resolved "https://registry.yarnpkg.com/xml/-/xml-1.0.1.tgz#78ba72020029c5bc87b8a81a3cfcd74b4a2fc1e5"
7513-
integrity sha1-eLpyAgApxbyHuKgaPPzXS0ovweU=
7514-
75157475
xmlchars@^2.2.0:
75167476
version "2.2.0"
75177477
resolved "https://registry.yarnpkg.com/xmlchars/-/xmlchars-2.2.0.tgz#060fe1bcb7f9c76fe2a17db86a9bc3ab894210cb"

0 commit comments

Comments
 (0)