Type tests
This commit is contained in:
parent
972cbf43b8
commit
4332034434
|
@ -157,7 +157,7 @@ export function processObjectSync(
|
||||||
*/
|
*/
|
||||||
export function processStringSync(
|
export function processStringSync(
|
||||||
string: string,
|
string: string,
|
||||||
context: object,
|
context?: object,
|
||||||
opts?: ProcessOptions
|
opts?: ProcessOptions
|
||||||
): string {
|
): string {
|
||||||
// Take a copy of input in case of error
|
// Take a copy of input in case of error
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { convertToJS } from "../src/index"
|
import { convertToJS } from "../src/index"
|
||||||
|
|
||||||
function checkLines(response, lines) {
|
function checkLines(response: string, lines: string[]) {
|
||||||
const toCheck = response.split("\n")
|
const toCheck = response.split("\n")
|
||||||
let count = 0
|
let count = 0
|
||||||
for (let line of lines) {
|
for (let line of lines) {
|
||||||
|
|
|
@ -271,7 +271,7 @@ describe("test the string helpers", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("test the comparison helpers", () => {
|
describe("test the comparison helpers", () => {
|
||||||
async function compare(func, a, b) {
|
async function compare(func: string, a: any, b: any) {
|
||||||
const output = await processString(
|
const output = await processString(
|
||||||
`{{ #${func} a b }}Success{{ else }}Fail{{ /${func} }}`,
|
`{{ #${func} a b }}Success{{ else }}Fail{{ /${func} }}`,
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,7 +3,7 @@ import vm from "vm"
|
||||||
import { processStringSync, encodeJSBinding, setJSRunner } from "../src/index"
|
import { processStringSync, encodeJSBinding, setJSRunner } from "../src/index"
|
||||||
import { UUID_REGEX } from "./constants"
|
import { UUID_REGEX } from "./constants"
|
||||||
|
|
||||||
const processJS = (js, context?): any => {
|
const processJS = (js: string, context?: object): any => {
|
||||||
return processStringSync(encodeJSBinding(js), context)
|
return processStringSync(encodeJSBinding(js), context)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ import { getParsedManifest, runJsHelpersTests } from "./utils"
|
||||||
|
|
||||||
tk.freeze("2021-01-21T12:00:00")
|
tk.freeze("2021-01-21T12:00:00")
|
||||||
|
|
||||||
function escapeRegExp(string) {
|
function escapeRegExp(string: string) {
|
||||||
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") // $& means the whole matched string
|
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") // $& means the whole matched string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,9 +40,9 @@ describe("manifest", () => {
|
||||||
describe("examples are valid", () => {
|
describe("examples are valid", () => {
|
||||||
describe.each(Object.keys(manifest))("%s", collection => {
|
describe.each(Object.keys(manifest))("%s", collection => {
|
||||||
it.each(manifest[collection])("%s", async (_, { hbs, js }) => {
|
it.each(manifest[collection])("%s", async (_, { hbs, js }) => {
|
||||||
const context = {
|
const context: any = {
|
||||||
double: i => i * 2,
|
double: (i: number) => i * 2,
|
||||||
isString: x => typeof x === "string",
|
isString: (x: any) => typeof x === "string",
|
||||||
}
|
}
|
||||||
|
|
||||||
const arrays = hbs.match(/\[[^/\]]+\]/)
|
const arrays = hbs.match(/\[[^/\]]+\]/)
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { getJsHelperList } from "../src/helpers"
|
||||||
|
|
||||||
import { convertToJS, processStringSync, encodeJSBinding } from "../src/index"
|
import { convertToJS, processStringSync, encodeJSBinding } from "../src/index"
|
||||||
|
|
||||||
function tryParseJson(str) {
|
function tryParseJson(str: string) {
|
||||||
if (typeof str !== "string") {
|
if (typeof str !== "string") {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ type ExampleType = [
|
||||||
]
|
]
|
||||||
|
|
||||||
export const getParsedManifest = () => {
|
export const getParsedManifest = () => {
|
||||||
const manifest = getManifest()
|
const manifest: any = getManifest()
|
||||||
const collections = Object.keys(manifest)
|
const collections = Object.keys(manifest)
|
||||||
|
|
||||||
const examples = collections.reduce((acc, collection) => {
|
const examples = collections.reduce((acc, collection) => {
|
||||||
|
@ -73,14 +73,14 @@ export const runJsHelpersTests = ({
|
||||||
funcWrap?: any
|
funcWrap?: any
|
||||||
testsToSkip?: any
|
testsToSkip?: any
|
||||||
} = {}) => {
|
} = {}) => {
|
||||||
funcWrap = funcWrap || (delegate => delegate())
|
funcWrap = funcWrap || ((delegate: () => any) => delegate())
|
||||||
const manifest = getParsedManifest()
|
const manifest = getParsedManifest()
|
||||||
|
|
||||||
const processJS = (js, context) => {
|
const processJS = (js: string, context: object | undefined) => {
|
||||||
return funcWrap(() => processStringSync(encodeJSBinding(js), context))
|
return funcWrap(() => processStringSync(encodeJSBinding(js), context))
|
||||||
}
|
}
|
||||||
|
|
||||||
function escapeRegExp(string) {
|
function escapeRegExp(string: string) {
|
||||||
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") // $& means the whole matched string
|
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") // $& means the whole matched string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,9 +98,9 @@ export const runJsHelpersTests = ({
|
||||||
|
|
||||||
examplesToRun.length &&
|
examplesToRun.length &&
|
||||||
it.each(examplesToRun)("%s", async (_, { hbs, js }) => {
|
it.each(examplesToRun)("%s", async (_, { hbs, js }) => {
|
||||||
const context = {
|
const context: any = {
|
||||||
double: i => i * 2,
|
double: (i: number) => i * 2,
|
||||||
isString: x => typeof x === "string",
|
isString: (x: any) => typeof x === "string",
|
||||||
}
|
}
|
||||||
|
|
||||||
const arrays = hbs.match(/\[[^/\]]+\]/)
|
const arrays = hbs.match(/\[[^/\]]+\]/)
|
||||||
|
|
Loading…
Reference in New Issue