forked from MapComplete/MapComplete
Port tests to vitest
This commit is contained in:
parent
64a4d7e929
commit
228ceb120d
33 changed files with 673 additions and 326 deletions
|
@ -2,40 +2,18 @@ import ScriptUtils from "../scripts/ScriptUtils"
|
|||
import { Utils } from "../Utils"
|
||||
import * as fakedom from "fake-dom"
|
||||
import Locale from "../UI/i18n/Locale"
|
||||
import { beforeEach } from "vitest"
|
||||
|
||||
export const mochaHooks = {
|
||||
beforeEach(done) {
|
||||
ScriptUtils.fixUtils()
|
||||
Locale.language.setData("en")
|
||||
beforeEach(async () => {
|
||||
ScriptUtils.fixUtils()
|
||||
Locale.language.setData("en")
|
||||
|
||||
if (fakedom === undefined || window === undefined) {
|
||||
throw "FakeDom not initialized"
|
||||
}
|
||||
if (fakedom === undefined || window === undefined) {
|
||||
throw "FakeDom not initialized"
|
||||
}
|
||||
|
||||
// Block internet access
|
||||
const realDownloadFunc = Utils.externalDownloadFunction
|
||||
Utils.externalDownloadFunction = async (url) => {
|
||||
console.error(
|
||||
"Fetching ",
|
||||
url,
|
||||
"blocked in tests, use Utils.injectJsonDownloadForTests"
|
||||
)
|
||||
const data = await realDownloadFunc(url)
|
||||
console.log(
|
||||
"\n\n ----------- \nBLOCKED DATA\n Utils.injectJsonDownloadForTests(\n" + " ",
|
||||
JSON.stringify(url),
|
||||
", \n",
|
||||
" ",
|
||||
// JSON.stringify(data),
|
||||
"\n )\n------------------\n\n"
|
||||
)
|
||||
throw new Error(
|
||||
"Detected internet access for URL " +
|
||||
url +
|
||||
", please inject it with Utils.injectJsonDownloadForTests"
|
||||
)
|
||||
}
|
||||
|
||||
done()
|
||||
},
|
||||
}
|
||||
// Block internet access
|
||||
Utils.externalDownloadFunction = async (url) => {
|
||||
throw "Fetching " + url + "blocked in tests, use Utils.injectJsonDownloadForTests instead"
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue