@@ -30,6 +30,8 @@ import { Playwright } from 'next-webdriver'
...
@@ -30,6 +30,8 @@ import { Playwright } from 'next-webdriver'
import{shouldUseTurbopack}from'./turbo'
import{shouldUseTurbopack}from'./turbo'
importstripAnsifrom'strip-ansi'
importstripAnsifrom'strip-ansi'
importescapeRegexfrom'escape-string-regexp'
// TODO: Create dedicated Jest environment that sets up these matchers
// TODO: Create dedicated Jest environment that sets up these matchers
// Edge Runtime unit tests fail with "EvalError: Code generation from strings disallowed for this context" if these matchers are imported in those tests.
// Edge Runtime unit tests fail with "EvalError: Code generation from strings disallowed for this context" if these matchers are imported in those tests.
import'./add-redbox-matchers'
import'./add-redbox-matchers'
...
@@ -1830,3 +1832,41 @@ export function trimEndMultiline(str: string) {
...
@@ -1830,3 +1832,41 @@ export function trimEndMultiline(str: string) {
.map((line)=>line.trimEnd())
.map((line)=>line.trimEnd())
.join('\n')
.join('\n')
}
}
/**
* Normalizes the manifest by applying the replacements to the manifest. This
* is useful for testing the manifest in a snapshot test.
*
* @param manifest - The manifest to normalize.
* @param replacements - The replacements to perform on the manifest.
* @returns The normalized manifest.
*/
exportfunctionnormalizeManifest<T>(
manifest:unknown,
replacements:[search:string,replace:string][]
):T{
returnJSON.parse(
replacements.reduce(
(acc,[search,replace])=>
acc.replace(
newRegExp(
// We want to match the literal string, so we need to escape it
// again
escapeRegex(
JSON.stringify(
// The output has already been escaped, so we need to escape our
// search string.
escapeRegex(search)
)
// Remove the quotes added by the JSON.stringify call.
.replace(/^"(.*)"/,'$1')
),
'g'
),
replace
),
// We'll perform the replacements on the JSON stringified manifest.