@@ -3,27 +3,17 @@ import * as childProcess from 'child_process';
33import * as http from 'http' ;
44import * as Busboy from 'busboy' ;
55import * as path from 'path' ;
6- import { ifdescribe , ifit } from './spec-helpers' ;
6+ import { ifdescribe , ifit , defer , startRemoteControlApp } from './spec-helpers' ;
77import { app } from 'electron/main' ;
88import { crashReporter } from 'electron/common' ;
99import { AddressInfo } from 'net' ;
1010import { EventEmitter } from 'events' ;
1111import * as fs from 'fs' ;
12- import * as v8 from 'v8' ;
1312import * as uuid from 'uuid' ;
1413
1514const isWindowsOnArm = process . platform === 'win32' && process . arch === 'arm64' ;
1615const isLinuxOnArm = process . platform === 'linux' && process . arch . includes ( 'arm' ) ;
1716
18- const afterTest : ( ( ( ) => void ) | ( ( ) => Promise < void > ) ) [ ] = [ ] ;
19- async function cleanup ( ) {
20- for ( const cleanup of afterTest ) {
21- const r = cleanup ( ) ;
22- if ( r instanceof Promise ) { await r ; }
23- }
24- afterTest . length = 0 ;
25- }
26-
2717type CrashInfo = {
2818 prod : string
2919 ver : string
@@ -57,49 +47,6 @@ function checkCrash (expectedProcessType: string, fields: CrashInfo) {
5747 }
5848}
5949
60- const startRemoteControlApp = async ( ) => {
61- const appPath = path . join ( __dirname , 'fixtures' , 'apps' , 'remote-control' ) ;
62- const appProcess = childProcess . spawn ( process . execPath , [ appPath ] ) ;
63- appProcess . stderr . on ( 'data' , d => {
64- process . stderr . write ( d ) ;
65- } ) ;
66- const port = await new Promise < number > ( resolve => {
67- appProcess . stdout . on ( 'data' , d => {
68- const m = / L i s t e n i n g : ( \d + ) / . exec ( d . toString ( ) ) ;
69- if ( m && m [ 1 ] != null ) {
70- resolve ( Number ( m [ 1 ] ) ) ;
71- }
72- } ) ;
73- } ) ;
74- function remoteEval ( js : string ) : any {
75- return new Promise ( ( resolve , reject ) => {
76- const req = http . request ( {
77- host : '127.0.0.1' ,
78- port,
79- method : 'POST'
80- } , res => {
81- const chunks = [ ] as Buffer [ ] ;
82- res . on ( 'data' , chunk => { chunks . push ( chunk ) ; } ) ;
83- res . on ( 'end' , ( ) => {
84- const ret = v8 . deserialize ( Buffer . concat ( chunks ) ) ;
85- if ( Object . prototype . hasOwnProperty . call ( ret , 'error' ) ) {
86- reject ( new Error ( `remote error: ${ ret . error } \n\nTriggered at:` ) ) ;
87- } else {
88- resolve ( ret . result ) ;
89- }
90- } ) ;
91- } ) ;
92- req . write ( js ) ;
93- req . end ( ) ;
94- } ) ;
95- }
96- function remotely ( script : Function , ...args : any [ ] ) : Promise < any > {
97- return remoteEval ( `(${ script } )(...${ JSON . stringify ( args ) } )` ) ;
98- }
99- afterTest . push ( ( ) => { appProcess . kill ( 'SIGINT' ) ; } ) ;
100- return { remoteEval, remotely } ;
101- } ;
102-
10350const startServer = async ( ) => {
10451 const crashes : CrashInfo [ ] = [ ] ;
10552 function getCrashes ( ) { return crashes ; }
@@ -145,7 +92,7 @@ const startServer = async () => {
14592
14693 const port = ( server . address ( ) as AddressInfo ) . port ;
14794
148- afterTest . push ( ( ) => { server . close ( ) ; } ) ;
95+ defer ( ( ) => { server . close ( ) ; } ) ;
14996
15097 return { getCrashes, port, waitForCrash } ;
15198} ;
@@ -188,8 +135,6 @@ function waitForNewFileInDir (dir: string): Promise<string[]> {
188135
189136// TODO(nornagon): Fix tests on linux/arm.
190137ifdescribe ( ! isLinuxOnArm && ! process . mas && ! process . env . DISABLE_CRASH_REPORTER_TESTS ) ( 'crashReporter module' , function ( ) {
191- afterEach ( cleanup ) ;
192-
193138 describe ( 'should send minidump' , ( ) => {
194139 it ( 'when renderer crashes' , async ( ) => {
195140 const { port, waitForCrash } = await startServer ( ) ;
0 commit comments