|
5 | 5 | import assert from 'assert' |
6 | 6 | import * as sinon from 'sinon' |
7 | 7 | import { performanceTest } from '../../shared/performance/performance' |
| 8 | +import { fs, globals } from '../../shared' |
| 9 | +import * as CodeWhispererConstants from '../../codewhisperer/models/constants' |
| 10 | +import { TransformByQState, ZipManifest } from '../../codewhisperer' |
| 11 | +import { zipCode } from '../../codewhisperer/indexNode' |
| 12 | +import { createTestWorkspace } from '../testUtil' |
| 13 | + |
| 14 | +interface SetupResult { |
| 15 | + tempDir: string |
| 16 | + tempFileName: string |
| 17 | + transformQManifest: ZipManifest |
| 18 | + writeSpy: sinon.SinonSpy |
| 19 | +} |
8 | 20 |
|
9 | 21 | describe('zipCode', function () { |
10 | 22 | describe('performance tests', function () { |
11 | | - performanceTest({}, 'many small files in zip', function () { |
12 | | - return { |
13 | | - setup: async () => {}, |
14 | | - execute: async () => {}, |
15 | | - verify: async () => {}, |
16 | | - } |
| 23 | + afterEach(function () { |
| 24 | + sinon.resetHistory() |
| 25 | + sinon.restore() |
17 | 26 | }) |
| 27 | + |
| 28 | + performanceTest( |
| 29 | + { |
| 30 | + testRuns: 10, |
| 31 | + linux: { |
| 32 | + userCpuUsage: 90, |
| 33 | + systemCpuUsage: 35, |
| 34 | + heapTotal: 4, |
| 35 | + }, |
| 36 | + darwin: { |
| 37 | + userCpuUsage: 90, |
| 38 | + systemCpuUsage: 35, |
| 39 | + heapTotal: 4, |
| 40 | + }, |
| 41 | + win32: { |
| 42 | + userCpuUsage: 90, |
| 43 | + systemCpuUsage: 35, |
| 44 | + heapTotal: 4, |
| 45 | + }, |
| 46 | + }, |
| 47 | + 'many small files in zip', |
| 48 | + function () { |
| 49 | + 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', |
| 58 | + }) |
| 59 | + ).uri.fsPath |
| 60 | + const transformQManifest = new ZipManifest() |
| 61 | + transformByQState.setProjectPath(tempDir) |
| 62 | + transformQManifest.customBuildCommand = CodeWhispererConstants.skipUnitTestsBuildCommand |
| 63 | + return { tempDir, tempFileName, transformQManifest, writeSpy } |
| 64 | + }, |
| 65 | + execute: async ({ tempDir, tempFileName, transformQManifest, writeSpy }: SetupResult) => { |
| 66 | + await zipCode({ |
| 67 | + dependenciesFolder: { |
| 68 | + path: tempDir, |
| 69 | + name: tempFileName, |
| 70 | + }, |
| 71 | + humanInTheLoopFlag: false, |
| 72 | + modulePath: tempDir, |
| 73 | + zipManifest: transformQManifest, |
| 74 | + }) |
| 75 | + }, |
| 76 | + verify: async (setup: SetupResult) => { |
| 77 | + // writes a zip to disk. |
| 78 | + assert.ok(setup.writeSpy.called) |
| 79 | + assert.ok( |
| 80 | + setup.writeSpy.getCalls()[0].args[0].includes('.zip') || |
| 81 | + setup.writeSpy.getCalls()[1].args[0].includes('.zip') |
| 82 | + ) |
| 83 | + }, |
| 84 | + } |
| 85 | + } |
| 86 | + ) |
18 | 87 | }) |
19 | 88 | }) |
0 commit comments