Introduce benchmark tests and improve snapshot attributes traversing (#897)

* housekeeping: refine test utils

* setup benchmark tests

* improve snapshot attributes loop perf
This commit is contained in:
yz-yu
2026-04-01 12:00:00 +08:00
committed by GitHub
parent 2887c8c7e5
commit 4cfd9db6cf
8 changed files with 215 additions and 73 deletions

View File

@@ -1,6 +1,6 @@
// tslint:disable:no-console
import * as fs from 'fs';
import * as path from 'path';
import type * as http from 'http';
import type * as puppeteer from 'puppeteer';
import {
assertSnapshot,
@@ -9,21 +9,12 @@ import {
launchPuppeteer,
waitForRAF,
replaceLast,
generateRecordSnippet,
ISuite,
} from './utils';
import { recordOptions, eventWithTime, EventType } from '../src/types';
import { visitSnapshot, NodeType } from 'rrweb-snapshot';
interface ISuite {
server: http.Server;
serverURL: string;
code: string;
browser: puppeteer.Browser;
}
interface IMimeType {
[key: string]: string;
}
describe('record integration tests', function (this: ISuite) {
jest.setTimeout(10_000);
@@ -40,19 +31,7 @@ describe('record integration tests', function (this: ISuite) {
<script>
${code}
window.Date.now = () => new Date(Date.UTC(2018, 10, 15, 8)).valueOf();
window.snapshots = [];
rrweb.record({
emit: event => {
window.snapshots.push(event);
},
maskTextSelector: ${JSON.stringify(options.maskTextSelector)},
maskAllInputs: ${options.maskAllInputs},
maskInputOptions: ${JSON.stringify(options.maskAllInputs)},
userTriggeredOnInput: ${options.userTriggeredOnInput},
maskTextFn: ${options.maskTextFn},
recordCanvas: ${options.recordCanvas},
plugins: ${options.plugins}
});
${generateRecordSnippet(options)}
</script>
</body>
`,
@@ -73,7 +52,7 @@ describe('record integration tests', function (this: ISuite) {
const pluginsCode = [
path.resolve(__dirname, '../dist/plugins/console-record.min.js'),
]
.map((path) => fs.readFileSync(path, 'utf8'))
.map((p) => fs.readFileSync(p, 'utf8'))
.join();
code = fs.readFileSync(bundlePath, 'utf8') + pluginsCode;
});