diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..3cea6e5 --- /dev/null +++ b/.github/workflows/tests.yml @@ -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/jest-coverage-report-action@v2.0-rc.1 + 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 diff --git a/.gitignore b/.gitignore index 2428c1b..efc986d 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ dist coverage/ junit.xml *.tgz +report.json \ No newline at end of file diff --git a/jest.config.ts b/jest.config.ts index f333e4f..dbfe2f1 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -14,9 +14,9 @@ const config: Config.InitialOptions = { roots: ['/test'], moduleNameMapper, testEnvironment: 'jest-environment-jsdom', - reporters: ['default', 'jest-junit'], collectCoverage: true, - coverageReporters: ['json', 'text', 'cobertura'], + coverageReporters: ['json'], + testLocationInResults: true, setupFilesAfterEnv: ['/test/__setup__/console.ts'], }; diff --git a/package.json b/package.json index e39714d..d6c1f3d 100644 --- a/package.json +++ b/package.json @@ -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": { @@ -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", diff --git a/renovate.json b/renovate.json index f45d8f1..4f39080 100644 --- a/renovate.json +++ b/renovate.json @@ -1,5 +1,3 @@ { - "extends": [ - "config:base" - ] + "extends": ["config:base"] } diff --git a/rollup.config.js b/rollup.config.js deleted file mode 100644 index e08ea54..0000000 --- a/rollup.config.js +++ /dev/null @@ -1,3 +0,0 @@ -/* eslint-disable no-global-assign */ -require('esbuild-register'); -module.exports = require('./rollup.config.ts'); diff --git a/src/useFind.ts b/src/useFind.ts index b3cb5b2..b25b754 100644 --- a/src/useFind.ts +++ b/src/useFind.ts @@ -8,10 +8,10 @@ function loadServiceEventHandlers< CustomApplication extends Application, T extends keyof ServiceTypes, M, - >( - service: FeathersService[T]>, - params: Ref, - data: Ref, +>( + service: FeathersService[T]>, + params: Ref, + data: Ref, ): () => void { const onCreated = (item: M): void => { // ignore items which are not matching the query @@ -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); }; @@ -67,7 +75,7 @@ export type UseFind = { export type UseFindFunc = < T extends keyof ServiceTypes, M = ServiceModel, - >( +>( serviceName: T, params?: Ref, ) => UseFind; diff --git a/src/useGet.ts b/src/useGet.ts index 6694b1a..1b37b44 100644 --- a/src/useGet.ts +++ b/src/useGet.ts @@ -7,10 +7,10 @@ function loadServiceEventHandlers< CustomApplication extends Application, T extends keyof ServiceTypes, M, - >( - service: FeathersService[T]>, - _id: Ref, - data: Ref, +>( + service: FeathersService[T]>, + _id: Ref, + data: Ref, ): () => void { const onCreated = (item: M): void => { if (_id.value === getId(item)) { @@ -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); }; @@ -54,7 +62,7 @@ export type UseGet = { export type UseGetFunc = < T extends keyof ServiceTypes, M = ServiceModel, - >( +>( serviceName: T, _id: Ref, ) => UseGet; diff --git a/yarn.lock b/yarn.lock index 22b3861..d18008a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" @@ -2612,15 +2607,7 @@ es-to-primitive@^1.2.1: is-date-object "^1.0.1" is-symbol "^1.0.2" -esbuild-register@2.6.0: - 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" - -esbuild@0.12.9, esbuild@^0.12.8: +esbuild@0.12.9: version "0.12.9" resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.12.9.tgz#bed4e7087c286cd81d975631f77d47feb1660070" integrity sha512-MWRhAbMOJ9RJygCrt778rz/qNYgA4ZVj6aXnNPxFjs7PmIpb0fuB9Gmg5uWrr6n++XKwwm/RmSz6RR5JL2Ocsw== @@ -4168,16 +4155,6 @@ jest-jasmine2@^26.6.3: pretty-format "^26.6.2" throat "^5.0.0" -jest-junit@12.2.0: - 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" @@ -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" @@ -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" @@ -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== @@ -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"