Skip to content

Commit 6510d98

Browse files
committed
test: share stack frame util
1 parent 0321a80 commit 6510d98

File tree

4 files changed

+40
-83
lines changed

4 files changed

+40
-83
lines changed

test/development/app-dir/owner-stack-invalid-element-type/owner-stack-invalid-element-type.test.ts

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,9 @@
11
import { nextTestSetup } from 'e2e-utils'
2-
import { assertHasRedbox, getRedboxSource } from 'next-test-utils'
3-
4-
async function getStackFramesContent(browser) {
5-
const stackFrameElements = await browser.elementsByCss(
6-
'[data-nextjs-call-stack-frame]'
7-
)
8-
const stackFramesContent = (
9-
await Promise.all(
10-
stackFrameElements.map(async (frame) => {
11-
const functionNameEl = await frame.$('[data-nextjs-frame-expanded]')
12-
const sourceEl = await frame.$('[data-has-source]')
13-
const functionName = functionNameEl
14-
? await functionNameEl.innerText()
15-
: ''
16-
const source = sourceEl ? await sourceEl.innerText() : ''
17-
18-
if (!functionName) {
19-
return ''
20-
}
21-
return `at ${functionName} (${source})`
22-
})
23-
)
24-
)
25-
.filter(Boolean)
26-
.join('\n')
27-
28-
return stackFramesContent
29-
}
2+
import {
3+
assertHasRedbox,
4+
getRedboxSource,
5+
getStackFramesContent,
6+
} from 'next-test-utils'
307

318
describe('app-dir - owner-stack-invalid-element-type', () => {
329
const { next } = nextTestSetup({

test/development/app-dir/owner-stack-react-missing-key-prop/owner-stack-react-missing-key-prop.test.ts

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,9 @@
11
import { nextTestSetup } from 'e2e-utils'
2-
import { getRedboxSource, waitForAndOpenRuntimeError } from 'next-test-utils'
3-
4-
async function getStackFramesContent(browser) {
5-
const stackFrameElements = await browser.elementsByCss(
6-
'[data-nextjs-call-stack-frame]'
7-
)
8-
const stackFramesContent = (
9-
await Promise.all(
10-
stackFrameElements.map(async (frame) => {
11-
const functionNameEl = await frame.$('[data-nextjs-frame-expanded]')
12-
const sourceEl = await frame.$('[data-has-source]')
13-
const functionName = functionNameEl
14-
? await functionNameEl.innerText()
15-
: ''
16-
const source = sourceEl ? await sourceEl.innerText() : ''
17-
18-
if (!functionName) {
19-
return ''
20-
}
21-
return `at ${functionName} (${source})`
22-
})
23-
)
24-
)
25-
.filter(Boolean)
26-
.join('\n')
27-
28-
return stackFramesContent
29-
}
2+
import {
3+
getRedboxSource,
4+
waitForAndOpenRuntimeError,
5+
getStackFramesContent,
6+
} from 'next-test-utils'
307

318
describe('owner-stack-react-missing-key-prop', () => {
329
const { next } = nextTestSetup({

test/development/app-dir/owner-stack/owner-stack.test.ts

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
assertNoRedbox,
55
waitForAndOpenRuntimeError,
66
getRedboxDescription,
7+
getStackFramesContent,
78
} from 'next-test-utils'
89

910
// TODO: parse the location and assert them in the future
@@ -17,33 +18,6 @@ function normalizeStackTrace(trace: string) {
1718
.trim()
1819
}
1920

20-
async function getStackFramesContent(browser) {
21-
const stackFrameElements = await browser.elementsByCss(
22-
'[data-nextjs-call-stack-frame]'
23-
)
24-
const stackFramesContent = (
25-
await Promise.all(
26-
stackFrameElements.map(async (frame) => {
27-
const functionNameEl = await frame.$('[data-nextjs-frame-expanded]')
28-
const sourceEl = await frame.$('[data-has-source]')
29-
const functionName = functionNameEl
30-
? await functionNameEl.innerText()
31-
: ''
32-
const source = sourceEl ? await sourceEl.innerText() : ''
33-
34-
if (!functionName) {
35-
return ''
36-
}
37-
return `at ${functionName} (${source})`
38-
})
39-
)
40-
)
41-
.filter(Boolean)
42-
.join('\n')
43-
44-
return stackFramesContent
45-
}
46-
4721
describe('app-dir - owner-stack', () => {
4822
const { next } = nextTestSetup({
4923
files: __dirname,

test/lib/next-test-utils.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,3 +1492,32 @@ export const checkLink = (
14921492
rel: string,
14931493
content: string | string[]
14941494
) => checkMeta(browser, rel, content, 'rel', 'link', 'href')
1495+
1496+
export async function getStackFramesContent(
1497+
browser: BrowserInterface
1498+
): Promise<string> {
1499+
const stackFrameElements = await browser.elementsByCss(
1500+
'[data-nextjs-call-stack-frame]'
1501+
)
1502+
const stackFramesContent = (
1503+
await Promise.all(
1504+
stackFrameElements.map(async (frame) => {
1505+
const functionNameEl = await frame.$('[data-nextjs-frame-expanded]')
1506+
const sourceEl = await frame.$('[data-has-source]')
1507+
const functionName = functionNameEl
1508+
? await functionNameEl.innerText()
1509+
: ''
1510+
const source = sourceEl ? await sourceEl.innerText() : ''
1511+
1512+
if (!functionName) {
1513+
return ''
1514+
}
1515+
return `at ${functionName} (${source})`
1516+
})
1517+
)
1518+
)
1519+
.filter(Boolean)
1520+
.join('\n')
1521+
1522+
return stackFramesContent
1523+
}

0 commit comments

Comments
 (0)