55import assert from 'assert'
66import * as sinon from 'sinon'
77import { performanceTest } from '../../shared/performance/performance'
8- import { fs , globals } from '../../shared'
8+ import { fs , getRandomString , globals } from '../../shared'
99import * as CodeWhispererConstants from '../../codewhisperer/models/constants'
1010import { TransformByQState , ZipManifest } from '../../codewhisperer'
1111import { zipCode } from '../../codewhisperer/indexNode'
@@ -18,10 +18,26 @@ interface SetupResult {
1818 writeSpy : sinon . SinonSpy
1919}
2020
21+ async function setup ( numberOfFiles : number , fileSize : number ) : Promise < SetupResult > {
22+ const transformByQState : TransformByQState = new TransformByQState ( )
23+ const tempFileName = `testfile-${ globals . clock . Date . now ( ) } .zip`
24+ const tempDir = (
25+ await createTestWorkspace ( numberOfFiles , {
26+ fileNamePrefix : 'file' ,
27+ fileContent : getRandomString ( fileSize ) ,
28+ fileNameSuffix : '.md' ,
29+ } )
30+ ) . uri . fsPath
31+ const writeSpy = sinon . spy ( fs , 'writeFile' )
32+ const transformQManifest = new ZipManifest ( )
33+ transformByQState . setProjectPath ( tempDir )
34+ transformQManifest . customBuildCommand = CodeWhispererConstants . skipUnitTestsBuildCommand
35+ return { tempDir, tempFileName, transformQManifest, writeSpy }
36+ }
37+
2138describe ( 'zipCode' , function ( ) {
2239 describe ( 'performance tests' , function ( ) {
2340 afterEach ( function ( ) {
24- sinon . resetHistory ( )
2541 sinon . restore ( )
2642 } )
2743
@@ -47,22 +63,52 @@ describe('zipCode', function () {
4763 'many small files in zip' ,
4864 function ( ) {
4965 return {
50- setup : async ( ) => {
51- const transformByQState : TransformByQState = new TransformByQState ( )
52- const tempFileName = `testfile-${ globals . clock . Date . now ( ) } .zip`
53- const tempDir = (
54- await createTestWorkspace ( 250 , {
55- fileNamePrefix : 'file' ,
56- fileContent : '0123456789' ,
57- fileNameSuffix : '.md' ,
66+ setup : async ( ) => await setup ( 250 , 10 ) ,
67+ execute : async ( { tempDir, tempFileName, transformQManifest, writeSpy } : SetupResult ) => {
68+ await zipCode ( {
69+ dependenciesFolder : {
70+ path : tempDir ,
71+ name : tempFileName ,
72+ } ,
73+ humanInTheLoopFlag : false ,
74+ modulePath : tempDir ,
75+ zipManifest : transformQManifest ,
76+ } )
77+ } ,
78+ verify : async ( setup : SetupResult ) => {
79+ assert . ok (
80+ setup . writeSpy . args . find ( ( arg ) => {
81+ return arg [ 0 ] . endsWith ( '.zip' )
5882 } )
59- ) . uri . fsPath
60- const writeSpy = sinon . spy ( fs , 'writeFile' )
61- const transformQManifest = new ZipManifest ( )
62- transformByQState . setProjectPath ( tempDir )
63- transformQManifest . customBuildCommand = CodeWhispererConstants . skipUnitTestsBuildCommand
64- return { tempDir, tempFileName, transformQManifest, writeSpy }
83+ )
6584 } ,
85+ }
86+ }
87+ )
88+
89+ performanceTest (
90+ {
91+ testRuns : 10 ,
92+ linux : {
93+ userCpuUsage : 90 ,
94+ systemCpuUsage : 35 ,
95+ heapTotal : 4 ,
96+ } ,
97+ darwin : {
98+ userCpuUsage : 90 ,
99+ systemCpuUsage : 35 ,
100+ heapTotal : 4 ,
101+ } ,
102+ win32 : {
103+ userCpuUsage : 90 ,
104+ systemCpuUsage : 35 ,
105+ heapTotal : 4 ,
106+ } ,
107+ } ,
108+ 'few large files' ,
109+ function ( ) {
110+ return {
111+ setup : async ( ) => await setup ( 10 , 1000 ) ,
66112 execute : async ( { tempDir, tempFileName, transformQManifest, writeSpy } : SetupResult ) => {
67113 await zipCode ( {
68114 dependenciesFolder : {
@@ -75,7 +121,6 @@ describe('zipCode', function () {
75121 } )
76122 } ,
77123 verify : async ( setup : SetupResult ) => {
78- // writes a zip to disk.
79124 assert . ok (
80125 setup . writeSpy . args . find ( ( arg ) => {
81126 return arg [ 0 ] . endsWith ( '.zip' )
0 commit comments