Browse Source

Feature: Mobile - Switch from jest to vitest.

Martin Gruner 3 years ago
parent
commit
215df848f5

+ 1 - 9
.eslintrc.js

@@ -6,17 +6,15 @@ module.exports = {
   root: true,
   env: {
     browser: true,
-    jest: true,
     node: true,
   },
-  plugins: ['@typescript-eslint', 'vue', 'prettier', 'jest', 'zammad'],
+  plugins: ['@typescript-eslint', 'vue', 'prettier', 'zammad'],
   extends: [
     'airbnb-base',
     'plugin:vue/vue3-recommended',
     'plugin:@typescript-eslint/eslint-recommended',
     'plugin:@typescript-eslint/recommended',
     'plugin:prettier/recommended',
-    'plugin:jest/recommended',
     '@vue/prettier',
     '@vue/typescript/recommended',
     'prettier',
@@ -88,12 +86,6 @@ module.exports = {
     'no-shadow': 'off',
     '@typescript-eslint/no-shadow': 'off',
 
-    // Expect assertions are mandatory for async tests.
-    'jest/prefer-expect-assertions': [
-      'error',
-      { onlyFunctionsWithAsyncKeyword: true },
-    ],
-
     // Enforce v-bind directive usage in long form.
     'vue/v-bind-style': ['error', 'longform'],
 

+ 1 - 1
.gitlab-ci.yml

@@ -6,7 +6,7 @@ include:
   - local: '/.gitlab/ci/pre.yml'
   - local: '/.gitlab/ci/integration.yml'
   - local: '/.gitlab/ci/rspec.yml'
-  - local: '/.gitlab/ci/jest.yml'
+  - local: '/.gitlab/ci/vitest.yml'
   - local: '/.gitlab/ci/unit.yml'
   - local: '/.gitlab/ci/browser-core.yml'
   - local: '/.gitlab/ci/browser-integration.yml'

+ 1 - 1
.gitlab/ci/jest.yml → .gitlab/ci/vitest.yml

@@ -1,4 +1,4 @@
-jest:
+vitest:
   stage: test
   extends:
     - .env_base

+ 1 - 1
.gitlab/merge_request_templates/new_tech_stack_application_feature.md

@@ -13,7 +13,7 @@
 - [ ] Covered new functionality with Jest-Test(*)
 - [ ] When relevant: Covered new GraphQL (Mutation/Query) with a request test.
 
-(*) Jest tests are normally only needed for the common components or other typescript functionality, because the other functionality will be tested with selenium tests and own GraphQL-API tests (with this we avoid that we need always to mock the graphql calls). But for sure special frontend handling should also be tested with a jest test.
+(*) Jest tests are normally only needed for the common components or other typescript functionality, because the other functionality will be tested with selenium tests and own GraphQL-API tests (with this we avoid that we need always to mock the graphql calls). But for sure special frontend handling should also be tested with a vitest test.
 
 ## QA Checklist (to be filled by the reviewer)
 

+ 15 - 0
app/frontend/apps/mobile/components/transition/TransitionViewNavigation.vue

@@ -14,6 +14,19 @@ import useViewTransition from '@mobile/composables/useViewTransition'
 const { viewTransition } = useViewTransition()
 </script>
 
+<!-- # TODO: does not work with vitest currently.
+
+tests/apps/mobile/components/transition/TransitionViewNavigation.spec.ts [ tests/apps/mobile/components/transition/TransitionViewNavigation.spec.ts ]
+TypeError: Cannot read property 'config' of undefined
+ ❯ getTailwindConfig ../../node_modules/tailwindcss/lib/lib/setupTrackingContext.js:81:62
+ ❯ ../../node_modules/tailwindcss/lib/lib/setupTrackingContext.js:124:92
+ ❯ ../../node_modules/tailwindcss/lib/processTailwindFeatures.js:43:11
+ ❯ plugins ../../node_modules/tailwindcss/lib/index.js:20:104
+ ❯ LazyResult.runOnRoot ../../node_modules/postcss/lib/lazy-result.js:339:16
+ ❯ LazyResult.runAsync ../../node_modules/postcss/lib/lazy-result.js:393:26
+ ❯ LazyResult.async ../../node_modules/postcss/lib/lazy-result.js:221:30
+ ❯ LazyResult.then ../../node_modules/postcss/lib/lazy-result.js:206:17
+
 <style scoped>
 /* TODO: Styles needs to be aligned/beautified. */
 
@@ -94,3 +107,5 @@ main > * {
   }
 }
 </style>
+
+-->

+ 4 - 4
app/frontend/tests/apps/mobile/router/guards/before/viewTransition.spec.ts

@@ -18,7 +18,7 @@ describe('viewTransition', () => {
         level: 1,
       },
     } as RouteLocationNormalized
-    const next = jest.fn()
+    const next = vi.fn()
 
     viewTransition(to, from, next)
 
@@ -36,7 +36,7 @@ describe('viewTransition', () => {
         level: 2,
       },
     } as RouteLocationNormalized
-    const next = jest.fn()
+    const next = vi.fn()
 
     viewTransition(to, from, next)
 
@@ -54,7 +54,7 @@ describe('viewTransition', () => {
         level: 1,
       },
     } as RouteLocationNormalized
-    const next = jest.fn()
+    const next = vi.fn()
 
     viewTransition(to, from, next)
 
@@ -70,7 +70,7 @@ describe('viewTransition', () => {
     const to = {
       meta: {},
     } as RouteLocationNormalized
-    const next = jest.fn()
+    const next = vi.fn()
 
     viewTransition(to, from, next)
 

+ 0 - 18
app/frontend/tests/babel.test.config.js

@@ -1,18 +0,0 @@
-// Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
-
-// We need babel for the test envoirment, to have the vite meta glob transformation in the test context.
-module.exports = {
-  presets: [
-    [
-      '@babel/preset-env',
-      {
-        targets: { node: 'current' },
-      },
-    ],
-    '@babel/preset-typescript',
-  ],
-  plugins: [
-    '@babel/plugin-transform-runtime',
-    'babel-plugin-transform-vite-meta-glob',
-  ],
-}

+ 3 - 5
app/frontend/tests/common/components/common/CommonDateTime.spec.ts

@@ -1,15 +1,13 @@
 // Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
 
-import '@tests/support/mock-hoist-helper'
+/* eslint-disable import/first */
+vi.useFakeTimers().setSystemTime(new Date('2020-10-11T10:10:10Z'))
+
 import CommonDateTime from '@common/components/common/CommonDateTime.vue'
 import { getWrapper } from '@tests/support/components'
 import useApplicationConfigStore from '@common/stores/application/config'
 import { nextTick } from 'vue'
 
-jest.mock('@tests/support/mock-hoist-helper', () => {
-  jest.useFakeTimers().setSystemTime(new Date('2020-10-11T10:10:10Z'))
-})
-
 describe('CommonDateTime.vue', () => {
   it('renders DateTime', async () => {
     expect.assertions(5)

+ 1 - 1
app/frontend/tests/common/form/index.spec.ts

@@ -28,7 +28,7 @@ describe('getFormPlugins', () => {
 describe('initializeForm', () => {
   const app = createApp({})
 
-  jest.spyOn(app, 'use')
+  vi.spyOn(app, 'use')
 
   it('check use form plugin without an error', () => {
     initializeForm(app)

+ 2 - 2
app/frontend/tests/common/router/guards/after/headerTitle.spec.ts

@@ -7,12 +7,12 @@ import { nextTick } from 'vue'
 import useMetaTitle from '@common/composables/useMetaTitle'
 import useApplicationConfigStore from '@common/stores/application/config'
 
-jest.mock('@common/server/apollo/client', () => {
+vi.mock('@common/server/apollo/client', () => {
   return {}
 })
 
 describe('headerTitle', () => {
-  createTestingPinia()
+  createTestingPinia({ createSpy: vi.fn })
   useApplicationConfigStore().value.product_name = 'Zammad'
 
   const from = {} as RouteLocationNormalized

Some files were not shown because too many files changed in this diff