1717import * as assert from 'assert' ;
1818import * as path from 'path' ;
1919
20- import { globP , ncpP , rimrafP , spawnP , tmpDirP , writeFileP } from './utils' ;
20+ import { globP , mkdirP , ncpP , rimrafP , spawnP , tmpDirP , writeFileP } from './utils' ;
2121
2222const INDEX_TS = 'index.ts' ;
2323const INDEX_JS = 'index.js' ;
@@ -36,6 +36,36 @@ debug.start();`,
3636 code : `import * as debug from '@google-cloud/debug-agent';
3737debug.start({ allowExpressions: true });` ,
3838 description : 'imports the module and starts with {allowExpressions: true}'
39+ } ,
40+ {
41+ code : `import * as debug from '@google-cloud/debug-agent';
42+ debug.start({
43+ allowExpressions: true,
44+ serviceContext: {
45+ service: 'Some service'
46+ }
47+ });` ,
48+ description : 'imports the module and starts with a partial `serviceContext`'
49+ } ,
50+ {
51+ code : `import * as debug from '@google-cloud/debug-agent';
52+ debug.start({
53+ allowExpressions: true,
54+ serviceContext: {
55+ service: 'Some service',
56+ version: 'Some version'
57+ }
58+ });` ,
59+ description : 'imports the module and starts with a complete `serviceContext`'
60+ } ,
61+ {
62+ code : `import * as debug from '@google-cloud/debug-agent';
63+ debug.start({
64+ capture: {
65+ maxFrames: 1
66+ }
67+ });` ,
68+ description : 'imports the module and starts with a partial `capture`'
3969 }
4070] ;
4171
@@ -74,6 +104,17 @@ interface CodeSample {
74104
75105describe ( 'Installation' , ( ) => {
76106 let installDir : string | undefined ;
107+ before ( async ( ) => {
108+ const tgz = await globP ( `${ process . cwd ( ) } /*.tgz` ) ;
109+ assert . deepStrictEqual (
110+ tgz . length , 0 ,
111+ `Expected zero tgz files in the current working directory before ` +
112+ `running the test but found files: ${ tgz . map ( file => {
113+ const parts = file . split ( path . sep ) ;
114+ return parts [ parts . length - 1 ] ;
115+ } ) } `) ;
116+ } ) ;
117+
77118 beforeEach ( async function ( ) {
78119 this . timeout ( TIMEOUT_MS ) ;
79120 // This script assumes that you don't already have a TGZ file
@@ -103,17 +144,26 @@ describe('Installation', () => {
103144
104145 describe ( 'When used with Typescript code' , ( ) => {
105146 TS_CODE_ARRAY . forEach ( ( sample ) => {
106- it ( `should install and work with code that ${ sample . description } ` ,
107- async function ( ) {
108- this . timeout ( TIMEOUT_MS ) ;
109- assert ( installDir ) ;
110- await writeFileP (
111- path . join ( installDir ! , INDEX_TS ) , sample . code , 'utf-8' ) ;
112- await spawnP (
113- `node_modules${ path . sep } .bin${ path . sep } tsc` , [ INDEX_TS ] ,
114- { cwd : installDir , stdio} , log ) ;
115- await spawnP ( 'node' , [ INDEX_JS ] , { cwd : installDir , stdio} , log ) ;
116- } ) ;
147+ it . only (
148+ `should install and work with code that ${ sample . description } ` ,
149+ async function ( ) {
150+ this . timeout ( TIMEOUT_MS ) ;
151+ assert ( installDir ) ;
152+ const srcDir = path . join ( installDir ! , 'src' ) ;
153+ await mkdirP ( srcDir ) ;
154+ await writeFileP ( path . join ( srcDir , INDEX_TS ) , sample . code , 'utf-8' ) ;
155+ await spawnP (
156+ 'npm' , [ 'install' , '--save-dev' , 'gts' , '[email protected] ' ] , 157+ { cwd : installDir , stdio} , log ) ;
158+ await spawnP (
159+ 'gts' , [ 'init' , '--yes' ] , { cwd : installDir , stdio} , log ) ;
160+ await spawnP (
161+ 'npm' , [ 'run' , 'compile' ] , { cwd : installDir , stdio} , log ) ;
162+ const buildDir = path . join ( installDir ! , 'build' ) ;
163+ await spawnP (
164+ 'node' , [ path . join ( buildDir , 'src' , INDEX_JS ) ] ,
165+ { cwd : installDir , stdio} , log ) ;
166+ } ) ;
117167 } ) ;
118168 } ) ;
119169
0 commit comments