Skip to content

Commit

Permalink
ci: add some tests (#36)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
anbraten and lukashass authored Aug 6, 2021
1 parent 75ae285 commit ea606a2
Show file tree
Hide file tree
Showing 9 changed files with 173 additions and 66 deletions.
135 changes: 135 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
name: Tests

on:
pull_request:
branches:
- main
push:
branches:
- main

env:
YARN_CACHE_FOLDER: ~/.yarn

jobs:
unit-tests:
name: Unit tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: 12

- name: Caching
uses: actions/cache@v2
with:
path: ${{ env.YARN_CACHE_FOLDER }}
key: ${{ runner.OS }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.OS }}-yarn-${{ env.cache-name }}
${{ runner.OS }}-yarn-
- name: Installing dependencies
run: yarn install --frozen-lockfile

- name: Unit test
run: yarn test

- uses: artiomtr/[email protected]
if: "github.event_name == 'pull_request'"
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
skip-step: all

typecheck:
name: Typecheck
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: 12

- name: Caching
uses: actions/cache@v2
with:
path: ${{ env.YARN_CACHE_FOLDER }}
key: ${{ runner.OS }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.OS }}-yarn-${{ env.cache-name }}
${{ runner.OS }}-yarn-
- name: Installing dependencies
run: yarn install --frozen-lockfile

- name: Typecheck
run: yarn typecheck

lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: 12

- name: Caching
uses: actions/cache@v2
with:
path: ${{ env.YARN_CACHE_FOLDER }}
key: ${{ runner.OS }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.OS }}-yarn-${{ env.cache-name }}
${{ runner.OS }}-yarn-
- name: Installing dependencies
run: yarn install --frozen-lockfile

- name: Lint
run: yarn lint

check-format:
name: Check format
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: 12

- name: Caching
uses: actions/cache@v2
with:
path: ${{ env.YARN_CACHE_FOLDER }}
key: ${{ runner.OS }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.OS }}-yarn-${{ env.cache-name }}
${{ runner.OS }}-yarn-
- name: Installing dependencies
run: yarn install --frozen-lockfile

- name: Check format
run: yarn lint:format
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ dist
coverage/
junit.xml
*.tgz
report.json
4 changes: 2 additions & 2 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ const config: Config.InitialOptions = {
roots: ['<rootDir>/test'],
moduleNameMapper,
testEnvironment: 'jest-environment-jsdom',
reporters: ['default', 'jest-junit'],
collectCoverage: true,
coverageReporters: ['json', 'text', 'cobertura'],
coverageReporters: ['json'],
testLocationInResults: true,
setupFilesAfterEnv: ['<rootDir>/test/__setup__/console.ts'],
};

Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
"/dist"
],
"scripts": {
"build": "rollup -c rollup.config.js",
"build": "rollup -c rollup.config.ts --configPlugin rollup-plugin-typescript2",
"clean": "rm -rf dist/ node_modules/",
"lint": "prettier --check . && eslint --max-warnings 0 .",
"start": "rollup -c rollup.config.js --watch",
"test": "NODE_OPTIONS=--experimental-vm-modules jest --forceExit --detectOpenHandles",
"lint": "eslint --max-warnings 0 .",
"lint:format": "prettier --check .",
"start": "yarn build --watch",
"test": "NODE_OPTIONS=--experimental-vm-modules jest --forceExit --detectOpenHandles --testLocationInResults --json --outputFile=report.json",
"test:watch": "yarn test --watch",
"typecheck": "tsc --noEmit",
"release": "semantic-release"
},
"dependencies": {
Expand All @@ -43,10 +45,8 @@
"@types/node": "15.12.4",
"@vue/test-utils": "2.0.0-rc.6",
"esbuild": "0.12.9",
"esbuild-register": "2.6.0",
"eslint": "7.29.0",
"jest": "26.6.3",
"jest-junit": "12.2.0",
"prettier": "2.3.1",
"rollup": "2.52.2",
"rollup-plugin-dts": "3.0.2",
Expand Down
4 changes: 1 addition & 3 deletions renovate.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{
"extends": [
"config:base"
]
"extends": ["config:base"]
}
3 changes: 0 additions & 3 deletions rollup.config.js

This file was deleted.

18 changes: 13 additions & 5 deletions src/useFind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ function loadServiceEventHandlers<
CustomApplication extends Application,
T extends keyof ServiceTypes<CustomApplication>,
M,
>(
service: FeathersService<CustomApplication, ServiceTypes<CustomApplication>[T]>,
params: Ref<Params>,
data: Ref<M[]>,
>(
service: FeathersService<CustomApplication, ServiceTypes<CustomApplication>[T]>,
params: Ref<Params>,
data: Ref<M[]>,
): () => void {
const onCreated = (item: M): void => {
// ignore items which are not matching the query
Expand Down Expand Up @@ -43,15 +43,23 @@ function loadServiceEventHandlers<
});
};

// eslint-disable-next-line @typescript-eslint/no-unsafe-call
service.on('created', onCreated);
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
service.on('removed', onRemoved);
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
service.on('patched', onItemChanged);
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
service.on('updated', onItemChanged);

const unloadEventHandlers = () => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
service.off('created', onCreated);
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
service.off('removed', onRemoved);
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
service.off('patched', onItemChanged);
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
service.off('updated', onItemChanged);
};

Expand All @@ -67,7 +75,7 @@ export type UseFind<T> = {
export type UseFindFunc<CustomApplication> = <
T extends keyof ServiceTypes<CustomApplication>,
M = ServiceModel<CustomApplication, T>,
>(
>(
serviceName: T,
params?: Ref<Params>,
) => UseFind<M>;
Expand Down
18 changes: 13 additions & 5 deletions src/useGet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ function loadServiceEventHandlers<
CustomApplication extends Application,
T extends keyof ServiceTypes<CustomApplication>,
M,
>(
service: FeathersService<CustomApplication, ServiceTypes<CustomApplication>[T]>,
_id: Ref<Id | undefined>,
data: Ref<M | undefined>,
>(
service: FeathersService<CustomApplication, ServiceTypes<CustomApplication>[T]>,
_id: Ref<Id | undefined>,
data: Ref<M | undefined>,
): () => void {
const onCreated = (item: M): void => {
if (_id.value === getId(item)) {
Expand All @@ -30,15 +30,23 @@ function loadServiceEventHandlers<
}
};

// eslint-disable-next-line @typescript-eslint/no-unsafe-call
service.on('created', onCreated);
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
service.on('removed', onRemoved);
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
service.on('patched', onItemChanged);
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
service.on('updated', onItemChanged);

const unloadEventHandlers = () => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
service.off('created', onCreated);
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
service.off('removed', onRemoved);
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
service.off('patched', onItemChanged);
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
service.off('updated', onItemChanged);
};

Expand All @@ -54,7 +62,7 @@ export type UseGet<T> = {
export type UseGetFunc<CustomApplication> = <
T extends keyof ServiceTypes<CustomApplication>,
M = ServiceModel<CustomApplication, T>,
>(
>(
serviceName: T,
_id: Ref<Id | undefined>,
) => UseGet<M>;
Expand Down
44 changes: 2 additions & 42 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1422,11 +1422,6 @@ ansi-regex@^3.0.0:
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-3.0.0.tgz#ed0317c322064f79466c02966bddb605ab37d998"
integrity sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=

ansi-regex@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-4.1.0.tgz#8b9f8f08cf1acb843756a839ca8c7e3168c51997"
integrity sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==

ansi-regex@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.0.tgz#388539f55179bf39339c81af30a654d69f87cb75"
Expand Down Expand Up @@ -2612,15 +2607,7 @@ es-to-primitive@^1.2.1:
is-date-object "^1.0.1"
is-symbol "^1.0.2"

[email protected]:
version "2.6.0"
resolved "https://registry.yarnpkg.com/esbuild-register/-/esbuild-register-2.6.0.tgz#9f19a54c82be751dd87673d6a66d7b9e1cdd8498"
integrity sha512-2u4AtnCXP5nivtIxZryiZOUcEQkOzFS7UhAqibUEmaTAThJ48gDLYTBF/Fsz+5r0hbV1jrFE6PQvPDUrKZNt/Q==
dependencies:
esbuild "^0.12.8"
jsonc-parser "^3.0.0"

[email protected], esbuild@^0.12.8:
[email protected]:
version "0.12.9"
resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.12.9.tgz#bed4e7087c286cd81d975631f77d47feb1660070"
integrity sha512-MWRhAbMOJ9RJygCrt778rz/qNYgA4ZVj6aXnNPxFjs7PmIpb0fuB9Gmg5uWrr6n++XKwwm/RmSz6RR5JL2Ocsw==
Expand Down Expand Up @@ -4168,16 +4155,6 @@ jest-jasmine2@^26.6.3:
pretty-format "^26.6.2"
throat "^5.0.0"

[email protected]:
version "12.2.0"
resolved "https://registry.yarnpkg.com/jest-junit/-/jest-junit-12.2.0.tgz#cff7f9516e84f8e30f6bdea04cd84db6b095a376"
integrity sha512-ecGzF3KEQwLbMP5xMO7wqmgmyZlY/5yWDvgE/vFa+/uIT0KsU5nluf0D2fjIlOKB+tb6DiuSSpZuGpsmwbf7Fw==
dependencies:
mkdirp "^1.0.4"
strip-ansi "^5.2.0"
uuid "^8.3.2"
xml "^1.0.1"

jest-leak-detector@^26.6.2:
version "26.6.2"
resolved "https://registry.yarnpkg.com/jest-leak-detector/-/jest-leak-detector-26.6.2.tgz#7717cf118b92238f2eba65054c8a0c9c653a91af"
Expand Down Expand Up @@ -4521,11 +4498,6 @@ jsonc-eslint-parser@^0.6.2:
eslint-visitor-keys "^1.3.0"
espree "^6.0.0 || ^7.2.0"

jsonc-parser@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/jsonc-parser/-/jsonc-parser-3.0.0.tgz#abdd785701c7e7eaca8a9ec8cf070ca51a745a22"
integrity sha512-fQzRfAbIBnR0IQvftw9FJveWiHp72Fg20giDrHz6TdfB12UH/uue0D3hm57UB5KgAVuniLMCaS8P1IMj9NR7cA==

jsonfile@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-4.0.0.tgz#8771aae0799b64076b76640fca058f9c10e33ecb"
Expand Down Expand Up @@ -6774,13 +6746,6 @@ strip-ansi@^4.0.0:
dependencies:
ansi-regex "^3.0.0"

strip-ansi@^5.2.0:
version "5.2.0"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-5.2.0.tgz#8c9a536feb6afc962bdfa5b104a5091c1ad9c0ae"
integrity sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==
dependencies:
ansi-regex "^4.1.0"

strip-ansi@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.0.tgz#0b1571dd7669ccd4f3e06e14ef1eed26225ae532"
Expand Down Expand Up @@ -7289,7 +7254,7 @@ uuid@^3.3.2:
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.4.0.tgz#b23e4358afa8a202fe7a100af1f5f883f02007ee"
integrity sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==

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

xml@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/xml/-/xml-1.0.1.tgz#78ba72020029c5bc87b8a81a3cfcd74b4a2fc1e5"
integrity sha1-eLpyAgApxbyHuKgaPPzXS0ovweU=

xmlchars@^2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/xmlchars/-/xmlchars-2.2.0.tgz#060fe1bcb7f9c76fe2a17db86a9bc3ab894210cb"
Expand Down

0 comments on commit ea606a2

Please sign in to comment.