Adding test checks.
This commit is contained in:
parent
fb41c72f80
commit
ae73c0147f
|
@ -0,0 +1,11 @@
|
|||
function isJest() {
|
||||
return (
|
||||
process.env.NODE_ENV === "jest" ||
|
||||
(process.env.JEST_WORKER_ID != null &&
|
||||
process.env.JEST_WORKER_ID !== "null")
|
||||
)
|
||||
}
|
||||
|
||||
export function isTest() {
|
||||
return isJest()
|
||||
}
|
|
@ -10,6 +10,7 @@ import { iifeWrapper } from "../iife"
|
|||
import { JsTimeoutError, UserScriptError } from "../errors"
|
||||
import { cloneDeep } from "lodash/fp"
|
||||
import { Log, LogType } from "../types"
|
||||
import { isTest } from "../environment"
|
||||
|
||||
// The method of executing JS scripts depends on the bundle being built.
|
||||
// This setter is used in the entrypoint (either index.js or index.mjs).
|
||||
|
@ -126,7 +127,9 @@ export function processJS(handlebars: string, context: any) {
|
|||
const jsLineCount = frontendWrapJS(js).split(js)[0].split("\n").length
|
||||
const buildLogResponse = (type: LogType) => {
|
||||
return (...props: any[]) => {
|
||||
console[type](...props)
|
||||
if (!isTest()) {
|
||||
console[type](...props)
|
||||
}
|
||||
props.forEach((prop, index) => {
|
||||
if (typeof prop === "object") {
|
||||
props[index] = JSON.stringify(prop)
|
||||
|
|
|
@ -43,4 +43,11 @@ describe("Javascript", () => {
|
|||
expect(output.logs[0].line).toEqual(1)
|
||||
expect(output.logs[0].type).toEqual("warn")
|
||||
})
|
||||
|
||||
it("should return the type working with error", () => {
|
||||
const output = processJS(`console.error("error"); return 1`)
|
||||
expect(output.logs[0].log).toEqual(["error"])
|
||||
expect(output.logs[0].line).toEqual(1)
|
||||
expect(output.logs[0].type).toEqual("error")
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue