From baa453d9dce8ba1388a35342681ff07fa665f012 Mon Sep 17 00:00:00 2001 From: Christian Bromann Date: Tue, 24 May 2022 12:10:00 +0000 Subject: [PATCH] remove more jest stuff --- .gitpod.yml | 2 +- CONTRIBUTING.md | 12 +++---- __mocks__/@babel/register.ts | 3 +- __mocks__/csv-stringify/sync.ts | 3 +- jest.config.js | 59 --------------------------------- tsconfig.prod.json | 1 - 6 files changed, 11 insertions(+), 69 deletions(-) delete mode 100644 jest.config.js diff --git a/.gitpod.yml b/.gitpod.yml index a46537064..3760bafce 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -9,7 +9,7 @@ tasks: cd coverage/lcov-report/ http-server -p 8000 & cd ../../ - npx jest --watch + npx vitest - name: Run Documentation Page init: | cd /workspace/webdriverio/website diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9fbde2c7d..1447a8ea8 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -106,7 +106,7 @@ In order to set up this project and start contributing follow this step by step $ npm run test # run test for a specific sub project (e.g. webdriver) - $ npx jest ./packages/webdriver/tests --collectCoverage=false + $ npx vitest ./packages/webdriver/tests ``` It should give you a passing result. Now you can move on to set up your development environment and start working on some code. If tests do not pass please create an issue and provide logs to the error. @@ -126,10 +126,10 @@ If you only work on a single package, you can watch only for that one by calling $ npm run watch ``` -It is also a good idea to run jest in watch mode while developing on a single package to see if changes affect any tests: +It is also a good idea to run vitest in watch mode while developing on a single package to see if changes affect any tests: ```sh -npx jest ./packages//tests --watch --collectCoverage=false +npx vitest ./packages//tests ``` #### TypeScript Definitions @@ -188,7 +188,7 @@ When a PR gets submitted, WebdriverIO runs the following checks: ``` - *Unit Tests* Like every project we unit-test our code and ensure that new patches are properly tested. The coverage threshold is pretty high so ensure that - your changes cover all necessary code paths. We are using [Jest](https://jestjs.io/) as a unit test framework here. + your changes cover all necessary code paths. We are using [Vitest](https://vitest.dev/) as a unit test framework here. You can manually trigger this check by calling: ```sh $ npm run test:coverage @@ -225,12 +225,12 @@ are located in packages/webdriverio/tests/commands/element/getCSSProperty.test.ts ``` -If that is not the case the functionality of that file might be tested through a different file. We recommend to write unit tests for every new function being written in the code base. We advise to mock out every dependency to either other packages or modules using [Jests mock capabilities](https://jestjs.io/docs/manual-mocks). +If that is not the case the functionality of that file might be tested through a different file. We recommend to write unit tests for every new function being written in the code base. We advise to mock out every dependency to either other packages or modules using [Vitests mock capabilities](https://vitest.dev/guide/mocking.html). During development it makes sense to focus running unit tests for a single file rather the whole code base. For example if you work on the `getCSSProperty` command it makes sense to run only the unit test for that specific command by calling: ```sh -npx jest packages/webdriverio/tests/commands/element/getCSSProperty.test.ts --watch --collectCoverage=false +npx vitest packages/webdriverio/tests/commands/element/getCSSProperty.test.ts ``` With the `--watch` flag the unit tests will be re-run as soon as you change something within the file. diff --git a/__mocks__/@babel/register.ts b/__mocks__/@babel/register.ts index bbabe6d0d..8b6d68c97 100644 --- a/__mocks__/@babel/register.ts +++ b/__mocks__/@babel/register.ts @@ -1 +1,2 @@ -export default jest.fn() +import { vi } from 'vitest' +export default vi.fn() diff --git a/__mocks__/csv-stringify/sync.ts b/__mocks__/csv-stringify/sync.ts index 312da381a..193afdf11 100644 --- a/__mocks__/csv-stringify/sync.ts +++ b/__mocks__/csv-stringify/sync.ts @@ -1 +1,2 @@ -export const stringify = jest.requireActual('../../../node_modules/csv-stringify/dist/cjs/sync.cjs').stringify +import { vi } from 'vitest' +export const stringify = await vi.importActual('../../../node_modules/csv-stringify/dist/cjs/sync.cjs') diff --git a/jest.config.js b/jest.config.js deleted file mode 100644 index f31fd77bc..000000000 --- a/jest.config.js +++ /dev/null @@ -1,59 +0,0 @@ -const testPathIgnorePatterns = [ - '/tests/', - '/node_modules/' -] - -const coveragePathIgnorePatterns = [ - 'node_modules/', - 'packages/devtools/src/scripts', - 'packages/devtools/src/commands', - 'packages/webdriverio/src/scripts', - 'packages/wdio-devtools-service/src/scripts', - 'packages/webdriverio/build', - 'packages/webdriver/build', - 'packages/wdio-cucumber-framework/tests/fixtures', - 'packages/wdio-logger/build', - 'packages/wdio-webdriver-mock-service', - 'packages/wdio-smoke-test-reporter', - 'packages/wdio-smoke-test-service', - 'packages/eslint-plugin-wdio', -] - -module.exports = { - globals: { - 'ts-jest': { - isolatedModules: true - } - }, - exclude: [ - 'packages/wdio-logger/**/*.test.ts', - 'packages/wdio-utils/**/*.test.ts' - ], - testMatch: [ - '**/tests/**/*.test.(js|ts)' - ], - transform: { - '^.+\\.(ts|js)$': 'ts-jest' - }, - testPathIgnorePatterns, - collectCoverageFrom: [ - 'packages/**/src/**/*.(js|ts)', - '!packages/**/src/**/*.d.ts' - ], - moduleNameMapper: { - 'graceful-fs': '/tests/helpers/fs.js' - }, - coverageDirectory: './coverage/', - collectCoverage: true, - coverageThreshold: { - global: { - branches: 89, - functions: 94, - lines: 95, - statements: 95 - } - }, - testEnvironment: 'node', - coveragePathIgnorePatterns, - resolver: `${__dirname}/tests/resolver.js`, -} diff --git a/tsconfig.prod.json b/tsconfig.prod.json index 55bbc8bad..3fb0f55b5 100644 --- a/tsconfig.prod.json +++ b/tsconfig.prod.json @@ -22,7 +22,6 @@ "e2e/**/*", "coverage", "examples", - "jest.config.js", "/*.js" ] }