1+ import { promisify } from 'util' ;
12import { spawn , ChildProcess } from 'child_process' ;
23import * as path from 'path' ;
34import { getRemote } from 'mockttp' ;
45import * as request from 'request-promise-native' ;
6+ import * as tmp from 'tmp' ;
7+ import { extractTarball as extractTarballCb } from 'tarball-extract' ;
8+ const extractTarball = promisify ( extractTarballCb ) as ( source : string , dest : string ) => Promise < void > ;
59
610import * as getGraphQL from 'graphql.js' ;
711
812import { delay } from '../src/util' ;
913import { expect } from 'chai' ;
1014
15+ async function setupServerPath ( ) {
16+ if ( ! process . env . TEST_BUILT_TARBALL ) {
17+ // By default, test the current folder code
18+ return path . join ( __dirname , '..' , 'bin' , 'run' ) ;
19+ }
20+
21+ // If TEST_BUILT_TARBALL is set, test the latest build ready-to-go tarball:
22+ const tmpDir = tmp . dirSync ( { unsafeCleanup : true } ) . name ;
23+ const version = require ( path . join ( '..' , 'package.json' ) ) . version ;
24+ const tarballPath = path . join (
25+ __dirname ,
26+ '..' ,
27+ 'build' ,
28+ 'dist' ,
29+ `v${ version } ` ,
30+ `httptoolkit-server-v${ version } .tar.gz`
31+ ) ;
32+
33+ console . log ( 'Extracting built tarball to' , tmpDir ) ;
34+ await extractTarball ( tarballPath , tmpDir ) ;
35+
36+ // Pretend this is being called by the real startup script,
37+ // so it acts like a proper prod build.
38+ process . env . HTTPTOOLKIT_SERVER_BINPATH = 'PROD-TEST' ;
39+ return path . join ( tmpDir , 'httptoolkit-server' , 'bin' , 'run' ) ;
40+ }
41+
1142describe ( 'Integration test' , function ( ) {
1243 // Timeout needs to be long, as first test runs (e.g. in CI) generate
1344 // fresh certificates, which can take a little while.
@@ -18,7 +49,9 @@ describe('Integration test', function () {
1849 let stderr = '' ;
1950
2051 beforeEach ( async ( ) => {
21- serverProcess = spawn ( path . join ( __dirname , '..' , 'bin' , 'run' ) , [ 'start' ] , {
52+ const serverRunPath = await setupServerPath ( ) ;
53+
54+ serverProcess = spawn ( serverRunPath , [ 'start' ] , {
2255 stdio : 'pipe'
2356 } ) ;
2457 stdout = "" ;
0 commit comments