Browse Source

finalize jest setup and config

Olivier Massot 4 years ago
parent
commit
c12c73b678
7 changed files with 39 additions and 20 deletions
  1. 10 5
      jest.config.js
  2. 1 0
      package.json
  3. 0 6
      tests/unit/index.ts
  4. 15 0
      tests/unit/jest.setup.ts
  5. 0 9
      tests/unit/pages/structures/index.spec.js
  6. 1 0
      tsconfig.json
  7. 12 0
      yarn.lock

+ 10 - 5
jest.config.js

@@ -3,7 +3,8 @@ module.exports = {
   moduleNameMapper: {
     '^@/(.*)$': '<rootDir>/$1',
     '^~/(.*)$': '<rootDir>/$1',
-    '^vue$': 'vue/dist/vue.common.js'
+    '^vue$': 'vue/dist/vue.common.js',
+    '\\.(css|sass)$': 'identity-obj-proxy'
   },
   moduleFileExtensions: [
     'ts',
@@ -19,9 +20,13 @@ module.exports = {
   collectCoverage: true,
   collectCoverageFrom: [
     '<rootDir>/components/**/*.vue',
-    '<rootDir>/pages/**/*.vue'
+    '<rootDir>/pages/**/*.vue',
+    '<rootDir>/services/**/*.ts'
   ],
-  testEnvironment: 'jsdom',
-  testMatch: ['**/tests/unit/**/*.spec.js'],
-  setupFiles: ['<rootDir>/tests/unit/index.ts']
+  setupFiles: ['<rootDir>/tests/unit/jest.setup.ts'],
+  testPathIgnorePatterns: [
+    'node_modules',
+    'tests/cypress'
+  ],
+  testEnvironment: 'jsdom'
 }

+ 1 - 0
package.json

@@ -54,6 +54,7 @@
     "eslint-plugin-cypress": "^2.12.1",
     "eslint-plugin-nuxt": "^2.0.0",
     "eslint-plugin-vue": "^7.12.1",
+    "identity-obj-proxy": "^3.0.0",
     "jest": "^27.0.5",
     "ts-jest": "^27.0.3",
     "vue-jest": "^3.0.4"

+ 0 - 6
tests/unit/index.ts

@@ -1,6 +0,0 @@
-import Vuex from 'vuex'
-import Vue from 'vue'
-import Vuetify from 'vuetify'
-
-Vue.use(Vuetify)
-Vue.use(Vuex)

+ 15 - 0
tests/unit/jest.setup.ts

@@ -0,0 +1,15 @@
+import Vuex from 'vuex'
+import Vue from 'vue'
+import Vuetify from 'vuetify'
+import { config } from '@vue/test-utils'
+
+Vue.config.silent = true
+
+// Mock Nuxt components
+config.stubs['nuxt-link'] = true // string stabs like '<a><slot /></a>' are now depreciated
+config.stubs['no-ssr'] = true
+config.mocks.$t = (i: any) => i
+config.mocks.localePath = (i: any) => i
+
+Vue.use(Vuetify)
+Vue.use(Vuex)

+ 0 - 9
tests/unit/pages/structures/index.spec.js

@@ -1,9 +0,0 @@
-import Vuetify from 'vuetify'
-
-let vuetify
-beforeEach(() => {
-  vuetify = new Vuetify()
-})
-
-describe('pages/structures/index.vue', () => {
-})

+ 1 - 0
tsconfig.json

@@ -25,6 +25,7 @@
     },
     "types": [
       "@nuxt/types",
+      "@types/jest",
       "@nuxtjs/i18n",
       "nuxt-leaflet",
       "@nuxtjs/axios",

+ 12 - 0
yarn.lock

@@ -6311,6 +6311,11 @@ hard-source-webpack-plugin@^0.13.1:
     webpack-sources "^1.0.1"
     write-json-file "^2.3.0"
 
+harmony-reflect@^1.4.6:
+  version "1.6.2"
+  resolved "https://registry.yarnpkg.com/harmony-reflect/-/harmony-reflect-1.6.2.tgz#31ecbd32e648a34d030d86adb67d4d47547fe710"
+  integrity sha512-HIp/n38R9kQjDEziXyDTuW3vvoxxyxjxFzXLrBr18uB47GnSt+G9D29fqrpM5ZkspMcPICud3XsBJQ4Y2URg8g==
+
 has-ansi@^2.0.0:
   version "2.0.0"
   resolved "https://registry.npmjs.org/has-ansi/-/has-ansi-2.0.0.tgz"
@@ -6627,6 +6632,13 @@ icss-utils@^4.0.0, icss-utils@^4.1.1:
   dependencies:
     postcss "^7.0.14"
 
+identity-obj-proxy@^3.0.0:
+  version "3.0.0"
+  resolved "https://registry.yarnpkg.com/identity-obj-proxy/-/identity-obj-proxy-3.0.0.tgz#94d2bda96084453ef36fbc5aaec37e0f79f1fc14"
+  integrity sha1-lNK9qWCERT7zb7xarsN+D3nx/BQ=
+  dependencies:
+    harmony-reflect "^1.4.6"
+
 ieee754@^1.1.13, ieee754@^1.1.4:
   version "1.2.1"
   resolved "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz"