@@ -4,7 +4,10 @@ const FixtureBuilder = require('../fixture-builder');
44const {
55 ACTION_QUEUE_METRICS_E2E_TEST ,
66} = require ( '../../../shared/constants/test-flags' ) ;
7- const { EVENT_NAMES , EVENT } = require ( '../../../shared/constants/metametrics' ) ;
7+ const {
8+ MetaMetricsEventName,
9+ MetaMetricsEventCategory,
10+ } = require ( '../../../shared/constants/metametrics' ) ;
811
912const PRIVATE_KEY =
1013 '0x7C9529A67102755B7E6102D6D950AC5D5863C98713805CEC576B945B15B71EAC' ;
@@ -14,15 +17,15 @@ const defaultGanacheOptions = {
1417 accounts : [ { secretKey : PRIVATE_KEY , balance : generateETHBalance ( 25 ) } ] ,
1518} ;
1619
17- const numberOfSegmentRequests = 1 ;
20+ const numberOfSegmentRequests = 2 ;
1821
1922async function mockSegment ( mockServer ) {
2023 return await mockServer
2124 . forPost ( 'https://api.segment.io/v1/batch' )
2225 . withJsonBodyIncluding ( {
2326 batch : [
2427 {
25- event : EVENT_NAMES . SERVICE_WORKER_RESTARTED ,
28+ event : MetaMetricsEventName . ServiceWorkerRestarted ,
2629 } ,
2730 ] ,
2831 } )
@@ -50,6 +53,7 @@ describe('MV3 - Service worker restart', function () {
5053 let windowHandles ;
5154
5255 it ( 'should continue to add new a account when service worker can not restart immediately' , async function ( ) {
56+ const driverOptions = { openDevToolsForTabs : true } ;
5357 await withFixtures (
5458 {
5559 dapp : true ,
@@ -67,6 +71,7 @@ describe('MV3 - Service worker restart', function () {
6771 // because of segment
6872 failOnConsoleError : false ,
6973 testSpecificMock : mockPostToSentryEnvelope ,
74+ driverOptions,
7075 } ,
7176 async ( { driver, mockServer } ) => {
7277 const mockedSegmentEndpoints = await mockSegment ( mockServer ) ;
@@ -126,22 +131,23 @@ describe('MV3 - Service worker restart', function () {
126131 assert . equal ( mockedRequests [ 0 ] . body . json . batch . length , 1 ) ;
127132 assert . equal (
128133 mockedRequests [ 0 ] . body . json . batch [ 0 ] . event ,
129- EVENT_NAMES . SERVICE_WORKER_RESTARTED ,
134+ MetaMetricsEventName . ServiceWorkerRestarted ,
130135 ) ;
131136
132137 assert . equal (
133- mockedRequests [ 0 ] . body . json . batch [ 0 ] . properties . service_worker_action_queue_methods . indexOf (
134- 'addNewAccount' ,
135- ) !== '-1' ,
136- true ,
138+ typeof mockedRequests [ 0 ] . body . json . batch [ 0 ] . properties
139+ . service_worker_restarted_time ,
140+ 'number' ,
137141 ) ;
142+
138143 assert . equal (
139- mockedRequests [ 0 ] . body . json . batch [ 0 ] . properties . category ,
140- EVENT . SOURCE . SERVICE_WORKERS ,
144+ mockedRequests [ 0 ] . body . json . batch [ 0 ] . properties
145+ . service_worker_restarted_time > 0 ,
146+ true ,
141147 ) ;
142148 assert . equal (
143149 mockedRequests [ 0 ] . body . json . batch [ 0 ] . properties . category ,
144- EVENT . SOURCE . SERVICE_WORKERS ,
150+ MetaMetricsEventCategory . ServiceWorkers ,
145151 ) ;
146152 assert . equal (
147153 mockedRequests [ 0 ] . body . json . batch [ 0 ] . properties . chain_id ,
@@ -159,24 +165,33 @@ describe('MV3 - Service worker restart', function () {
159165 assert . equal ( mockedRequests [ 1 ] . url , 'https://api.segment.io/v1/batch' ) ;
160166
161167 assert . equal ( mockedRequests [ 1 ] . body . json . batch . length , 1 ) ;
168+
162169 assert . equal (
163- mockedRequests [ 1 ] . body . json . batch [ 1 ] . event ,
164- EVENT_NAMES . SERVICE_WORKER_RESTARTED ,
170+ mockedRequests [ 1 ] . body . json . batch [ 0 ] . event ,
171+ MetaMetricsEventName . ServiceWorkerRestarted ,
165172 ) ;
166173
167- const serviceWorkerRestartTimeRequestProperties =
168- mockedRequests [ 1 ] . body . json . batch [ 1 ] . properties ;
169174 assert . equal (
170- serviceWorkerRestartTimeRequestProperties . category ,
171- EVENT . SOURCE . SERVICE_WORKERS ,
175+ mockedRequests [ 1 ] . body . json . batch [ 0 ] . properties . service_worker_action_queue_methods . indexOf (
176+ 'addNewAccount' ,
177+ ) !== '-1' ,
178+ true ,
179+ ) ;
180+ assert . equal (
181+ mockedRequests [ 1 ] . body . json . batch [ 0 ] . properties . category ,
182+ MetaMetricsEventCategory . ServiceWorkers ,
183+ ) ;
184+ assert . equal (
185+ mockedRequests [ 1 ] . body . json . batch [ 0 ] . properties . chain_id ,
186+ convertToHexValue ( 1337 ) ,
172187 ) ;
173- assert (
174- typeof serviceWorkerRestartTimeRequestProperties . service_worker_action_queue_methods ===
175- 'number ',
188+ assert . equal (
189+ mockedRequests [ 1 ] . body . json . batch [ 0 ] . properties . environment_type ,
190+ 'background ',
176191 ) ;
177- assert (
178- serviceWorkerRestartTimeRequestProperties . service_worker_action_queue_methods >
179- 0 ,
192+ assert . equal (
193+ mockedRequests [ 1 ] . body . json . batch [ 0 ] . properties . locale ,
194+ 'en' ,
180195 ) ;
181196 } ,
182197 ) ;
0 commit comments