import assert from 'assert' ; import execa from 'execa' ; import fs from 'fs' ; import mv from 'mv' ; import { ncp } from 'ncp' ; import path from 'path' ; import tmp from 'tmp' ; import { promisify } from 'util' ; import { describe , it , before , after } from 'mocha' ; const keep = false ; const mvp = promisify ( mv ) as { } as ( ... args : string [ ] ) => Promise < void > ; const ncpp = promisify ( ncp ) ; const stagingDir = tmp . dirSync ( { keep , unsafeCleanup : true } ) ; const stagingPath = stagingDir . name ; const pkg = require ( '../../package.json' ) ; describe ( '📦 pack and install' , ( ) => { /**
     * Create a staging directory with temp fixtures used to test on a fresh
     * application.
     */ before ( 'pack and install' , async ( ) => { await execa ( 'npm' , [ 'pack' ] ) ; const tarball = `${ pkg . name }-${ pkg . version }.tgz` ; await mvp ( tarball , `${ stagingPath }/gaxios.tgz` ) ; await ncpp ( 'system-test/fixtures/sample' , `${ stagingPath }/` ) ; await execa ( 'npm' , [ 'install' ] , { cwd : `${ stagingPath }/` , stdio : 'inherit' , } ) ; } ) ; it ( 'should run the sample' , async ( ) => { await execa ( 'node' , [ '--throw-deprecation' , 'build/src/index.js' ] , { cwd : `${ stagingPath }/` , stdio : 'inherit' , } ) ; } ) ; it ( 'should be able to webpack the library' , async ( ) => { await execa ( 'npx' , [ 'webpack' ] , { cwd : `${ stagingPath }/` , stdio : 'inherit' , } ) ; const bundle = path . join ( stagingPath , 'dist' , 'bundle.min.js' ) ; const stat = fs . statSync ( bundle ) ; assert ( stat . size < 256 * 1024 ) ; } ) . timeout ( 20000 ) ; /**
     * CLEAN UP - remove the staging directory when done.
     */ after ( 'cleanup staging' , ( ) => { if ( ! keep ) { stagingDir . removeCallback ( ) ; } } ) ; } ) ;