Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
*/
import assert from 'assert'
import sinon from 'sinon'
import fs from 'fs-extra'
import os from 'os'
import { DiffModel, AddedChangeNode, ModifiedChangeNode } from 'aws-core-vscode/codewhisperer/node'
import path from 'path'
import { getTestResourceFilePath } from './amazonQGumbyUtil'
import { fs } from 'aws-core-vscode/shared'

describe('DiffModel', function () {
afterEach(() => {
Expand All @@ -20,7 +20,7 @@ describe('DiffModel', function () {

const workspacePath = 'workspace'

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

const workspacePath = os.tmpdir()

sinon.replace(fs, 'existsSync', (path) => true)
sinon.replace(fs, 'exists', async (path) => true)

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

assert.strictEqual(change instanceof ModifiedChangeNode, true)

fs.rmSync(path.join(workspacePath, 'README.md'))
await fs.delete(path.join(workspacePath, 'README.md'))
})
})
12 changes: 6 additions & 6 deletions packages/core/src/test/awsService/cdk/detectCdkProjects.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
import assert from 'assert'
import * as path from 'path'
import * as vscode from 'vscode'
import * as fs from 'fs-extra'
import { detectCdkProjects } from '../../../awsService/cdk/explorer/detectCdkProjects'
import { makeTemporaryToolkitFolder } from '../../../shared/filesystemUtilities'
import { saveCdkJson } from './treeTestUtils'
import { createTestWorkspaceFolder } from '../../testUtil'
import { FakeExtensionContext } from '../../fakeExtensionContext'
import { mkdirp, writeJSON } from 'fs-extra'
import { waitUntil } from '../../../shared/utilities/timeoutUtils'
import { fs } from '../../../shared'

describe('detectCdkProjects', function () {
const workspacePaths: string[] = []
Expand Down Expand Up @@ -45,7 +44,7 @@ describe('detectCdkProjects', function () {

afterEach(async function () {
for (const path of workspacePaths) {
await fs.remove(path)
await fs.delete(path)
}

workspacePaths.length = 0
Expand Down Expand Up @@ -88,15 +87,15 @@ describe('detectCdkProjects', function () {

it('detects deep projects', async function () {
const cdkJsonUri = vscode.Uri.joinPath(workspaceFolders[0].uri, 'directory1', 'directory2', 'cdk.json')
await mkdirp(path.dirname(cdkJsonUri.fsPath))
await fs.mkdir(path.dirname(cdkJsonUri.fsPath))
await saveCdkJson(cdkJsonUri.fsPath)
const actual = await detectCdkProjects_wait(workspaceFolders)
assert.strictEqual(actual[0]?.cdkJsonUri.fsPath, cdkJsonUri.fsPath)
})

it('ignores projects in `node_modules`', async function () {
const cdkJsonPath = path.join(workspaceFolders[0].uri.fsPath, 'node_modules', 'lib', 'cdk.json')
await mkdirp(path.dirname(cdkJsonPath))
await fs.mkdir(path.dirname(cdkJsonPath))
await saveCdkJson(cdkJsonPath)
const actual = await detectCdkProjects_wait(workspaceFolders)
assert.strictEqual(actual.length, 0)
Expand All @@ -118,7 +117,8 @@ describe('detectCdkProjects', function () {

it('takes into account `output` from cdk.json to build tree.json path', async function () {
const cdkJsonUri = vscode.Uri.joinPath(workspaceFolders[0].uri, 'cdk.json')
await writeJSON(cdkJsonUri.fsPath, { app: 'npx ts-node bin/demo-nov7.ts', output: 'build/cdk.out' })
const cdkJsonStr = JSON.stringify({ app: 'npx ts-node bin/demo-nov7.ts', output: 'build/cdk.out' })
await fs.writeFile(cdkJsonUri.fsPath, cdkJsonStr)
const actual = await detectCdkProjects_wait(workspaceFolders)

assert.ok(actual)
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/test/awsService/cdk/treeTestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { writeFile } from 'fs-extra'
import { ConstructTree, ConstructTreeEntity } from '../../../awsService/cdk/explorer/tree/types'
import { fs } from '../../../shared'

export async function saveCdkJson(cdkJsonPath: string) {
const cdkJsonContent = '{ "app": "npx ts-node bin/demo-nov7.ts"}'

await writeFile(cdkJsonPath, cdkJsonContent, 'utf8')
await fs.writeFile(cdkJsonPath, cdkJsonContent, 'utf8')
}

export function generateConstructTreeEntity(label: string, treePath: string, children?: boolean): ConstructTreeEntity {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import assert from 'assert'
import * as path from 'path'
import * as vscode from 'vscode'
import * as fs from 'fs-extra'

import { createURIFromArgs } from '../../../../awsService/cloudWatchLogs/cloudWatchLogsUtils'
import { saveCurrentLogDataContent } from '../../../../awsService/cloudWatchLogs/commands/saveCurrentLogDataContent'
Expand All @@ -19,6 +18,7 @@ import {
LogDataRegistry,
} from '../../../../awsService/cloudWatchLogs/registry/logDataRegistry'
import { assertTextEditorContains } from '../../../testUtil'
import { fs } from '../../../../shared'

async function testFilterLogEvents(
logGroupInfo: CloudWatchLogsGroupInfo,
Expand Down Expand Up @@ -46,7 +46,7 @@ describe('saveCurrentLogDataContent', async function () {
})

afterEach(async function () {
await fs.remove(tempDir)
await fs.delete(tempDir)
})

it('saves log content to a file', async function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import assert, { fail } from 'assert'
import * as vscode from 'vscode'
import * as fs from 'fs-extra'
import * as sinon from 'sinon'
import { makeTemporaryToolkitFolder } from '../../../shared/filesystemUtilities'
import { transformByQState, TransformByQStoppedError } from '../../../codewhisperer/models/model'
Expand Down Expand Up @@ -37,6 +36,7 @@ import {
} from '../../../codewhisperer/service/transformByQ/transformProjectValidationHandler'
import { TransformationCandidateProject, ZipManifest } from '../../../codewhisperer/models/model'
import globals from '../../../shared/extensionGlobals'
import { fs } from '../../../shared'

describe('transformByQ', function () {
let tempDir: string
Expand All @@ -48,7 +48,7 @@ describe('transformByQ', function () {

afterEach(async function () {
sinon.restore()
await fs.remove(tempDir)
await fs.delete(tempDir)
})

it('WHEN converting short duration in milliseconds THEN converts correctly', async function () {
Expand Down Expand Up @@ -254,13 +254,13 @@ describe('transformByQ', function () {
'resolver-status.properties',
]

m2Folders.forEach((folder) => {
for (const folder of m2Folders) {
const folderPath = path.join(tempDir, folder)
fs.mkdirSync(folderPath, { recursive: true })
filesToAdd.forEach((file) => {
fs.writeFileSync(path.join(folderPath, file), 'sample content for the test file')
})
})
await fs.mkdir(folderPath)
for (const file of filesToAdd) {
await fs.writeFile(path.join(folderPath, file), 'sample content for the test file')
}
}

const tempFileName = `testfile-${globals.clock.Date.now()}.zip`
transformByQState.setProjectPath(tempDir)
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/test/credentials/sharedCredentials.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

import assert from 'assert'
import * as path from 'path'
import * as fs from 'fs-extra'
import { EnvironmentVariables } from '../../shared/environmentVariables'
import { makeTemporaryToolkitFolder } from '../../shared/filesystemUtilities'
import { getCredentialsFilename, getConfigFilename } from '../../auth/credentials/sharedCredentialsFile'
import { fs } from '../../shared'

describe('sharedCredentials', function () {
let tempFolder: string
Expand All @@ -26,7 +26,7 @@ describe('sharedCredentials', function () {
})

after(async function () {
await fs.remove(tempFolder)
await fs.delete(tempFolder)
})

describe('getCredentialsFilename', function () {
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/test/credentials/sso/cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

import assert from 'assert'
import * as path from 'path'
import * as fs from 'fs-extra'
import { makeTemporaryToolkitFolder, tryRemoveFolder } from '../../../shared/filesystemUtilities'
import { getRegistrationCache, getTokenCache } from '../../../auth/sso/cache'
import { fs } from '../../../shared'

describe('SSO Cache', function () {
const region = 'dummyRegion'
Expand Down Expand Up @@ -47,7 +47,7 @@ describe('SSO Cache', function () {
await cache.save({ startUrl, region }, validRegistration)

const cachedPath = path.join(testDir, `aws-toolkit-vscode-client-id-${region}.json`)
const contents = await fs.readFile(cachedPath, 'utf-8')
const contents = await fs.readFileAsString(cachedPath)

assert.deepStrictEqual(JSON.parse(contents), {
...validRegistration,
Expand All @@ -70,7 +70,7 @@ describe('SSO Cache', function () {

// SHA-1 hash of the encoded start URL `https://123456.awsapps.com/start`
const cachedPath = path.join(testDir, 'c1ac99f782ad92755c6de8647b510ec247330ad1.json')
const contents = await fs.readFile(cachedPath, 'utf-8')
const contents = await fs.readFileAsString(cachedPath)

assert.deepStrictEqual(JSON.parse(contents), {
region,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import { CloudControlClient, DefaultCloudControlClient } from '../../shared/clie
import { CloudFormationClient, DefaultCloudFormationClient } from '../../shared/clients/cloudFormationClient'
import { makeTemporaryToolkitFolder, readFileAsString } from '../../shared/filesystemUtilities'
import { FakeExtensionContext } from '../fakeExtensionContext'
import { remove } from 'fs-extra'
import { existsSync } from 'fs'
import { ResourceTypeMetadata } from '../../dynamicResources/model/resources'
import globals from '../../shared/extensionGlobals'
import { Stub, stub } from '../utilities/stubber'
import { CloudControl, CloudFormation } from 'aws-sdk'
import { fs } from '../../shared'

describe('ResourceManager', function () {
let sandbox: sinon.SinonSandbox
Expand Down Expand Up @@ -71,7 +71,7 @@ describe('ResourceManager', function () {
registerMappingSpy.restore()
sandbox.restore()
await resourceManager.dispose()
await remove(tempFolder)
await fs.delete(tempFolder)
})

it('opens resources in preview mode', async function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*/

import assert from 'assert'
import * as fs from 'fs-extra'
import * as path from 'path'
import * as vscode from 'vscode'

Expand All @@ -25,6 +24,8 @@ import { MockOutputChannel } from '../../../test/mockOutputChannel'
import admZip from 'adm-zip'
import { makeTemporaryToolkitFolder } from '../../../shared/filesystemUtilities'
import { DefaultSchemaClient } from '../../../shared/clients/schemaClient'
import { fs } from '../../../shared'
import * as fs2 from 'fs'

describe('CodeDownloader', function () {
let tempFolder: string
Expand All @@ -48,7 +49,7 @@ describe('CodeDownloader', function () {

afterEach(async function () {
sandbox.restore()
await fs.remove(tempFolder)
await fs.delete(tempFolder)
})
const testSchemaName = 'testSchema'
const testRegistryName = 'testRegistry'
Expand Down Expand Up @@ -128,7 +129,7 @@ describe('CodeGenerator', function () {

afterEach(async function () {
sandbox.restore()
await fs.remove(tempFolder)
await fs.delete(tempFolder)
})
const testSchemaName = 'testSchema'
const testRegistryName = 'testRegistry'
Expand Down Expand Up @@ -201,7 +202,7 @@ describe('CodeGeneratorStatusPoller', function () {

afterEach(async function () {
sandbox.restore()
await fs.remove(tempFolder)
await fs.delete(tempFolder)
})
const testSchemaName = 'testSchema'
const testRegistryName = 'testRegistry'
Expand Down Expand Up @@ -352,7 +353,7 @@ describe('SchemaCodeDownload', function () {

afterEach(async function () {
sandbox.restore()
await fs.remove(tempFolder)
await fs.delete(tempFolder)
})
const testSchemaName = 'testSchema'
const testRegistryName = 'testRegistry'
Expand Down Expand Up @@ -383,7 +384,7 @@ describe('SchemaCodeDownload', function () {

// should extract the zip file with provided fileContent
const expectedFilePath = path.join(request.destinationDirectory.fsPath, fileName)
const response = fs.readFileSync(expectedFilePath, 'utf8')
const response = await fs.readFileAsString(expectedFilePath)
assert.strictEqual(response, fileContent, `${expectedFilePath} :file content do not match`)
})

Expand Down Expand Up @@ -420,7 +421,7 @@ describe('SchemaCodeDownload', function () {
)

const expectedFilePath = path.join(request.destinationDirectory.fsPath, fileName)
const response = fs.readFileSync(expectedFilePath, 'utf8')
const response = await fs.readFileAsString(expectedFilePath)
assert.strictEqual(response, fileContent, 'Extracted file content do not match with expected')
})

Expand Down Expand Up @@ -449,7 +450,7 @@ describe('CodeExtractor', function () {
})

afterEach(async function () {
await fs.remove(destinationDirectory)
await fs.delete(destinationDirectory)
sandbox.restore()
})

Expand Down Expand Up @@ -524,7 +525,7 @@ describe('CodeExtractor', function () {

afterEach(async function () {
sandbox.restore()
await fs.remove(destinationDirectory)
await fs.delete(destinationDirectory)
})

it('should extract files if no collision present', async function () {
Expand All @@ -546,12 +547,12 @@ describe('CodeExtractor', function () {
const file2Path = path.join(destinationDirectory, fileName2)

// confirm both file exist
assert.ok(fs.existsSync(file1Path), `${file1Path} should exist`)
assert.ok(fs.existsSync(file2Path), `${file2Path} should exist`)
assert.ok(await fs.exists(file1Path), `${file1Path} should exist`)
assert.ok(await fs.exists(file2Path), `${file2Path} should exist`)

//confirm file contents
const file1Content = fs.readFileSync(file1Path, { encoding: 'utf8' })
const file2Content = fs.readFileSync(file2Path, { encoding: 'utf8' })
const file1Content = await fs.readFileAsString(file1Path)
const file2Content = await fs.readFileAsString(file2Path)

assert.strictEqual(file1Content, 'First file content', `${file1Path} : file content do not match`)
assert.strictEqual(file2Content, 'Second file content', `${file2Path} : file content do not match`)
Expand All @@ -577,7 +578,7 @@ describe('CodeExtractor', function () {
await codeExtractor.extractAndPlace(buffer, request)

const file1Path = path.join(destinationDirectory, fileName1)
const file1Content = fs.readFileSync(file1Path, { encoding: 'utf8' })
const file1Content = await fs.readFileAsString(file1Path)

assert.strictEqual(file1Content, expectedFileContent, `${file1Path} :File content should not be overriden`)
})
Expand All @@ -603,7 +604,7 @@ describe('CodeExtractor', function () {
await codeExtractor.extractAndPlace(buffer, request)

const file1Path = path.join(destinationDirectory, fileName1)
const file1Content = fs.readFileSync(file1Path, { encoding: 'utf8' })
const file1Content = await fs.readFileAsString(file1Path)

assert.strictEqual(file1Content, overridenFileContent, `${file1Path} :File content should be overriden`)
})
Expand Down Expand Up @@ -633,7 +634,7 @@ describe('CodeExtractor', function () {
)

const file1Path = path.join(destinationDirectory, fileName1)
const file1Content = fs.readFileSync(file1Path, { encoding: 'utf8' })
const file1Content = await fs.readFileAsString(file1Path)

assert.strictEqual(file1Content, expectedFileContent, `${file1Path} :File content should not be overriden`)
})
Expand Down Expand Up @@ -681,9 +682,9 @@ describe('CodeExtractor', function () {
const zip = new admZip()
zip.addFile(fileName, Buffer.from(fileContent))
const buffer = zip.toBuffer()
const fd = fs.openSync(zipFileName, 'w')
fs.writeSync(fd, buffer, 0, buffer.byteLength, 0)
fs.closeSync(fd)
const fd = fs2.openSync(zipFileName, 'w')
fs2.writeSync(fd, buffer, 0, buffer.byteLength, 0)
fs2.closeSync(fd)

return zip
}
Expand Down
Loading
Loading