Test improvements

This commit is contained in:
James Lyne 2021-09-12 20:37:07 +01:00
parent bcf76a296b
commit 7e647b7c19
4 changed files with 352 additions and 260 deletions

37
package-lock.json generated
View File

@ -18,6 +18,7 @@
}, },
"devDependencies": { "devDependencies": {
"@types/jest": "^27.0.1", "@types/jest": "^27.0.1",
"@types/jest-in-case": "^1.0.5",
"@types/leaflet": "1.7.5", "@types/leaflet": "1.7.5",
"@types/node": "^16.9.1", "@types/node": "^16.9.1",
"@typescript-eslint/eslint-plugin": "^4.31", "@typescript-eslint/eslint-plugin": "^4.31",
@ -29,6 +30,7 @@
"eslint": "^7.32", "eslint": "^7.32",
"eslint-plugin-vue": "^7.17", "eslint-plugin-vue": "^7.17",
"jest": "^26.6.3", "jest": "^26.6.3",
"jest-in-case": "^1.0.2",
"patch-package": "^6.4", "patch-package": "^6.4",
"rollup-plugin-analyzer": "^4.0", "rollup-plugin-analyzer": "^4.0",
"sass": "^1.39", "sass": "^1.39",
@ -1262,6 +1264,16 @@
"pretty-format": "^27.0.0" "pretty-format": "^27.0.0"
} }
}, },
"node_modules/@types/jest-in-case": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/@types/jest-in-case/-/jest-in-case-1.0.5.tgz",
"integrity": "sha512-QcIc5IqSVfpl+9jFl4/LlZnAPDNYUfLD+VrvtrK/cOx2CbS7K+FoXGIajiaY3gpFAkBiHGV2PThuWrmaRFE/Tg==",
"dev": true,
"dependencies": {
"@types/jest": "*",
"@types/node": "*"
}
},
"node_modules/@types/json-schema": { "node_modules/@types/json-schema": {
"version": "7.0.9", "version": "7.0.9",
"resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.9.tgz", "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.9.tgz",
@ -4974,6 +4986,15 @@
"fsevents": "^2.1.2" "fsevents": "^2.1.2"
} }
}, },
"node_modules/jest-in-case": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/jest-in-case/-/jest-in-case-1.0.2.tgz",
"integrity": "sha1-VnRLWvMyIr0KurcM+Rnx0XCrdcw=",
"dev": true,
"engines": {
"node": ">=4"
}
},
"node_modules/jest-jasmine2": { "node_modules/jest-jasmine2": {
"version": "26.6.3", "version": "26.6.3",
"resolved": "https://registry.npmjs.org/jest-jasmine2/-/jest-jasmine2-26.6.3.tgz", "resolved": "https://registry.npmjs.org/jest-jasmine2/-/jest-jasmine2-26.6.3.tgz",
@ -10564,6 +10585,16 @@
"pretty-format": "^27.0.0" "pretty-format": "^27.0.0"
} }
}, },
"@types/jest-in-case": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/@types/jest-in-case/-/jest-in-case-1.0.5.tgz",
"integrity": "sha512-QcIc5IqSVfpl+9jFl4/LlZnAPDNYUfLD+VrvtrK/cOx2CbS7K+FoXGIajiaY3gpFAkBiHGV2PThuWrmaRFE/Tg==",
"dev": true,
"requires": {
"@types/jest": "*",
"@types/node": "*"
}
},
"@types/json-schema": { "@types/json-schema": {
"version": "7.0.9", "version": "7.0.9",
"resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.9.tgz", "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.9.tgz",
@ -13452,6 +13483,12 @@
"walker": "^1.0.7" "walker": "^1.0.7"
} }
}, },
"jest-in-case": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/jest-in-case/-/jest-in-case-1.0.2.tgz",
"integrity": "sha1-VnRLWvMyIr0KurcM+Rnx0XCrdcw=",
"dev": true
},
"jest-jasmine2": { "jest-jasmine2": {
"version": "26.6.3", "version": "26.6.3",
"resolved": "https://registry.npmjs.org/jest-jasmine2/-/jest-jasmine2-26.6.3.tgz", "resolved": "https://registry.npmjs.org/jest-jasmine2/-/jest-jasmine2-26.6.3.tgz",

View File

@ -21,6 +21,7 @@
}, },
"devDependencies": { "devDependencies": {
"@types/jest": "^27.0.1", "@types/jest": "^27.0.1",
"@types/jest-in-case": "^1.0.5",
"@types/leaflet": "1.7.5", "@types/leaflet": "1.7.5",
"@types/node": "^16.9.1", "@types/node": "^16.9.1",
"@typescript-eslint/eslint-plugin": "^4.31", "@typescript-eslint/eslint-plugin": "^4.31",
@ -32,6 +33,7 @@
"eslint": "^7.32", "eslint": "^7.32",
"eslint-plugin-vue": "^7.17", "eslint-plugin-vue": "^7.17",
"jest": "^26.6.3", "jest": "^26.6.3",
"jest-in-case": "^1.0.2",
"patch-package": "^6.4", "patch-package": "^6.4",
"rollup-plugin-analyzer": "^4.0", "rollup-plugin-analyzer": "^4.0",
"sass": "^1.39", "sass": "^1.39",

View File

@ -15,269 +15,321 @@
*/ */
import {parseUrl} from "@/util"; import {parseUrl} from "@/util";
import {LiveAtlasParsedUrl} from "@/index"; import cases from 'jest-in-case';
describe("parseURL", () => { describe("parseURL", () => {
const testUrls = (urls: Map<URL, LiveAtlasParsedUrl>) => { cases('valid Dynmap URLs', (options: any) => {
urls.forEach((value, key) => { expect(parseUrl(options.url)).toEqual(options.result);
// @ts-ignore }, [
process.stdout.write(key.toString() + '\n'); {
expect(parseUrl(key)).toEqual(value); 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: {
test('parses valid Dynmap URLs', () => {
const tests = new Map<URL, LiveAtlasParsedUrl>();
// Complete URL
tests.set(new URL('https://minecraft.rtgame.co.uk/build?worldname=world&mapname=surface&zoom=4&x=6885&y=64&z=24608'), {
world: 'world', world: 'world',
map: 'surface', map: 'surface',
location: {x: 6885, y: 64, z: 24608}, location: {x: 6885, y: 64, z: 24608},
zoom: 4, zoom: 4,
legacy: true legacy: true
}); }
},
// No location {
tests.set(new URL('https://minecraft.rtgame.co.uk/build?worldname=world&mapname=surface&zoom=4'), { name: 'no location',
url: new URL('https://minecraft.rtgame.co.uk/build?worldname=world&mapname=surface&zoom=4'),
result: {
world: 'world', world: 'world',
map: 'surface', map: 'surface',
location: undefined, location: undefined,
zoom: 4, zoom: 4,
legacy: true legacy: true
}); }
},
// No zoom {
tests.set(new URL('https://minecraft.rtgame.co.uk/build?worldname=world&mapname=surface&x=6885&y=64&z=24608'), { 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', world: 'world',
map: 'surface', map: 'surface',
location: {x: 6885, y: 64, z: 24608}, location: {x: 6885, y: 64, z: 24608},
zoom: undefined, zoom: undefined,
legacy: true legacy: true
}); }
},
// No zoom or location {
tests.set(new URL('https://minecraft.rtgame.co.uk/build?worldname=world&mapname=surface'), { name: 'no zoom or location',
url: new URL('https://minecraft.rtgame.co.uk/build?worldname=world&mapname=surface'),
result: {
world: 'world', world: 'world',
map: 'surface', map: 'surface',
location: undefined, location: undefined,
zoom: undefined, zoom: undefined,
legacy: true legacy: true
}); }
},
// No zoom, location or map {
tests.set(new URL('https://minecraft.rtgame.co.uk/build?worldname=world'), { name: 'no map, zoom or location',
url: new URL('https://minecraft.rtgame.co.uk/build?worldname=world'),
result: {
world: 'world', world: 'world',
map: undefined, map: undefined,
location: undefined, location: undefined,
zoom: undefined, zoom: undefined,
legacy: true legacy: true
}); }
}
]);
testUrls(tests); cases('valid Pl3xmap URLs', (options: any) => {
}); expect(parseUrl(options.url)).toEqual(options.result);
}, [
test('parses valid Pl3xmap URLs', () => { {
const tests = new Map<URL, LiveAtlasParsedUrl>(); name: 'Complete URL',
url: new URL('https://minecraft.rtgame.co.uk/build?world=world&zoom=4&x=6885&y=64&z=24608'),
// Complete URL result: {
tests.set(new URL('https://minecraft.rtgame.co.uk/build?world=world&zoom=4&x=6885&z=24608'), {
world: 'world', world: 'world',
map: undefined, map: undefined,
location: {x: 6885, y: 64, z: 24608}, location: {x: 6885, y: 64, z: 24608},
zoom: 4, zoom: 4,
legacy: true legacy: true
}); }
},
// No location {
tests.set(new URL('https://minecraft.rtgame.co.uk/build?world=world&zoom=4'), { name: 'no location',
url: new URL('https://minecraft.rtgame.co.uk/build?world=world&zoom=4'),
result: {
world: 'world', world: 'world',
map: undefined, map: undefined,
location: undefined, location: undefined,
zoom: 4, zoom: 4,
legacy: true legacy: true
}); }
},
// No zoom {
tests.set(new URL('https://minecraft.rtgame.co.uk/build?world=world&x=6885&z=24608'), { name: 'no zoom',
url: new URL('https://minecraft.rtgame.co.uk/build?world=world&x=6885&y=64&z=24608'),
result: {
world: 'world', world: 'world',
map: undefined, map: undefined,
location: {x: 6885, y: 64, z: 24608}, location: {x: 6885, y: 64, z: 24608},
zoom: undefined, zoom: undefined,
legacy: true legacy: true
}); }
},
// No zoom or location {
tests.set(new URL('https://minecraft.rtgame.co.uk/build?world=world'), { name: 'no zoom or location',
url: new URL('https://minecraft.rtgame.co.uk/build?world=world'),
result: {
world: 'world', world: 'world',
map: undefined, map: undefined,
location: undefined, location: undefined,
zoom: undefined, zoom: undefined,
legacy: true legacy: true
}); }
},
{
name: 'nothing',
url: new URL('https://minecraft.rtgame.co.uk/map/survival?'),
result: null
}
]);
testUrls(tests); cases('valid LiveAtlas URLs', (options: any) => {
}); expect(parseUrl(options.url)).toEqual(options.result);
}, [
test('parses valid LiveAtlas URL', () => { {
const tests = new Map<URL, LiveAtlasParsedUrl>(); name: 'Complete URL',
url: new URL('https://minecraft.rtgame.co.uk/map/survival#world;flat;168,64,1914;2'),
// Complete URL result: {
tests.set(new URL('https://minecraft.rtgame.co.uk/map/survival#world;flat;168,64,1914;2'), {
world: 'world', world: 'world',
map: 'flat', map: 'flat',
location: {x: 168, y: 64, z: 1914}, location: {x: 168, y: 64, z: 1914},
zoom: 2, zoom: 2,
legacy: false legacy: false
}); }
},
// No zoom {
tests.set(new URL('https://minecraft.rtgame.co.uk/map/survival#world;flat;168,64,1914'), { name: 'no zoom',
url: new URL('https://minecraft.rtgame.co.uk/map/survival#world;flat;168,64,1914'),
result: {
world: 'world', world: 'world',
map: 'flat', map: 'flat',
location: {x: 168, y: 64, z: 1914}, location: {x: 168, y: 64, z: 1914},
zoom: undefined, zoom: undefined,
legacy: false legacy: false
}); }
},
// No location or zoom {
tests.set(new URL('https://minecraft.rtgame.co.uk/map/survival#world;flat'), { name: 'no location or zoom',
url: new URL('https://minecraft.rtgame.co.uk/map/survival#world;flat'),
result: {
world: 'world', world: 'world',
map: 'flat', map: 'flat',
location: undefined, location: undefined,
zoom: undefined, zoom: undefined,
legacy: false legacy: false
}); }
},
// No map, location or zoom {
tests.set(new URL('https://minecraft.rtgame.co.uk/map/survival#world'), { name: 'no map, location or zoom',
url: new URL('https://minecraft.rtgame.co.uk/map/survival#world'),
result: {
world: 'world', world: 'world',
map: undefined, map: undefined,
location: undefined, location: undefined,
zoom: undefined, zoom: undefined,
legacy: false legacy: false
}); }
},
{
name: 'nothing',
url: new URL('https://minecraft.rtgame.co.uk/map/survival#'),
result: null
}
]);
testUrls(tests); cases('incomplete or invalid LiveAtlas URLs', (options: any) => {
}); expect(parseUrl(options.url)).toEqual(options.result);
}, [
test('handles incomplete or invalid LiveAtlas URLs', () => { {
const tests = new Map<URL, LiveAtlasParsedUrl>(); name: 'negative zoom',
url: new URL('https://minecraft.rtgame.co.uk/map/survival#world;flat;168,64,1914;-2'),
//Negative zoom result: {
tests.set(new URL('https://minecraft.rtgame.co.uk/map/survival#world;flat;168,64,1914;-2'), {
world: 'world', world: 'world',
map: 'flat', map: 'flat',
location: {x: 168, y: 64, z: 1914}, location: {x: 168, y: 64, z: 1914},
zoom: undefined, zoom: undefined,
legacy: false legacy: false
}); }
},
//NaN zoom {
tests.set(new URL('https://minecraft.rtgame.co.uk/map/survival#world;flat;168,64,1914;ewsjtuiewshfoes'), { name: 'NaN zoom',
url: new URL('https://minecraft.rtgame.co.uk/map/survival#world;flat;168,64,1914;ewsjtuiewshfoes'),
result: {
world: 'world', world: 'world',
map: 'flat', map: 'flat',
location: {x: 168, y: 64, z: 1914}, location: {x: 168, y: 64, z: 1914},
zoom: undefined, zoom: undefined,
legacy: false legacy: false
}); }
},
//Missing z coordinate {
tests.set(new URL('https://minecraft.rtgame.co.uk/map/survival#world;flat;168,64;2'), { name: 'missing z coordinate',
url: new URL('https://minecraft.rtgame.co.uk/map/survival#world;flat;168,64;2'),
result: {
world: 'world', world: 'world',
map: 'flat', map: 'flat',
location: undefined, location: undefined,
zoom: 2, zoom: 2,
legacy: false legacy: false
}); }
},
//NaN z coordinate {
tests.set(new URL('https://minecraft.rtgame.co.uk/map/survival#world;flat;168,64,j;2'), { name: 'NaN z coordinate',
url: new URL('https://minecraft.rtgame.co.uk/map/survival#world;flat;168,64,j;2'),
result: {
world: 'world', world: 'world',
map: 'flat', map: 'flat',
location: undefined, location: undefined,
zoom: 2, zoom: 2,
legacy: false legacy: false
}); }
},
//Missing y and z coordinates {
tests.set(new URL('https://minecraft.rtgame.co.uk/map/survival#world;flat;168;2'), { name: 'missing y and z coordinates',
url: new URL('https://minecraft.rtgame.co.uk/map/survival#world;flat;168;2'),
result: {
world: 'world', world: 'world',
map: 'flat', map: 'flat',
location: undefined, location: undefined,
zoom: 2, zoom: 2,
legacy: false legacy: false
}); }
},
//Invalid location {
tests.set(new URL('https://minecraft.rtgame.co.uk/map/survival#world;flat;23wteyuisezujsezr'), { name: 'invalid location',
url: new URL('https://minecraft.rtgame.co.uk/map/survival#world;flat;23wteyuisezujsezr'),
result: {
world: 'world', world: 'world',
map: 'flat', map: 'flat',
location: undefined, location: undefined,
zoom: undefined, zoom: undefined,
legacy: false legacy: false
}); }
}
]);
testUrls(tests); cases('incomplete or invalid Dynmap URLs', (options: any) => {
}); expect(parseUrl(options.url)).toEqual(options.result);
}, [
test('handles incomplete or invalid Dynmap URLs', () => { {
const tests = new Map<URL, LiveAtlasParsedUrl>(); 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'),
//Negative zoom result: {
tests.set(new URL('https://minecraft.rtgame.co.uk/map/survival?worldname=world&mapname=surface&zoom=-2&x=6885&y=64&z=24608'), {
world: 'world', world: 'world',
map: 'surface', map: 'surface',
location: {x: 6885, y: 64, z: 24608}, location: {x: 6885, y: 64, z: 24608},
zoom: undefined, zoom: undefined,
legacy: true legacy: true
}); }
},
//NaN zoom {
tests.set(new URL('https://minecraft.rtgame.co.uk/map/survival?worldname=world&mapname=surface&zoom=fsghrtdrh&x=6885&y=64&z=24608'), { 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', world: 'world',
map: 'surface', map: 'surface',
location: {x: 6885, y: 64, z: 24608}, location: {x: 6885, y: 64, z: 24608},
zoom: undefined, zoom: undefined,
legacy: true legacy: true
}); }
},
//Missing z coordinate {
tests.set(new URL('https://minecraft.rtgame.co.uk/map/survival?worldname=world&mapname=surface&zoom=2&x=6885&y=64'), { 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', world: 'world',
map: 'surface', map: 'surface',
location: undefined, location: undefined,
zoom: 2, zoom: 2,
legacy: true legacy: true
}); }
},
//NaN z coordinate {
tests.set(new URL('https://minecraft.rtgame.co.uk/map/survival?worldname=world&mapname=surface&zoom=2&x=6885&y=64&z=j'), { 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', world: 'world',
map: 'surface', map: 'surface',
location: undefined, location: undefined,
zoom: 2, zoom: 2,
legacy: true legacy: true
}); }
},
//Missing y and z coordinates {
tests.set(new URL('https://minecraft.rtgame.co.uk/map/survival?worldname=world&mapname=surface&zoom=2&x=6885'), { 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', world: 'world',
map: 'surface', map: 'surface',
location: undefined, location: undefined,
zoom: 2, zoom: 2,
legacy: true legacy: true
}); }
},
//Invalid/missing coordinates {
tests.set(new URL('https://minecraft.rtgame.co.uk/map/survival?worldname=world&mapname=surface&x=3wresfsg'), { name: 'Invalid/missing coordinates',
url: new URL('https://minecraft.rtgame.co.uk/map/survival?worldname=world&mapname=surface&x=3wresfsg'),
result: {
world: 'world', world: 'world',
map: 'surface', map: 'surface',
location: undefined, location: undefined,
zoom: undefined, zoom: undefined,
legacy: true legacy: true
}); }
},
testUrls(tests); {
}); name: 'Missing world',
url: new URL('https://minecraft.rtgame.co.uk/map/survival?mapname=surface&x=3wresfsg'),
result: null
}
]);
}); });

View File

@ -17,7 +17,8 @@
"types": [ "types": [
"vite/client", "vite/client",
"vue", "vue",
"jest" "jest",
"jest-in-case"
], ],
"paths": { "paths": {
"@/*": [ "@/*": [