Switch tests to vitest

This commit is contained in:
James Lyne 2022-06-21 23:26:32 +01:00
parent 4d0e481f74
commit 73a31c090c
9 changed files with 1706 additions and 589 deletions

1
.gitignore vendored
View File

@ -15,3 +15,4 @@ pnpm-debug.log*
# Editor directories and files # Editor directories and files
/.cache/ /.cache/
/coverage/

View File

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

1593
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -5,7 +5,8 @@
"scripts": { "scripts": {
"serve": "vite", "serve": "vite",
"preview": "vite preview --port 8082", "preview": "vite preview --port 8082",
"test": "jest", "test": "vitest",
"coverage": "vitest run --coverage",
"clean": "rimraf dist java/target/resources", "clean": "rimraf dist java/target/resources",
"copy": "cpy plugin.yml dist java/target/resources --parents && rimraf java/target/resources/assets/*.svg", "copy": "cpy plugin.yml dist java/target/resources --parents && rimraf java/target/resources/assets/*.svg",
"build": "npm run clean && vue-tsc --noEmit && vite build --out-dir dist && npm-run-all copy mvn", "build": "npm run clean && vue-tsc --noEmit && vite build --out-dir dist && npm-run-all copy mvn",
@ -25,8 +26,6 @@
}, },
"devDependencies": { "devDependencies": {
"@types/dynmap": "^3.1.1", "@types/dynmap": "^3.1.1",
"@types/jest": "^27.4.1",
"@types/jest-in-case": "^1.0.6",
"@types/leaflet": "1.7.11", "@types/leaflet": "1.7.11",
"@types/lodash.debounce": "^4.0.7", "@types/lodash.debounce": "^4.0.7",
"@types/node": "^18.0.0", "@types/node": "^18.0.0",
@ -37,21 +36,20 @@
"@vue/eslint-config-typescript": "^10.0", "@vue/eslint-config-typescript": "^10.0",
"@vue/test-utils": "^2.0.0", "@vue/test-utils": "^2.0.0",
"@vue/vue3-jest": "^27.0.0", "@vue/vue3-jest": "^27.0.0",
"c8": "^7.11.3",
"cpy-cli": "^4.1.0", "cpy-cli": "^4.1.0",
"eslint": "^8.17", "eslint": "^8.17",
"eslint-plugin-vue": "^8.7", "eslint-plugin-vue": "^8.7",
"jest": "^27.5.1",
"jest-in-case": "^1.0.2",
"npm-run-all": "^4.1.5", "npm-run-all": "^4.1.5",
"patch-package": "^6.4", "patch-package": "^6.4",
"rimraf": "^3.0.2", "rimraf": "^3.0.2",
"rollup-plugin-analyzer": "^4.0", "rollup-plugin-analyzer": "^4.0",
"sass": "^1.52", "sass": "^1.52",
"ts-jest": "^27.1.4",
"ts-node": "^10.8.1", "ts-node": "^10.8.1",
"typescript": "^4.7", "typescript": "^4.7",
"vite": "2.9.12", "vite": "2.9.12",
"vite-plugin-svg-sprite-component": "^1.0", "vite-plugin-svg-sprite-component": "^1.0",
"vitest": "^0.15.2",
"vue-tsc": "0.37.9" "vue-tsc": "0.37.9"
}, },
"eslintConfig": { "eslintConfig": {

323
test/util.test.ts Normal file
View File

@ -0,0 +1,323 @@
/*
* Copyright 2022 James Lyne
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {parseUrl} from "@/util";
import {LiveAtlasParsedUrl} from "@/index";
const validURLs: [string, URL, LiveAtlasParsedUrl][] = [
[
'Dynmap - complete',
new URL('https://minecraft.rtgame.co.uk/build?worldname=world&mapname=surface&zoom=4&x=6885&y=64&z=24608'),
{
world: 'world',
map: 'surface',
location: {x: 6885, y: 64, z: 24608},
zoom: 4,
legacy: true
}
],
[
'Dynmap - no location',
new URL('https://minecraft.rtgame.co.uk/build?worldname=world&mapname=surface&zoom=4'),
{
world: 'world',
map: 'surface',
location: undefined,
zoom: 4,
legacy: true
}
],
[
'Dynmap - no zoom',
new URL('https://minecraft.rtgame.co.uk/build?worldname=world&mapname=surface&x=6885&y=64&z=24608'),
{
world: 'world',
map: 'surface',
location: {x: 6885, y: 64, z: 24608},
zoom: undefined,
legacy: true
}
],
[
'Dynmap - no zoom or location',
new URL('https://minecraft.rtgame.co.uk/build?worldname=world&mapname=surface'),
{
world: 'world',
map: 'surface',
location: undefined,
zoom: undefined,
legacy: true
}
],
[
'Dynmap - no map, zoom or location',
new URL('https://minecraft.rtgame.co.uk/build?worldname=world'),
{
world: 'world',
map: undefined,
location: undefined,
zoom: undefined,
legacy: true
}
],
[
'Pl3xmap - complete',
new URL('https://minecraft.rtgame.co.uk/build?world=world&zoom=4&x=6885&y=64&z=24608'),
{
world: 'world',
map: undefined,
location: {x: 6885, y: 64, z: 24608},
zoom: 4,
legacy: true
}
],
[
'Pl3xmap - no location',
new URL('https://minecraft.rtgame.co.uk/build?world=world&zoom=4'),
{
world: 'world',
map: undefined,
location: undefined,
zoom: 4,
legacy: true
}
],
[
'Pl3xmap - no zoom',
new URL('https://minecraft.rtgame.co.uk/build?world=world&x=6885&y=64&z=24608'),
{
world: 'world',
map: undefined,
location: {x: 6885, y: 64, z: 24608},
zoom: undefined,
legacy: true
}
],
[
'Pl3xmap - no zoom or location',
new URL('https://minecraft.rtgame.co.uk/build?world=world'),
{
world: 'world',
map: undefined,
location: undefined,
zoom: undefined,
legacy: true
}
],
[
'LiveAtlas - complete',
new URL('https://minecraft.rtgame.co.uk/map/survival#world;flat;168,64,1914;2'),
{
world: 'world',
map: 'flat',
location: {x: 168, y: 64, z: 1914},
zoom: 2,
legacy: false
}
],
[
'LiveAtlas - no zoom',
new URL('https://minecraft.rtgame.co.uk/map/survival#world;flat;168,64,1914'),
{
world: 'world',
map: 'flat',
location: {x: 168, y: 64, z: 1914},
zoom: undefined,
legacy: false
}
],
[
'LiveAtlas - no location or zoom',
new URL('https://minecraft.rtgame.co.uk/map/survival#world;flat'),
{
world: 'world',
map: 'flat',
location: undefined,
zoom: undefined,
legacy: false
}
],
[
'LiveAtlas - no map, location or zoom',
new URL('https://minecraft.rtgame.co.uk/map/survival#world'),
{
world: 'world',
map: undefined,
location: undefined,
zoom: undefined,
legacy: false
}
]
]
const invalidURLs: [string, URL, LiveAtlasParsedUrl|null][] = [
[
'LiveAtlas - negative zoom',
new URL('https://minecraft.rtgame.co.uk/map/survival#world;flat;168,64,1914;-2'),
{
world: 'world',
map: 'flat',
location: {x: 168, y: 64, z: 1914},
zoom: undefined,
legacy: false
}
],
[
'LiveAtlas - NaN zoom',
new URL('https://minecraft.rtgame.co.uk/map/survival#world;flat;168,64,1914;ewsjtuiewshfoes'),
{
world: 'world',
map: 'flat',
location: {x: 168, y: 64, z: 1914},
zoom: undefined,
legacy: false
}
],
[
'LiveAtlas - missing z coordinate',
new URL('https://minecraft.rtgame.co.uk/map/survival#world;flat;168,64;2'),
{
world: 'world',
map: 'flat',
location: undefined,
zoom: 2,
legacy: false
}
],
[
'LiveAtlas - NaN z coordinate',
new URL('https://minecraft.rtgame.co.uk/map/survival#world;flat;168,64,j;2'),
{
world: 'world',
map: 'flat',
location: undefined,
zoom: 2,
legacy: false
}
],
[
'LiveAtlas - missing y and z coordinates',
new URL('https://minecraft.rtgame.co.uk/map/survival#world;flat;168;2'),
{
world: 'world',
map: 'flat',
location: undefined,
zoom: 2,
legacy: false
}
],
[
'LiveAtlas - invalid location',
new URL('https://minecraft.rtgame.co.uk/map/survival#world;flat;23wteyuisezujsezr'),
{
world: 'world',
map: 'flat',
location: undefined,
zoom: undefined,
legacy: false
}
],
[
'Dynmap - Negative zoom',
new URL('https://minecraft.rtgame.co.uk/map/survival?worldname=world&mapname=surface&zoom=-2&x=6885&y=64&z=24608'),
{
world: 'world',
map: 'surface',
location: {x: 6885, y: 64, z: 24608},
zoom: undefined,
legacy: true
}
],
[
'Dynmap - NaN zoom',
new URL('https://minecraft.rtgame.co.uk/map/survival?worldname=world&mapname=surface&zoom=fsghrtdrh&x=6885&y=64&z=24608'),
{
world: 'world',
map: 'surface',
location: {x: 6885, y: 64, z: 24608},
zoom: undefined,
legacy: true
}
],
[
'Dynmap - Missing z coordinate',
new URL('https://minecraft.rtgame.co.uk/map/survival?worldname=world&mapname=surface&zoom=2&x=6885&y=64'),
{
world: 'world',
map: 'surface',
location: undefined,
zoom: 2,
legacy: true
}
],
[
'Dynmap - NaN z coordinate',
new URL('https://minecraft.rtgame.co.uk/map/survival?worldname=world&mapname=surface&zoom=2&x=6885&y=64&z=j'),
{
world: 'world',
map: 'surface',
location: undefined,
zoom: 2,
legacy: true
}
],
[
'Dynmap - Missing y and z coordinates',
new URL('https://minecraft.rtgame.co.uk/map/survival?worldname=world&mapname=surface&zoom=2&x=6885'),
{
world: 'world',
map: 'surface',
location: undefined,
zoom: 2,
legacy: true
}
],
[
'Dynmap - Invalid/missing coordinates',
new URL('https://minecraft.rtgame.co.uk/map/survival?worldname=world&mapname=surface&x=3wresfsg'),
{
world: 'world',
map: 'surface',
location: undefined,
zoom: undefined,
legacy: true
}
],
[
'Dynmap - Missing world',
new URL('https://minecraft.rtgame.co.uk/map/survival?mapname=surface&x=3wresfsg'),
null
],
[
'empty hash',
new URL('https://minecraft.rtgame.co.uk/map/survival#'),
null
],
[
'empty query',
new URL('https://minecraft.rtgame.co.uk/map/survival?'),
null
],
];
describe("parseURL", () => {
test.each(validURLs)("Valid URL - %s", (name: string, url: URL, expected: LiveAtlasParsedUrl) => {
expect(parseUrl(url)).toEqual(expected);
});
test.each(invalidURLs)("Invalid or incomplete URL - %s", (name: string, url: URL, expected: LiveAtlasParsedUrl|null) => {
expect(parseUrl(url)).toEqual(expected);
});
});

View File

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

View File

@ -1,335 +0,0 @@
/*
* Copyright 2022 James Lyne
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {parseUrl} from "@/util";
import cases from 'jest-in-case';
describe("parseURL", () => {
cases('valid Dynmap URLs', (options: any) => {
expect(parseUrl(options.url)).toEqual(options.result);
}, [
{
name: 'Complete URL',
url: new URL('https://minecraft.rtgame.co.uk/build?worldname=world&mapname=surface&zoom=4&x=6885&y=64&z=24608'),
result: {
world: 'world',
map: 'surface',
location: {x: 6885, y: 64, z: 24608},
zoom: 4,
legacy: true
}
},
{
name: 'no location',
url: new URL('https://minecraft.rtgame.co.uk/build?worldname=world&mapname=surface&zoom=4'),
result: {
world: 'world',
map: 'surface',
location: undefined,
zoom: 4,
legacy: true
}
},
{
name: 'no zoom',
url: new URL('https://minecraft.rtgame.co.uk/build?worldname=world&mapname=surface&x=6885&y=64&z=24608'),
result: {
world: 'world',
map: 'surface',
location: {x: 6885, y: 64, z: 24608},
zoom: undefined,
legacy: true
}
},
{
name: 'no zoom or location',
url: new URL('https://minecraft.rtgame.co.uk/build?worldname=world&mapname=surface'),
result: {
world: 'world',
map: 'surface',
location: undefined,
zoom: undefined,
legacy: true
}
},
{
name: 'no map, zoom or location',
url: new URL('https://minecraft.rtgame.co.uk/build?worldname=world'),
result: {
world: 'world',
map: undefined,
location: undefined,
zoom: undefined,
legacy: true
}
}
]);
cases('valid Pl3xmap URLs', (options: any) => {
expect(parseUrl(options.url)).toEqual(options.result);
}, [
{
name: 'Complete URL',
url: new URL('https://minecraft.rtgame.co.uk/build?world=world&zoom=4&x=6885&y=64&z=24608'),
result: {
world: 'world',
map: undefined,
location: {x: 6885, y: 64, z: 24608},
zoom: 4,
legacy: true
}
},
{
name: 'no location',
url: new URL('https://minecraft.rtgame.co.uk/build?world=world&zoom=4'),
result: {
world: 'world',
map: undefined,
location: undefined,
zoom: 4,
legacy: true
}
},
{
name: 'no zoom',
url: new URL('https://minecraft.rtgame.co.uk/build?world=world&x=6885&y=64&z=24608'),
result: {
world: 'world',
map: undefined,
location: {x: 6885, y: 64, z: 24608},
zoom: undefined,
legacy: true
}
},
{
name: 'no zoom or location',
url: new URL('https://minecraft.rtgame.co.uk/build?world=world'),
result: {
world: 'world',
map: undefined,
location: undefined,
zoom: undefined,
legacy: true
}
},
{
name: 'nothing',
url: new URL('https://minecraft.rtgame.co.uk/map/survival?'),
result: null
}
]);
cases('valid LiveAtlas URLs', (options: any) => {
expect(parseUrl(options.url)).toEqual(options.result);
}, [
{
name: 'Complete URL',
url: new URL('https://minecraft.rtgame.co.uk/map/survival#world;flat;168,64,1914;2'),
result: {
world: 'world',
map: 'flat',
location: {x: 168, y: 64, z: 1914},
zoom: 2,
legacy: false
}
},
{
name: 'no zoom',
url: new URL('https://minecraft.rtgame.co.uk/map/survival#world;flat;168,64,1914'),
result: {
world: 'world',
map: 'flat',
location: {x: 168, y: 64, z: 1914},
zoom: undefined,
legacy: false
}
},
{
name: 'no location or zoom',
url: new URL('https://minecraft.rtgame.co.uk/map/survival#world;flat'),
result: {
world: 'world',
map: 'flat',
location: undefined,
zoom: undefined,
legacy: false
}
},
{
name: 'no map, location or zoom',
url: new URL('https://minecraft.rtgame.co.uk/map/survival#world'),
result: {
world: 'world',
map: undefined,
location: undefined,
zoom: undefined,
legacy: false
}
},
{
name: 'nothing',
url: new URL('https://minecraft.rtgame.co.uk/map/survival#'),
result: null
}
]);
cases('incomplete or invalid LiveAtlas URLs', (options: any) => {
expect(parseUrl(options.url)).toEqual(options.result);
}, [
{
name: 'negative zoom',
url: new URL('https://minecraft.rtgame.co.uk/map/survival#world;flat;168,64,1914;-2'),
result: {
world: 'world',
map: 'flat',
location: {x: 168, y: 64, z: 1914},
zoom: undefined,
legacy: false
}
},
{
name: 'NaN zoom',
url: new URL('https://minecraft.rtgame.co.uk/map/survival#world;flat;168,64,1914;ewsjtuiewshfoes'),
result: {
world: 'world',
map: 'flat',
location: {x: 168, y: 64, z: 1914},
zoom: undefined,
legacy: false
}
},
{
name: 'missing z coordinate',
url: new URL('https://minecraft.rtgame.co.uk/map/survival#world;flat;168,64;2'),
result: {
world: 'world',
map: 'flat',
location: undefined,
zoom: 2,
legacy: false
}
},
{
name: 'NaN z coordinate',
url: new URL('https://minecraft.rtgame.co.uk/map/survival#world;flat;168,64,j;2'),
result: {
world: 'world',
map: 'flat',
location: undefined,
zoom: 2,
legacy: false
}
},
{
name: 'missing y and z coordinates',
url: new URL('https://minecraft.rtgame.co.uk/map/survival#world;flat;168;2'),
result: {
world: 'world',
map: 'flat',
location: undefined,
zoom: 2,
legacy: false
}
},
{
name: 'invalid location',
url: new URL('https://minecraft.rtgame.co.uk/map/survival#world;flat;23wteyuisezujsezr'),
result: {
world: 'world',
map: 'flat',
location: undefined,
zoom: undefined,
legacy: false
}
}
]);
cases('incomplete or invalid Dynmap URLs', (options: any) => {
expect(parseUrl(options.url)).toEqual(options.result);
}, [
{
name: 'Negative zoom',
url: new URL('https://minecraft.rtgame.co.uk/map/survival?worldname=world&mapname=surface&zoom=-2&x=6885&y=64&z=24608'),
result: {
world: 'world',
map: 'surface',
location: {x: 6885, y: 64, z: 24608},
zoom: undefined,
legacy: true
}
},
{
name: 'NaN zoom',
url: new URL('https://minecraft.rtgame.co.uk/map/survival?worldname=world&mapname=surface&zoom=fsghrtdrh&x=6885&y=64&z=24608'),
result: {
world: 'world',
map: 'surface',
location: {x: 6885, y: 64, z: 24608},
zoom: undefined,
legacy: true
}
},
{
name: 'Missing z coordinate',
url: new URL('https://minecraft.rtgame.co.uk/map/survival?worldname=world&mapname=surface&zoom=2&x=6885&y=64'),
result: {
world: 'world',
map: 'surface',
location: undefined,
zoom: 2,
legacy: true
}
},
{
name: 'NaN z coordinate',
url: new URL('https://minecraft.rtgame.co.uk/map/survival?worldname=world&mapname=surface&zoom=2&x=6885&y=64&z=j'),
result: {
world: 'world',
map: 'surface',
location: undefined,
zoom: 2,
legacy: true
}
},
{
name: 'Missing y and z coordinates',
url: new URL('https://minecraft.rtgame.co.uk/map/survival?worldname=world&mapname=surface&zoom=2&x=6885'),
result: {
world: 'world',
map: 'surface',
location: undefined,
zoom: 2,
legacy: true
}
},
{
name: 'Invalid/missing coordinates',
url: new URL('https://minecraft.rtgame.co.uk/map/survival?worldname=world&mapname=surface&x=3wresfsg'),
result: {
world: 'world',
map: 'surface',
location: undefined,
zoom: undefined,
legacy: true
}
},
{
name: 'Missing world',
url: new URL('https://minecraft.rtgame.co.uk/map/survival?mapname=surface&x=3wresfsg'),
result: null
}
]);
});

View File

@ -17,8 +17,7 @@
"types": [ "types": [
"vite/client", "vite/client",
"vue", "vue",
"jest", "jest"
"jest-in-case"
], ],
"paths": { "paths": {
"@/*": [ "@/*": [
@ -35,7 +34,7 @@
"include": [ "include": [
"src/**/*.ts", "src/**/*.ts",
"src/**/*.vue", "src/**/*.vue",
"tests/**/*.ts" "test/**/*.ts"
], ],
"exclude": [ "exclude": [
"node_modules" "node_modules"

View File

@ -44,5 +44,9 @@ export default defineConfig(({ mode }) => {
assetsDir: 'live-atlas/assets' assetsDir: 'live-atlas/assets'
}, },
define: envWithProcessPrefix, define: envWithProcessPrefix,
test: {
globals: true,
environment: 'jsdom',
},
} }
}); });