Testing preparation

This commit is contained in:
James Lyne 2021-09-10 15:32:48 +01:00
parent 287de1f960
commit 5d133de1e9
8 changed files with 10397 additions and 134 deletions

19
jest.config.ts Normal file
View File

@ -0,0 +1,19 @@
export default {
preset: 'ts-jest',
moduleFileExtensions: [
'js',
'ts',
'json',
'vue'
],
transform: {
'^.+\\.ts$': 'ts-jest',
'^.+\\.vue$': 'vue-jest'
},
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1',
},
setupFilesAfterEnv: [
'<rootDir>/tests/setup.ts'
]
}

10425
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -5,6 +5,7 @@
"scripts": { "scripts": {
"serve": "vite", "serve": "vite",
"preview": "vite preview --port 8082", "preview": "vite preview --port 8082",
"test": "jest",
"build": "vue-tsc --noEmit && vite build --out-dir dist", "build": "vue-tsc --noEmit && vite build --out-dir dist",
"lint": "eslint --ext .ts,.vue src", "lint": "eslint --ext .ts,.vue src",
"lint:fix": "eslint -ext .ts,.vue src --fix", "lint:fix": "eslint -ext .ts,.vue src --fix",
@ -19,20 +20,27 @@
"vuex": "^4.0" "vuex": "^4.0"
}, },
"devDependencies": { "devDependencies": {
"@types/jest": "^27.0.1",
"@types/leaflet": "1.7.5", "@types/leaflet": "1.7.5",
"@types/node": "^16.9.1",
"@typescript-eslint/eslint-plugin": "^4.31", "@typescript-eslint/eslint-plugin": "^4.31",
"@typescript-eslint/parser": "^4.31", "@typescript-eslint/parser": "^4.31",
"@vitejs/plugin-vue": "^1.6", "@vitejs/plugin-vue": "^1.6",
"@vue/compiler-sfc": "^3.2.10", "@vue/compiler-sfc": "^3.2.10",
"@vue/eslint-config-typescript": "^7.0", "@vue/eslint-config-typescript": "^7.0",
"@vue/test-utils": "^2.0.0-rc.14",
"eslint": "^7.32", "eslint": "^7.32",
"eslint-plugin-vue": "^7.17", "eslint-plugin-vue": "^7.17",
"jest": "^26.6.3",
"patch-package": "^6.4", "patch-package": "^6.4",
"rollup-plugin-analyzer": "^4.0", "rollup-plugin-analyzer": "^4.0",
"sass": "^1.39", "sass": "^1.39",
"ts-jest": "^26.5.6",
"ts-node": "^10.2.1",
"typescript": "^4.4", "typescript": "^4.4",
"vite": "^2.5", "vite": "^2.5",
"vite-plugin-svg-sprite-component": "^1.0", "vite-plugin-svg-sprite-component": "^1.0",
"vue-jest": "^5.0.0-alpha.10",
"vue-tsc": "0.3.0" "vue-tsc": "0.3.0"
}, },
"eslintConfig": { "eslintConfig": {

10
src/index.d.ts vendored
View File

@ -38,6 +38,16 @@ declare global {
interface Window { interface Window {
liveAtlasConfig: LiveAtlasGlobalConfig, liveAtlasConfig: LiveAtlasGlobalConfig,
} }
declare const process : {
env: {
VITE_VERSION: string
}
}
}
export interface ProcessEnv {
[key: string]: string | undefined
} }
interface Coordinate { interface Coordinate {

View File

@ -91,7 +91,7 @@ export type State = {
} }
export const state: State = { export const state: State = {
version: (import.meta.env.VITE_VERSION || 'Unknown') as string, version: (process.env.VITE_VERSION || 'Unknown') as string,
servers: new Map(), servers: new Map(),
configuration: { configuration: {

4
tests/setup.ts Normal file
View File

@ -0,0 +1,4 @@
console.warn = jest.fn();
export {}

View File

@ -16,7 +16,8 @@
"baseUrl": ".", "baseUrl": ".",
"types": [ "types": [
"vite/client", "vite/client",
"vue" "vue",
"jest"
], ],
"paths": { "paths": {
"@/*": [ "@/*": [
@ -32,10 +33,8 @@
}, },
"include": [ "include": [
"src/**/*.ts", "src/**/*.ts",
"src/**/*.tsx",
"src/**/*.vue", "src/**/*.vue",
"tests/**/*.ts", "tests/**/*.ts"
"tests/**/*.tsx"
], ],
"exclude": [ "exclude": [
"node_modules" "node_modules"

View File

@ -1,30 +1,46 @@
// noinspection JSUnusedGlobalSymbols // noinspection JSUnusedGlobalSymbols
import { defineConfig } from 'vite'; import {defineConfig, loadEnv} from 'vite';
import { resolve } from 'path'; import { resolve } from 'path';
import vue from '@vitejs/plugin-vue'; import vue from '@vitejs/plugin-vue';
import svgSpritePlugin from "vite-plugin-svg-sprite-component"; import svgSpritePlugin from "vite-plugin-svg-sprite-component";
import analyze from 'rollup-plugin-analyzer'; import analyze from 'rollup-plugin-analyzer';
export default defineConfig({ export default defineConfig(({ mode }) => {
plugins: [vue(), analyze(), svgSpritePlugin({ const env = loadEnv(mode, process.cwd())
symbolId: (name) => `icon--${name}`,
})], // expose .env as process.env instead of import.meta since jest does not import meta yet
base: './', const envWithProcessPrefix = Object.entries(env).reduce(
server: { (prev, [key, val]) => {
host: '0.0.0.0', return {
port: 8080 ...prev,
}, ['process.env.' + key]: `"${val}"`,
resolve: {
alias: [
{
find: '@',
replacement: resolve(__dirname, 'src')
} }
] },
}, {},
build: { );
chunkSizeWarningLimit: 600,
assetsDir: 'live-atlas/assets' return {
plugins: [vue(), analyze(), svgSpritePlugin({
symbolId: (name) => `icon--${name}`,
})],
base: './',
server: {
host: '0.0.0.0',
port: 8080
},
resolve: {
alias: [
{
find: '@',
replacement: resolve(__dirname, 'src')
}
]
},
build: {
chunkSizeWarningLimit: 600,
assetsDir: 'live-atlas/assets'
},
define: envWithProcessPrefix,
} }
}); });