mapcomplete/test/TestAll.ts

103 lines
3.8 KiB
TypeScript
Raw Normal View History

import TagSpec from "./Tag.spec";
import ImageAttributionSpec from "./ImageAttribution.spec";
import GeoOperationsSpec from "./GeoOperations.spec";
import ThemeSpec from "./Theme.spec";
import UtilsSpec from "./Utils.spec";
2021-06-28 18:06:54 +02:00
import OsmObjectSpec from "./OsmObject.spec";
import ScriptUtils from "../scripts/ScriptUtils";
2021-07-04 20:36:19 +02:00
import UnitsSpec from "./Units.spec";
import RelationSplitHandlerSpec from "./RelationSplitHandler.spec";
import SplitActionSpec from "./SplitAction.spec";
import {Utils} from "../Utils";
import TileFreshnessCalculatorSpec from "./TileFreshnessCalculator.spec";
2021-10-03 01:38:57 +02:00
import WikidataSpecTest from "./Wikidata.spec.test";
import ImageProviderSpec from "./ImageProvider.spec";
import ActorsSpec from "./Actors.spec";
import ReplaceGeometrySpec from "./ReplaceGeometry.spec";
import LegacyThemeLoaderSpec from "./LegacyThemeLoader.spec";
2022-01-14 13:58:15 +01:00
import T from "./TestHelper";
import CreateNoteImportLayerSpec from "./CreateNoteImportLayer.spec";
import ValidatedTextFieldTranslationsSpec from "./ValidatedTextFieldTranslations.spec";
2022-02-14 01:15:20 +01:00
import CreateCacheSpec from "./CreateCache.spec";
import CodeQualitySpec from "./CodeQuality.spec";
2022-02-22 14:13:41 +01:00
import ImportMultiPolygonSpec from "./ImportMultiPolygon.spec";
2021-06-28 18:06:54 +02:00
2021-12-30 20:41:45 +01:00
async function main() {
2022-01-26 21:40:38 +01:00
const allTests: T[] = [
2021-12-30 20:41:45 +01:00
new OsmObjectSpec(),
new TagSpec(),
new ImageAttributionSpec(),
new GeoOperationsSpec(),
new ThemeSpec(),
new UtilsSpec(),
new UnitsSpec(),
new RelationSplitHandlerSpec(),
new SplitActionSpec(),
new TileFreshnessCalculatorSpec(),
new WikidataSpecTest(),
new ImageProviderSpec(),
new ActorsSpec(),
new ReplaceGeometrySpec(),
2022-01-14 13:58:15 +01:00
new LegacyThemeLoaderSpec(),
new CreateNoteImportLayerSpec(),
2022-02-14 20:10:49 +01:00
new ValidatedTextFieldTranslationsSpec(),
new CreateCacheSpec(),
2022-02-22 14:13:41 +01:00
new CodeQualitySpec(),
new ImportMultiPolygonSpec()
2021-12-30 20:41:45 +01:00
]
2022-02-14 01:15:20 +01:00
ScriptUtils.fixUtils();
const realDownloadFunc = Utils.externalDownloadFunction;
2021-12-30 20:41:45 +01:00
Utils.externalDownloadFunction = async (url) => {
console.error("Fetching ", url, "blocked in tests, use Utils.injectJsonDownloadForTests")
2022-02-14 01:15:20 +01:00
const data = await realDownloadFunc(url)
2021-12-30 20:41:45 +01:00
console.log("\n\n ----------- \nBLOCKED DATA\n Utils.injectJsonDownloadForTests(\n" +
" ", JSON.stringify(url), ", \n",
" ", JSON.stringify(data), "\n )\n------------------\n\n")
throw "Detected internet access for URL " + url + ", please inject it with Utils.injectJsonDownloadForTests"
}
2021-12-30 20:41:45 +01:00
let args = [...process.argv]
args.splice(0, 2)
2022-02-19 02:45:15 +01:00
args = args.map(a => a.toLowerCase().replace(/"/g, ""))
2021-12-30 20:41:45 +01:00
const allFailures: { testsuite: string, name: string, msg: string } [] = []
let testsToRun = allTests
if (args.length > 0) {
2022-01-14 13:58:15 +01:00
args = args.map(a => a.toLowerCase()).map(a => {
2022-01-26 21:40:38 +01:00
if (!a.endsWith("spec")) {
2022-01-14 13:58:15 +01:00
return a + "spec"
2022-01-26 21:40:38 +01:00
} else {
2022-01-14 13:58:15 +01:00
return a;
}
})
2021-12-30 20:41:45 +01:00
testsToRun = allTests.filter(t => args.indexOf(t.name.toLowerCase()) >= 0)
2022-02-19 02:45:15 +01:00
console.log("Only running test "+testsToRun.join(", "))
2021-12-30 20:41:45 +01:00
}
2021-12-30 20:41:45 +01:00
if (testsToRun.length == 0) {
2022-01-14 13:58:15 +01:00
const available = allTests.map(t => t.name)
available.sort()
throw "No tests found. Try one of " + available.join(", ")
}
2021-12-30 20:41:45 +01:00
for (let i = 0; i < testsToRun.length; i++) {
const test = testsToRun[i];
console.log(" Running test", i, "/", testsToRun.length, test.name)
2022-01-26 21:40:38 +01:00
2021-12-30 20:41:45 +01:00
allFailures.push(...(await test.Run() ?? []))
console.log("OK!")
}
if (allFailures.length > 0) {
for (const failure of allFailures) {
console.error(" !! " + failure.testsuite + "." + failure.name + " failed due to: " + failure.msg)
}
throw "Some test failed"
}
console.log("All tests successful: ", testsToRun.map(t => t.name).join(", "))
}
2021-12-30 20:41:45 +01:00
main()