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": {
"@types/jest": "^27.0.1",
"@types/jest-in-case": "^1.0.5",
"@types/leaflet": "1.7.5",
"@types/node": "^16.9.1",
"@typescript-eslint/eslint-plugin": "^4.31",
@ -29,6 +30,7 @@
"eslint": "^7.32",
"eslint-plugin-vue": "^7.17",
"jest": "^26.6.3",
"jest-in-case": "^1.0.2",
"patch-package": "^6.4",
"rollup-plugin-analyzer": "^4.0",
"sass": "^1.39",
@ -1262,6 +1264,16 @@
"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": {
"version": "7.0.9",
"resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.9.tgz",
@ -4974,6 +4986,15 @@
"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": {
"version": "26.6.3",
"resolved": "https://registry.npmjs.org/jest-jasmine2/-/jest-jasmine2-26.6.3.tgz",
@ -10564,6 +10585,16 @@
"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": {
"version": "7.0.9",
"resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.9.tgz",
@ -13452,6 +13483,12 @@
"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": {
"version": "26.6.3",
"resolved": "https://registry.npmjs.org/jest-jasmine2/-/jest-jasmine2-26.6.3.tgz",

View File

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

View File

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