Refactor
This commit is contained in:
parent
4829cdc4ce
commit
99e5bc1a57
|
@ -28,13 +28,17 @@ const manifest = JSON.parse(
|
||||||
const functionsToExclude = { string: ["raw"] }
|
const functionsToExclude = { string: ["raw"] }
|
||||||
|
|
||||||
const collections = Object.keys(manifest)
|
const collections = Object.keys(manifest)
|
||||||
const examples = collections.reduce(
|
const examples = collections.reduce((acc, collection) => {
|
||||||
(acc, collection) => ({
|
const functions = Object.keys(manifest[collection]).filter(
|
||||||
...acc,
|
fnc =>
|
||||||
[collection]: manifest[collection],
|
!functionsToExclude[collection]?.includes(fnc) &&
|
||||||
}),
|
manifest[collection][fnc].example
|
||||||
{}
|
|
||||||
)
|
)
|
||||||
|
if (functions.length) {
|
||||||
|
acc[collection] = functions
|
||||||
|
}
|
||||||
|
return acc
|
||||||
|
}, {})
|
||||||
|
|
||||||
function escapeRegExp(string) {
|
function escapeRegExp(string) {
|
||||||
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") // $& means the whole matched string
|
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") // $& means the whole matched string
|
||||||
|
@ -42,12 +46,8 @@ function escapeRegExp(string) {
|
||||||
|
|
||||||
describe("manifest", () => {
|
describe("manifest", () => {
|
||||||
describe("examples are valid", () => {
|
describe("examples are valid", () => {
|
||||||
describe.each(collections)("%s", collection => {
|
describe.each(Object.keys(examples))("%s", collection => {
|
||||||
it.each(
|
it.each(examples[collection])("%s", async func => {
|
||||||
Object.keys(examples[collection]).filter(
|
|
||||||
fnc => !functionsToExclude[collection]?.includes(fnc)
|
|
||||||
)
|
|
||||||
)("%s", async func => {
|
|
||||||
const example = manifest[collection][func].example
|
const example = manifest[collection][func].example
|
||||||
|
|
||||||
let [hbs, js] = example.split("->").map(x => x.trim())
|
let [hbs, js] = example.split("->").map(x => x.trim())
|
||||||
|
|
Loading…
Reference in New Issue