Skip to content

Commit c5ce4ca

Browse files
committed
Add remaining integration tests
1 parent 501543d commit c5ce4ca

File tree

2 files changed

+55
-12
lines changed

2 files changed

+55
-12
lines changed

src/index.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export class Extension implements StringifyExtension {
121121
}
122122
}
123123

124-
function stringifySelector(selector: Selector) {
124+
export function stringifySelector(selector: Selector) {
125125
const selectorString = Array.isArray(selector) ? selector[0] : selector
126126

127127
if (selectorString.startsWith("aria/")) {
@@ -131,19 +131,20 @@ function stringifySelector(selector: Selector) {
131131
}
132132
}
133133

134-
if (process.env.NODE_ENV !== "test") {
135-
class RecorderPlugin
136-
implements chrome.devtools.recorder.RecorderExtensionPlugin
137-
{
138-
stringify(recording: UserFlow) {
139-
return stringify(recording, { extension: new Extension() })
140-
}
134+
export class RecorderPlugin
135+
implements chrome.devtools.recorder.RecorderExtensionPlugin
136+
{
137+
stringify(recording: UserFlow) {
138+
return stringify(recording, { extension: new Extension() })
139+
}
141140

142-
stringifyStep(step: Step) {
143-
return stringifyStep(step, { extension: new Extension() })
144-
}
141+
stringifyStep(step: Step) {
142+
return stringifyStep(step, { extension: new Extension() })
145143
}
144+
}
146145

146+
// istanbul ignore next
147+
if (process.env.NODE_ENV !== "test") {
147148
chrome.devtools.recorder.registerRecorderExtensionPlugin(
148149
new RecorderPlugin(),
149150
"Testing Library",

src/test.ts

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
type Step,
88
type UserFlow,
99
} from "@puppeteer/replay"
10-
import { Extension } from "."
10+
import { Extension, RecorderPlugin, stringifySelector } from "."
1111
import flow from "./fixtures/Example.json"
1212

1313
const extension = new Extension()
@@ -110,6 +110,16 @@ describe("Extension", () => {
110110
},
111111
'await userEvent.dblClick(screen.getByText("Test"))',
112112
],
113+
[
114+
{
115+
type: "doubleClick",
116+
selectors,
117+
button: "secondary",
118+
offsetX: 0,
119+
offsetY: 0,
120+
},
121+
'await userEvent.dblClick(screen.getByText("Test"), { buttons: 2 })',
122+
],
113123
[
114124
{
115125
type: "keyDown",
@@ -138,6 +148,14 @@ describe("Extension", () => {
138148
},
139149
'expect(location.href).toBe("https://example.com/")\nexpect(document.title).toBe("Example Domain")',
140150
],
151+
[
152+
{
153+
type: "navigate",
154+
url: "https://example.com/",
155+
assertedEvents: [{ type: "navigation" }],
156+
},
157+
"",
158+
],
141159
[
142160
{
143161
type: "waitForElement",
@@ -157,3 +175,27 @@ describe("Extension", () => {
157175
})
158176
})
159177
})
178+
179+
describe("stringifySelector", () => {
180+
test("aria", () => {
181+
expect(stringifySelector("aria/Test")).toBe('screen.getByText("Test")')
182+
})
183+
184+
test("selector", () => {
185+
expect(stringifySelector("p")).toBe('document.querySelector("p")')
186+
})
187+
})
188+
189+
describe("RecorderPlugin", () => {
190+
test("stringify", async () => {
191+
expect(await new RecorderPlugin().stringify(flow as UserFlow)).toBe(
192+
await readFile(join(__dirname, "fixtures/example.test.js"), "utf8"),
193+
)
194+
})
195+
196+
test("stringifyStep", async () => {
197+
expect(
198+
await new RecorderPlugin().stringifyStep(flow.steps[1] as Step),
199+
).toBe('await waitFor(() => screen.getByText("More information..."))\n')
200+
})
201+
})

0 commit comments

Comments
 (0)