11import { expect } from 'chai' ;
22import sinon from 'sinon' ;
3+ import { record as rrwebRecordFn } from '@rrweb/record' ;
34import { EventType } from '@rrweb/types' ;
45
56import Recorder from '../src/browser/replay/recorder.js' ;
@@ -65,17 +66,16 @@ describe('Recorder', function () {
6566 } ) ;
6667 } ) ;
6768
68- it ( 'should throw error if no record function is passed' , function ( ) {
69- expect ( ( ) => new Recorder ( { } , null ) ) . to . throw (
70- TypeError ,
71- "Expected 'recordFn' to be provided" ,
72- ) ;
69+ it ( 'should use the default recorder if no record function is passed' , function ( ) {
70+ const recorder = new Recorder ( { } ) ;
71+
72+ expect ( recorder . _recordFn ) . to . equal ( rrwebRecordFn ) ;
7373 } ) ;
7474 } ) ;
7575
7676 describe ( 'recording management' , function ( ) {
7777 it ( 'should start recording correctly' , function ( ) {
78- const recorder = new Recorder ( { enabled : true } , recordFnStub ) ;
78+ const recorder = new Recorder ( { enabled : true , recordFn : recordFnStub } ) ;
7979 recorder . start ( ) ;
8080
8181 expect ( recorder . isRecording ) . to . be . true ;
@@ -88,23 +88,23 @@ describe('Recorder', function () {
8888 } ) ;
8989
9090 it ( 'should not start if already recording' , function ( ) {
91- const recorder = new Recorder ( { enabled : true } , recordFnStub ) ;
91+ const recorder = new Recorder ( { enabled : true , recordFn : recordFnStub } ) ;
9292 recorder . start ( ) ;
9393 recorder . start ( ) ;
9494
9595 expect ( recordFnStub . calledOnce ) . to . be . true ;
9696 } ) ;
9797
9898 it ( 'should not start if disabled' , function ( ) {
99- const recorder = new Recorder ( { enabled : false } , recordFnStub ) ;
99+ const recorder = new Recorder ( { enabled : false , recordFn : recordFnStub } ) ;
100100 recorder . start ( ) ;
101101
102102 expect ( recorder . isRecording ) . to . be . false ;
103103 expect ( recordFnStub . called ) . to . be . false ;
104104 } ) ;
105105
106106 it ( 'should stop recording correctly' , function ( ) {
107- const recorder = new Recorder ( { enabled : true } , recordFnStub ) ;
107+ const recorder = new Recorder ( { enabled : true , recordFn : recordFnStub } ) ;
108108 recorder . start ( ) ;
109109 recorder . stop ( ) ;
110110
@@ -124,7 +124,7 @@ describe('Recorder', function () {
124124
125125 describe ( 'event handling' , function ( ) {
126126 it ( 'should handle events correctly' , function ( ) {
127- const recorder = new Recorder ( { } , recordFnStub ) ;
127+ const recorder = new Recorder ( { recordFn : recordFnStub } ) ;
128128 recorder . start ( ) ;
129129
130130 const event1 = { timestamp : 1000 , type : 'event1' , data : { a : 1 } } ;
@@ -166,7 +166,7 @@ describe('Recorder', function () {
166166 } ) ;
167167
168168 it ( 'should be ready after first full snapshot' , function ( ) {
169- const recorder = new Recorder ( { } , recordFnStub ) ;
169+ const recorder = new Recorder ( { recordFn : recordFnStub } ) ;
170170 recorder . start ( ) ;
171171
172172 // First checkout
@@ -181,7 +181,7 @@ describe('Recorder', function () {
181181 } ) ;
182182
183183 it ( 'should handle checkout events correctly' , function ( ) {
184- const recorder = new Recorder ( { } , recordFnStub ) ;
184+ const recorder = new Recorder ( { recordFn : recordFnStub } ) ;
185185 recorder . start ( ) ;
186186
187187 // First checkout
@@ -308,7 +308,7 @@ describe('Recorder', function () {
308308
309309 describe ( 'dump functionality' , function ( ) {
310310 it ( 'should create a span with events and return formatted payload' , function ( ) {
311- const recorder = new Recorder ( { } , recordFnStub ) ;
311+ const recorder = new Recorder ( { recordFn : recordFnStub } ) ;
312312 recorder . start ( ) ;
313313
314314 emitCallback ( { timestamp : 1000 , type : 'event1' , data : { a : 1 } } , false ) ;
@@ -355,7 +355,7 @@ describe('Recorder', function () {
355355 } ) ;
356356
357357 it ( 'should create a span with the correct span name' , function ( ) {
358- const recorder = new Recorder ( { } , recordFnStub ) ;
358+ const recorder = new Recorder ( { recordFn : recordFnStub } ) ;
359359 recorder . start ( ) ;
360360
361361 emitCallback ( { timestamp : 1000 , type : 'event1' , data : { a : 1 } } , false ) ;
@@ -371,7 +371,7 @@ describe('Recorder', function () {
371371 } ) ;
372372
373373 it ( 'should add events with the correct event name and replayId' , function ( ) {
374- const recorder = new Recorder ( { } , recordFnStub ) ;
374+ const recorder = new Recorder ( { recordFn : recordFnStub } ) ;
375375 recorder . start ( ) ;
376376
377377 emitCallback (
@@ -402,7 +402,7 @@ describe('Recorder', function () {
402402 } ) ;
403403
404404 it ( 'should handle no events' , function ( ) {
405- const recorder = new Recorder ( { } , recordFnStub ) ;
405+ const recorder = new Recorder ( { recordFn : recordFnStub } ) ;
406406
407407 expect ( ( ) => {
408408 recorder . exportRecordingSpan ( mockTracing , {
@@ -417,7 +417,7 @@ describe('Recorder', function () {
417417
418418 describe ( 'configure' , function ( ) {
419419 it ( 'should update options' , function ( ) {
420- const recorder = new Recorder ( { enabled : true } , recordFnStub ) ;
420+ const recorder = new Recorder ( { enabled : true , recordFn : recordFnStub } ) ;
421421
422422 recorder . configure ( { enabled : false , maxSeconds : 20 } ) ;
423423
@@ -449,7 +449,7 @@ describe('Recorder', function () {
449449 } ) ;
450450
451451 it ( 'should stop recording if enabled set to false' , function ( ) {
452- const recorder = new Recorder ( { enabled : true } , recordFnStub ) ;
452+ const recorder = new Recorder ( { enabled : true , recordFn : recordFnStub } ) ;
453453 recorder . start ( ) ;
454454
455455 expect ( recorder . isRecording ) . to . be . true ;
0 commit comments