Skip to content

Commit 4213161

Browse files
committed
finish replacements
1 parent dfb4889 commit 4213161

File tree

8 files changed

+44
-41
lines changed

8 files changed

+44
-41
lines changed

packages/amazonq/test/unit/amazonqGumby/transformationResultsHandler.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
*/
55
import assert from 'assert'
66
import sinon from 'sinon'
7-
import fs from 'fs-extra'
87
import os from 'os'
98
import { DiffModel, AddedChangeNode, ModifiedChangeNode } from 'aws-core-vscode/codewhisperer/node'
109
import path from 'path'
1110
import { getTestResourceFilePath } from './amazonQGumbyUtil'
11+
import { fs } from 'aws-core-vscode/shared'
1212

1313
describe('DiffModel', function () {
1414
afterEach(() => {
@@ -20,7 +20,7 @@ describe('DiffModel', function () {
2020

2121
const workspacePath = 'workspace'
2222

23-
sinon.replace(fs, 'existsSync', (path) => {
23+
sinon.replace(fs, 'exists', async (path) => {
2424
const pathStr = path.toString()
2525
if (pathStr.includes(workspacePath)) {
2626
return false
@@ -42,9 +42,9 @@ describe('DiffModel', function () {
4242

4343
const workspacePath = os.tmpdir()
4444

45-
sinon.replace(fs, 'existsSync', (path) => true)
45+
sinon.replace(fs, 'exists', async (path) => true)
4646

47-
fs.writeFileSync(
47+
await fs.writeFile(
4848
path.join(workspacePath, 'README.md'),
4949
'This guide walks you through using Gradle to build a simple Java project.'
5050
)
@@ -56,6 +56,6 @@ describe('DiffModel', function () {
5656

5757
assert.strictEqual(change instanceof ModifiedChangeNode, true)
5858

59-
fs.rmSync(path.join(workspacePath, 'README.md'))
59+
await fs.delete(path.join(workspacePath, 'README.md'))
6060
})
6161
})

packages/core/src/test/stepFunctions/utils.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66
import assert from 'assert'
77
import { IAM } from 'aws-sdk'
8-
import * as fs from 'fs-extra'
98
import * as sinon from 'sinon'
109
import * as vscode from 'vscode'
1110
import { makeTemporaryToolkitFolder } from '../../shared/filesystemUtilities'
1211
import { isDocumentValid, isStepFunctionsRole, StateMachineGraphCache } from '../../stepFunctions/utils'
1312
import globals from '../../shared/extensionGlobals'
13+
import { fs } from '../../shared'
1414

1515
const requestBody = 'request body string'
1616
const assetUrl = 'https://something'
@@ -24,7 +24,7 @@ describe('StateMachineGraphCache', function () {
2424
})
2525

2626
after(async function () {
27-
await fs.remove(tempFolder)
27+
await fs.delete(tempFolder)
2828
})
2929

3030
describe('updateCachedFile', function () {

packages/core/src/testE2E/amazonqGumby/transformByQ.test.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import * as os from 'os'
77
import * as path from 'path'
8-
import * as fs from 'fs-extra'
98
import * as CodeWhispererConstants from '../../codewhisperer/models/constants'
109
import * as codeWhisperer from '../../codewhisperer/client/codewhisperer'
1110
import assert from 'assert'
@@ -15,6 +14,7 @@ import AdmZip from 'adm-zip'
1514
import { setValidConnection } from '../util/connection'
1615
import { transformByQState, ZipManifest } from '../../codewhisperer/models/model'
1716
import globals from '../../shared/extensionGlobals'
17+
import { fs } from '../../shared'
1818

1919
describe('transformByQ', async function () {
2020
let tempDir = ''
@@ -29,10 +29,10 @@ describe('transformByQ', async function () {
2929
this.skip()
3030
}
3131
tempDir = path.join(os.tmpdir(), 'gumby-test')
32-
fs.mkdirSync(tempDir)
32+
await fs.mkdir(tempDir)
3333
tempFileName = `testfile-${globals.clock.Date.now()}.txt`
3434
tempFilePath = path.join(tempDir, tempFileName)
35-
fs.writeFileSync(tempFilePath, 'sample content for the test file')
35+
await fs.writeFile(tempFilePath, 'sample content for the test file')
3636
transformByQState.setProjectPath(tempDir)
3737
const zipCodeResult = await zipCode({
3838
dependenciesFolder: {
@@ -47,13 +47,13 @@ describe('transformByQ', async function () {
4747

4848
after(async function () {
4949
if (tempDir !== '') {
50-
await fs.remove(tempDir)
50+
await fs.delete(tempDir)
5151
}
5252
})
5353

5454
it('WHEN upload payload with missing sha256 in headers THEN fails to upload', async function () {
55-
const buffer = fs.readFileSync(zippedCodePath)
56-
const sha256 = getSha256(buffer)
55+
const buffer = await fs.readFile(zippedCodePath)
56+
const sha256 = getSha256(Buffer.from(buffer))
5757
const response = await codeWhisperer.codeWhispererClient.createUploadUrl({
5858
contentChecksum: sha256,
5959
contentChecksumType: CodeWhispererConstants.contentChecksumType,
@@ -63,10 +63,13 @@ describe('transformByQ', async function () {
6363
'x-amz-checksum-sha256': '',
6464
'Content-Type': 'application/zip',
6565
}
66+
const body = await fs.readFileAsString(zippedCodePath)
6667
await assert.rejects(
6768
() =>
68-
request.fetch('PUT', response.uploadUrl, { body: fs.readFileSync(zippedCodePath), headers: headersObj })
69-
.response
69+
request.fetch('PUT', response.uploadUrl, {
70+
body: body,
71+
headers: headersObj,
72+
}).response
7073
)
7174
})
7275

@@ -85,8 +88,8 @@ describe('transformByQ', async function () {
8588
})
8689

8790
it('WHEN createUploadUrl THEN URL uses HTTPS and sets 60 second expiration', async function () {
88-
const buffer = fs.readFileSync(zippedCodePath)
89-
const sha256 = getSha256(buffer)
91+
const buffer = await fs.readFile(zippedCodePath)
92+
const sha256 = getSha256(Buffer.from(buffer))
9093
const response = await codeWhisperer.codeWhispererClient.createUploadUrl({
9194
contentChecksum: sha256,
9295
contentChecksumType: CodeWhispererConstants.contentChecksumType,

packages/core/src/testInteg/cloudformation/templateRegistry.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
*/
55

66
import * as path from 'path'
7-
import * as fs from 'fs-extra'
87

98
import { CloudFormationTemplateRegistry } from '../../shared/fs/templateRegistry'
109
import { makeSampleSamTemplateYaml, strToYamlFile } from '../../test/shared/cloudformation/cloudformationTestUtils'
1110
import { getTestWorkspaceFolder } from '../integrationTestsUtilities'
1211
import { Timeout, sleep, waitUntil } from '../../shared/utilities/timeoutUtils'
1312
import assert from 'assert'
13+
import { fs } from '../../shared'
1414

1515
/**
1616
* Note: these tests are pretty shallow right now. They do not test the following:
@@ -30,14 +30,14 @@ describe('CloudFormation Template Registry', async function () {
3030
beforeEach(async function () {
3131
testDir = path.join(workspaceDir, dir.toString())
3232
testDirNested = path.join(testDir, 'nested')
33-
await fs.mkdirp(testDirNested)
33+
await fs.mkdir(testDirNested)
3434
registry = new CloudFormationTemplateRegistry()
3535
dir++
3636
})
3737

3838
afterEach(async function () {
3939
registry.dispose()
40-
await fs.remove(testDir)
40+
await fs.delete(testDir)
4141
})
4242

4343
it('adds initial template files with yaml and yml extensions at various nesting levels', async function () {
@@ -99,7 +99,7 @@ describe('CloudFormation Template Registry', async function () {
9999

100100
await registryHasTargetNumberOfFiles(registry, 1)
101101

102-
await fs.remove(filepath)
102+
await fs.delete(filepath)
103103

104104
await registryHasTargetNumberOfFiles(registry, 0)
105105
})

packages/core/src/testInteg/sam.test.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import assert from 'assert'
77
import { Runtime } from 'aws-sdk/clients/lambda'
8-
import { mkdirpSync, mkdtemp } from 'fs-extra'
8+
import { mkdtempSync } from 'fs'
99
import * as path from 'path'
1010
import * as semver from 'semver'
1111
import * as vscode from 'vscode'
@@ -27,6 +27,7 @@ import { insertTextIntoFile } from '../shared/utilities/textUtilities'
2727
import globals from '../shared/extensionGlobals'
2828
import { closeAllEditors } from '../test/testUtil'
2929
import { ToolkitError } from '../shared/errors'
30+
import { fs } from '../shared'
3031

3132
const projectFolder = testUtils.getTestWorkspaceFolder()
3233

@@ -393,9 +394,9 @@ describe('SAM Integration Tests', async function () {
393394
await testUtils.configureAwsToolkitExtension()
394395
// await testUtils.configureGoExtension()
395396

396-
testSuiteRoot = await mkdtemp(path.join(projectFolder, 'inttest'))
397+
testSuiteRoot = mkdtempSync(path.join(projectFolder, 'inttest'))
397398
console.log('testSuiteRoot: ', testSuiteRoot)
398-
mkdirpSync(testSuiteRoot)
399+
await fs.mkdir(testSuiteRoot)
399400
})
400401

401402
after(async function () {
@@ -417,7 +418,7 @@ describe('SAM Integration Tests', async function () {
417418
randomTestScenario = scenarios[0]
418419

419420
runtimeTestRoot = path.join(testSuiteRoot, 'randomScenario')
420-
mkdirpSync(runtimeTestRoot)
421+
await fs.mkdir(runtimeTestRoot)
421422
})
422423

423424
after(async function () {
@@ -453,7 +454,7 @@ describe('SAM Integration Tests', async function () {
453454
before(async function () {
454455
runtimeTestRoot = path.join(testSuiteRoot, scenario.runtime)
455456
console.log('runtimeTestRoot: ', runtimeTestRoot)
456-
mkdirpSync(runtimeTestRoot)
457+
await fs.mkdir(runtimeTestRoot)
457458
})
458459

459460
after(async function () {
@@ -480,7 +481,7 @@ describe('SAM Integration Tests', async function () {
480481
let cfnTemplatePath: string
481482

482483
before(async function () {
483-
testDir = await mkdtemp(path.join(runtimeTestRoot, 'samapp-'))
484+
testDir = mkdtempSync(path.join(runtimeTestRoot, 'samapp-'))
484485
log(`testDir: ${testDir}`)
485486

486487
await createSamApplication(testDir, scenario)

packages/core/src/testInteg/schema/schema.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import globals from '../../shared/extensionGlobals'
77
import { GlobalStorage } from '../../shared/globalStorage'
8-
import * as fs from 'fs-extra'
98
import { getDefaultSchemas, samAndCfnSchemaUrl } from '../../shared/schemas'
109
import {
1110
getCITestSchemas,
@@ -18,6 +17,7 @@ import {
1817
} from '../../test/shared/schema/testUtils'
1918
import { assertTelemetry } from '../../test/testUtil'
2019
import { waitUntil } from '../../shared/utilities/timeoutUtils'
20+
import { fs } from '../../shared'
2121

2222
describe('Sam Schema Regression', function () {
2323
let samSchema: JSONObject
@@ -72,7 +72,7 @@ describe('getDefaultSchemas()', () => {
7272
beforeEach(async () => {})
7373

7474
it('uses cache after initial fetch for CFN/SAM schema', async () => {
75-
fs.removeSync(GlobalStorage.samAndCfnSchemaDestinationUri().fsPath)
75+
await fs.delete(GlobalStorage.samAndCfnSchemaDestinationUri().fsPath)
7676
await globals.telemetry.setTelemetryEnabled(true)
7777
globals.telemetry.clearRecords()
7878
globals.telemetry.logger.clear()
@@ -81,7 +81,7 @@ describe('getDefaultSchemas()', () => {
8181
await getDefaultSchemas()
8282
await waitUntil(
8383
async () => {
84-
return fs.existsSync(GlobalStorage.samAndCfnSchemaDestinationUri().fsPath)
84+
return await fs.exists(GlobalStorage.samAndCfnSchemaDestinationUri().fsPath)
8585
},
8686
{ truthy: true, interval: 200, timeout: 5000 }
8787
)

packages/core/src/testInteg/shared/utilities/workspaceUtils.test.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
*/
55

66
import assert from 'assert'
7-
import { writeFile, mkdirp, remove } from 'fs-extra'
87
import * as path from 'path'
98
import * as vscode from 'vscode'
10-
import * as fs from 'fs'
119
import {
1210
collectFiles,
1311
collectFilesForIndex,
@@ -22,6 +20,7 @@ import { assertTelemetry, createTestWorkspace, createTestWorkspaceFolder, toFile
2220
import sinon from 'sinon'
2321
import { performanceTest } from '../../../shared/performance/performance'
2422
import { randomUUID } from '../../../shared/crypto'
23+
import { fs } from '../../../shared'
2524

2625
describe('findParentProjectFile', async function () {
2726
const workspaceDir = getTestWorkspaceFolder()
@@ -75,14 +74,14 @@ describe('findParentProjectFile', async function () {
7574
]
7675

7776
before(async function () {
78-
await mkdirp(path.join(workspaceDir, 'someproject', 'src'))
79-
await mkdirp(path.join(workspaceDir, 'someotherproject'))
77+
await fs.mkdir(path.join(workspaceDir, 'someproject', 'src'))
78+
await fs.mkdir(path.join(workspaceDir, 'someotherproject'))
8079
globalRegistry = globals.codelensRootRegistry
8180
})
8281

8382
after(async function () {
84-
await remove(path.join(workspaceDir, 'someproject'))
85-
await remove(path.join(workspaceDir, 'someotherproject'))
83+
await fs.delete(path.join(workspaceDir, 'someproject'))
84+
await fs.delete(path.join(workspaceDir, 'someotherproject'))
8685
globals.codelensRootRegistry = globalRegistry
8786
})
8887

@@ -92,7 +91,7 @@ describe('findParentProjectFile', async function () {
9291

9392
afterEach(async function () {
9493
for (const file of filesToDelete) {
95-
await remove(file.fsPath)
94+
await fs.delete(file.fsPath)
9695
}
9796
filesToDelete = []
9897
globals.codelensRootRegistry.dispose()
@@ -102,7 +101,7 @@ describe('findParentProjectFile', async function () {
102101
it(test.scenario, async () => {
103102
filesToDelete = test.filesToUse
104103
for (const file of test.filesToUse) {
105-
await writeFile(file.fsPath, '')
104+
await fs.writeFile(file.fsPath, '')
106105
// Add it to the registry. The registry is async and we are not
107106
// testing the registry in this test, so manually use it
108107
await globals.codelensRootRegistry.addItem(file)
@@ -448,7 +447,7 @@ describe('getWorkspaceFoldersByPrefixes', function () {
448447
subDir: 'test/app',
449448
})
450449
const newRoot = path.join(ws1.uri.fsPath, '../app_cdk')
451-
await fs.promises.mkdir(newRoot, { recursive: true })
450+
await fs.mkdir(newRoot)
452451
const ws2: vscode.WorkspaceFolder = {
453452
index: 0,
454453
uri: vscode.Uri.file(newRoot),

packages/core/src/testInteg/stepFunctions/visualizeStateMachine.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
*/
55

66
import assert from 'assert'
7-
import * as fs from 'fs-extra'
87
import * as vscode from 'vscode'
98
import * as sinon from 'sinon'
109
import { MessageObject } from '../../stepFunctions/commands/visualizeStateMachine/aslVisualization'
1110
import { makeTemporaryToolkitFolder } from '../../shared/filesystemUtilities'
1211
import { closeAllEditors, toTextEditor } from '../../test/testUtil'
1312
import { previewStateMachineCommand } from '../../stepFunctions/activation'
13+
import { fs } from '../../shared'
1414

1515
const sampleStateMachine = `
1616
{
@@ -89,7 +89,7 @@ describe('visualizeStateMachine', async function () {
8989
})
9090

9191
afterEach(async function () {
92-
await fs.remove(tempFolder)
92+
await fs.delete(tempFolder)
9393
sinon.restore()
9494
})
9595

0 commit comments

Comments
 (0)