import * as assert from 'assert' ; import { describe , it , afterEach } from 'mocha' ; import * as execa from 'execa' ; import * as fs from 'fs' ; import * as mv from 'mv' ; import { ncp } from 'ncp' ; import * as path from 'path' ; import * as tmp from 'tmp' ; import { promisify } from 'util' ; const mvp = promisify ( mv ) as { } as ( ... args : string [ ] ) => Promise < void > ; const ncpp = promisify ( ncp ) ; const keep = ! ! process . env . GALN_KEEP_TEMPDIRS ; const pkg = require ( '../../package.json' ) ; let stagingDir ; let stagingPath ; async function packAndInstall ( ) { stagingDir = tmp . dirSync ( { keep , unsafeCleanup : true } ) ; stagingPath = stagingDir . name ; await execa ( 'npm' , [ 'pack' ] , { stdio : 'inherit' } ) ; const tarball = `${ pkg . name }-${ pkg . version }.tgz` ; await mvp ( tarball , `${ stagingPath }/google-auth-library.tgz` ) ; await ncpp ( 'system-test/fixtures/kitchen' , `${ stagingPath }/` ) ; await execa ( 'npm' , [ 'install' ] , { cwd : `${ stagingPath }/` , stdio : 'inherit' } ) ; } describe ( 'pack and install' , ( ) => { /**
     * Create a staging directory with temp fixtures used to test on a fresh
     * application.
     */ it ( 'should be able to use the d.ts' , async function ( ) { this . retries ( 3 ) ; this . timeout ( 40000 ) ; await packAndInstall ( ) ; } ) ; it ( 'should be able to webpack the library' , async function ( ) { this . retries ( 3 ) ; this . timeout ( 40000 ) ; await packAndInstall ( ) ; 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 ) ; } ) ; /**
     * CLEAN UP - remove the staging directory when done.
     */ afterEach ( 'cleanup staging' , ( ) => { if ( ! keep ) { stagingDir . removeCallback ( ) ; } } ) ; } ) ;