More verbose test code
This commit is contained in:
parent
108508db7e
commit
52fca8714d
|
@ -40,6 +40,18 @@ function escapeRegExp(string) {
|
||||||
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") // $& means the whole matched string
|
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") // $& means the whole matched string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function tryParseJson(str) {
|
||||||
|
if (typeof str !== "string") {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return JSON.parse(str.replace(/\'/g, '"'))
|
||||||
|
} catch (e) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
describe("manifest", () => {
|
describe("manifest", () => {
|
||||||
describe("examples are valid", () => {
|
describe("examples are valid", () => {
|
||||||
describe.each(Object.keys(examples))("%s", collection => {
|
describe.each(Object.keys(examples))("%s", collection => {
|
||||||
|
@ -67,18 +79,15 @@ describe("manifest", () => {
|
||||||
let result = await processString(hbs, context)
|
let result = await processString(hbs, context)
|
||||||
// Trim 's
|
// Trim 's
|
||||||
js = js.replace(/^\'|\'$/g, "")
|
js = js.replace(/^\'|\'$/g, "")
|
||||||
try {
|
if ((parsedExpected = tryParseJson(js))) {
|
||||||
let parsedExpected
|
if (Array.isArray(parsedExpected)) {
|
||||||
if (
|
|
||||||
Array.isArray((parsedExpected = JSON.parse(js.replace(/\'/g, '"'))))
|
|
||||||
) {
|
|
||||||
if (typeof parsedExpected[0] === "object") {
|
if (typeof parsedExpected[0] === "object") {
|
||||||
js = JSON.stringify(parsedExpected)
|
js = JSON.stringify(parsedExpected)
|
||||||
} else {
|
} else {
|
||||||
js = parsedExpected.join(",")
|
js = parsedExpected.join(",")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch {}
|
}
|
||||||
result = result.replace(/ /g, " ")
|
result = result.replace(/ /g, " ")
|
||||||
expect(result).toEqual(js)
|
expect(result).toEqual(js)
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue