Skip to content

Commit 49eb2a1

Browse files
committed
Set up an integration test
1 parent 2d9744e commit 49eb2a1

File tree

7 files changed

+9770
-4152
lines changed

7 files changed

+9770
-4152
lines changed

package-lock.json

Lines changed: 9678 additions & 4140 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
"scripts": {
44
"start": "webpack --mode=development --watch",
55
"build": "webpack --mode=production",
6-
"test": "tsc"
6+
"type": "tsc",
7+
"test": "jest"
78
},
89
"dependencies": {
910
"@babel/core": "^7.18.10",
1011
"@babel/preset-env": "^7.18.10",
1112
"@babel/preset-typescript": "^7.18.6",
1213
"@puppeteer/replay": "^0.6.1",
14+
"@types/jest": "^28.1.6",
15+
"jest": "^28.1.3",
1316
"babel-loader": "^8.2.5",
1417
"copy-webpack-plugin": "^11.0.0",
1518
"html-webpack-plugin": "^5.5.0",
@@ -27,5 +30,10 @@
2730
]
2831
},
2932
"browserslist": "chrome 104",
33+
"jest": {
34+
"testPathIgnorePatterns": [
35+
"/fixtures/"
36+
]
37+
},
3038
"prettier": "prettier-config-nick"
3139
}

src/fixtures/Example.json

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"title": "Example",
3+
"steps": [
4+
{
5+
"type": "setViewport",
6+
"width": 0,
7+
"height": 0,
8+
"deviceScaleFactor": 1,
9+
"isMobile": false,
10+
"hasTouch": false,
11+
"isLandscape": false
12+
},
13+
{
14+
"type": "navigate",
15+
"url": "https://example.com/",
16+
"assertedEvents": [
17+
{
18+
"type": "navigation",
19+
"url": "https://example.com/",
20+
"title": "Example Domain"
21+
}
22+
]
23+
},
24+
{
25+
"type": "click",
26+
"target": "main",
27+
"selectors": [
28+
["aria/More information..."],
29+
["body > div > p:nth-child(3) > a"]
30+
],
31+
"offsetY": 0,
32+
"offsetX": 0,
33+
"assertedEvents": [
34+
{
35+
"type": "navigation",
36+
"url": "https://www.iana.org/domains/reserved",
37+
"title": ""
38+
}
39+
]
40+
}
41+
]
42+
}

src/fixtures/example.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* @jest-environment url
3+
* @jest-environment-options { "url": "https://example.com/" }
4+
*/
5+
const { screen } = require("@testing-library/dom")
6+
require("@testing-library/jest-dom")
7+
8+
test("Example", () => {
9+
expect(location.href).toBe("https://example.com/")
10+
expect(screen.getByText("Example Domain")).toBeInTheDocument()
11+
})

src/index.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
import { stringify, type UserFlow } from "@puppeteer/replay"
1+
import { stringify, StringifyExtension, type UserFlow } from "@puppeteer/replay"
22

3-
class RecorderPlugin {
4-
stringify(recording: UserFlow) {
5-
return stringify(recording)
3+
export class Extension extends StringifyExtension {}
4+
5+
if (process.env.NODE_ENV !== "test") {
6+
class RecorderPlugin {
7+
stringify(recording: UserFlow) {
8+
return stringify(recording, { extension: new Extension() })
9+
}
610
}
7-
}
811

9-
chrome.devtools.recorder.registerRecorderExtensionPlugin(
10-
new RecorderPlugin(),
11-
"Testing Library",
12-
"application/javascript",
13-
)
12+
chrome.devtools.recorder.registerRecorderExtensionPlugin(
13+
new RecorderPlugin(),
14+
"Testing Library",
15+
"application/javascript",
16+
)
17+
}

src/test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { readFile } from "fs/promises"
2+
import { join } from "path"
3+
import { stringify, UserFlow } from "@puppeteer/replay"
4+
import { Extension } from "."
5+
import flow from "./fixtures/Example.json"
6+
7+
test("Extension", async () => {
8+
expect(
9+
await stringify(flow as UserFlow, { extension: new Extension() }),
10+
).toBe(await readFile(join(__dirname, "fixtures/example.test.js"), "utf8"))
11+
})

tsconfig.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
{
22
"compilerOptions": {
3+
"noFallthroughCasesInSwitch": true,
4+
"noUnusedLocals": true,
5+
"noUnusedParameters": true,
36
"strict": true,
47
"moduleResolution": "Node",
8+
"resolveJsonModule": true,
59
"noEmit": true,
610
"checkJs": true,
711
"esModuleInterop": true,
812
"target": "ES2015"
913
},
10-
"exclude": ["dist"]
14+
"exclude": ["src/fixtures/*.test.*", "dist"]
1115
}

0 commit comments

Comments
 (0)