Skip to content

Commit

Permalink
Add structured stack trace tests to jest scenario.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalton committed Aug 16, 2018
1 parent e8f9fcf commit 8216c8f
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
"use strict"

const { prepareStackTrace } = Error

Error.prepareStackTrace = (error, structuredStackTrace) => structuredStackTrace

const error = new Error

Error.captureStackTrace(error)

const CJS_STRUCTURED_STACK_TRACE = error.stack

Error.prepareStackTrace = prepareStackTrace

module.exports = {
CJS_BUFFER_PROP: global.Buffer,
CJS_BUFFER_VAR: Buffer,
Expand All @@ -19,6 +31,7 @@ module.exports = {
CJS_SET_INTERVAL_VAR: setInterval,
CJS_SET_TIMEOUT_PROP: global.setTimeout,
CJS_SET_TIMEOUT_VAR: setTimeout,
CJS_STRUCTURED_STACK_TRACE,
CJS_URL_PROP: global.URL,
CJS_URL_SEARCH_PARAMS_PROP: global.URLSearchParams,
CJS_URL_SEARCH_PARAMS_VAR: typeof URLSearchParams === "undefined" ? void 0 : URLSearchParams,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
const { prepareStackTrace } = Error

Error.prepareStackTrace = (error, structuredStackTrace) => structuredStackTrace

const error = new Error

Error.captureStackTrace(error)

export const ESM_STRUCTURED_STACK_TRACE = error.stack

Error.prepareStackTrace = prepareStackTrace

export const ESM_BUFFER_PROP = global.Buffer
export const ESM_BUFFER_VAR = Buffer
export const ESM_CLEAR_IMMEDIATE_PROP = global.clearImmediate
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
"use strict"

test("test", () => {
const expectedValues = {
CJS_JEST_GLOBAL_VAR: "JEST_GLOBAL_VALUE",
CJS_JEST_GLOBAL_PROP: "JEST_GLOBAL_VALUE",
ESM_JEST_GLOBAL_VAR: "JEST_GLOBAL_VALUE",
ESM_JEST_GLOBAL_PROP: "JEST_GLOBAL_VALUE"
}
const arrayNames = [
"CJS_STRUCTURED_STACK_TRACE",
"ESM_STRUCTURED_STACK_TRACE"
]

const funcNames = [
"CJS_BUFFER_PROP",
Expand Down Expand Up @@ -52,7 +50,18 @@ test("test", () => {
"ESM_PROCESS_VAR"
]

const expectedValues = {
CJS_JEST_GLOBAL_VAR: "JEST_GLOBAL_VALUE",
CJS_JEST_GLOBAL_PROP: "JEST_GLOBAL_VALUE",
ESM_JEST_GLOBAL_VAR: "JEST_GLOBAL_VALUE",
ESM_JEST_GLOBAL_PROP: "JEST_GLOBAL_VALUE"
}

function checkTypes(actual) {
for (const name of arrayNames) {
expect(Array.isArray(actual[name])).toBe(true)
}

for (const name of funcNames) {
expect(typeof actual[name]).toBe("function")
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions test/scenario-tests.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ describe("scenario tests", function () {
}
})

it("should carry over the global object of jest", function () {
const dirPath = path.resolve(testPath, "fixture/scenario/jest-global-object")
it("should carry over the context object of jest", function () {
const dirPath = path.resolve(testPath, "fixture/scenario/jest-context")
const configPath = path.resolve(dirPath, "jest.config.json")

return exec("jest", [
Expand All @@ -239,7 +239,7 @@ describe("scenario tests", function () {
})

it("should carry over the process object of jest", function () {
const dirPath = path.resolve(testPath, "fixture/scenario/jest-process-object")
const dirPath = path.resolve(testPath, "fixture/scenario/jest-process")
const configPath = path.resolve(dirPath, "jest.config.json")

return exec("jest", [
Expand Down

0 comments on commit 8216c8f

Please sign in to comment.