Skip to content

Commit dfb4889

Browse files
committed
migrate next chunk of files
1 parent e9613f8 commit dfb4889

20 files changed

+121
-117
lines changed

packages/core/src/test/shared/codelens/csharpCodeLensProvider.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66
import assert from 'assert'
77
import * as os from 'os'
88
import * as path from 'path'
9-
import * as fs from 'fs-extra'
109
import * as vscode from 'vscode'
1110
import * as sampleDotNetSamProgram from './sampleDotNetSamProgram'
1211

13-
import { writeFile } from 'fs-extra'
1412
import {
1513
DotNetLambdaHandlerComponents,
1614
generateDotNetLambdaHandler,
@@ -19,6 +17,7 @@ import {
1917
isValidLambdaHandler,
2018
} from '../../../shared/codelens/csharpCodeLensProvider'
2119
import { makeTemporaryToolkitFolder } from '../../../shared/filesystemUtilities'
20+
import { fs } from '../../../shared'
2221

2322
const fakeRange = new vscode.Range(0, 0, 0, 0)
2423

@@ -31,12 +30,12 @@ describe('getLambdaHandlerComponents', async function () {
3130
})
3231

3332
afterEach(async function () {
34-
await fs.remove(tempFolder)
33+
await fs.delete(tempFolder)
3534
})
3635

3736
it('Detects a public function symbol', async function () {
3837
const programFile = path.join(tempFolder, 'program.cs')
39-
await writeFile(programFile, sampleDotNetSamProgram.getFunctionText())
38+
await fs.writeFile(programFile, sampleDotNetSamProgram.getFunctionText())
4039

4140
const textDoc = await vscode.workspace.openTextDocument(programFile)
4241
const documentSymbols = sampleDotNetSamProgram.getDocumentSymbols()

packages/core/src/test/shared/codelens/goCodeLensProvider.test.ts

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

66
import assert from 'assert'
77
import * as path from 'path'
8-
import * as fs from 'fs-extra'
98
import * as vscode from 'vscode'
109

11-
import { writeFile } from 'fs-extra'
1210
import { isValidFuncSignature } from '../../../shared/codelens/goCodeLensProvider'
1311
import { makeTemporaryToolkitFolder } from '../../../shared/filesystemUtilities'
12+
import { fs } from '../../../shared'
1413

1514
describe('getLambdaHandlerCandidates', async function () {
1615
let tempFolder: string
@@ -23,12 +22,12 @@ describe('getLambdaHandlerCandidates', async function () {
2322
programFile = path.join(tempFolder, 'program.go')
2423
dummyMod = path.join(tempFolder, 'go.mod')
2524

26-
await writeFile(programFile, getFunctionText())
27-
await writeFile(dummyMod, 'require github.com/aws/aws-lambda-go v1.13.3\nmodule hello-world\ngo 1.14')
25+
await fs.writeFile(programFile, getFunctionText())
26+
await fs.writeFile(dummyMod, 'require github.com/aws/aws-lambda-go v1.13.3\nmodule hello-world\ngo 1.14')
2827
})
2928

3029
after(async function () {
31-
await fs.remove(tempFolder)
30+
await fs.delete(tempFolder)
3231
})
3332

3433
it('Detects only good function symbols from a mock program', async function () {

packages/core/src/test/shared/codelens/javaCodeLensProvider.test.ts

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

66
import assert from 'assert'
7-
import * as fs from 'fs-extra'
87
import * as os from 'os'
98
import * as path from 'path'
109
import * as vscode from 'vscode'
@@ -17,6 +16,7 @@ import {
1716
} from '../../../shared/codelens/javaCodeLensProvider'
1817
import { makeTemporaryToolkitFolder } from '../../../shared/filesystemUtilities'
1918
import * as SampleJavaSamProgram from './sampleJavaSamProgram'
19+
import { fs } from '../../../shared'
2020

2121
const fakeRange = new vscode.Range(0, 0, 0, 0)
2222

@@ -30,7 +30,7 @@ describe('javaCodeLensProvider', () => {
3030
})
3131

3232
afterEach(async () => {
33-
await fs.remove(tempFolder)
33+
await fs.delete(tempFolder)
3434
})
3535

3636
it('Detects a public function symbol', async function () {

packages/core/src/test/shared/codelens/localLambdaRunner.test.ts

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

66
import assert from 'assert'
77
import * as vscode from 'vscode'
8-
import * as fs from 'fs-extra'
98
import * as fsUtils from '../../../shared/filesystemUtilities'
109
import { SamCliBuildInvocation, SamCliBuildInvocationArguments } from '../../../shared/sam/cli/samCliBuild'
1110
import * as localLambdaRunner from '../../../shared/sam/localLambdaRunner'
@@ -14,6 +13,7 @@ import { FakeExtensionContext } from '../../fakeExtensionContext'
1413
import { SamLaunchRequestArgs } from '../../../shared/sam/debugger/awsSamDebugger'
1514
import { assertLogsContain } from '../../globalSetup.test'
1615
import { ToolkitError } from '../../../shared/errors'
16+
import { fs } from '../../../shared'
1717

1818
describe('localLambdaRunner', async function () {
1919
let tempDir: string
@@ -26,7 +26,7 @@ describe('localLambdaRunner', async function () {
2626
})
2727

2828
afterEach(async function () {
29-
await fs.remove(tempDir)
29+
await fs.delete(tempDir)
3030
})
3131

3232
describe('attachDebugger', async function () {

packages/core/src/test/shared/credentials/userCredentialsUtils.test.ts

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

66
import assert from 'assert'
7-
import * as fs from 'fs-extra'
87
import * as path from 'path'
98
import * as sinon from 'sinon'
109

@@ -20,6 +19,7 @@ import { UserCredentialsUtils } from '../../../shared/credentials/userCredential
2019
import { EnvironmentVariables } from '../../../shared/environmentVariables'
2120
import { makeTemporaryToolkitFolder } from '../../../shared/filesystemUtilities'
2221
import { getConfigFilename, getCredentialsFilename } from '../../../auth/credentials/sharedCredentialsFile'
22+
import { fs } from '../../../shared'
2323

2424
describe('UserCredentialsUtils', function () {
2525
let tempFolder: string
@@ -35,17 +35,14 @@ describe('UserCredentialsUtils', function () {
3535
})
3636

3737
afterEach(async function () {
38-
if (fs.existsSync(defaultConfigFileName)) {
39-
await fs.rm(defaultConfigFileName)
40-
}
41-
if (fs.existsSync(defaultCredentialsFilename)) {
42-
await fs.rm(defaultCredentialsFilename)
43-
}
38+
await fs.delete(defaultConfigFileName)
39+
await fs.delete(defaultCredentialsFilename)
40+
4441
sinon.restore()
4542
})
4643

4744
after(async function () {
48-
await fs.remove(tempFolder)
45+
await fs.delete(tempFolder)
4946
})
5047

5148
describe('findExistingCredentialsFilenames', function () {
@@ -58,8 +55,8 @@ describe('UserCredentialsUtils', function () {
5855
AWS_CONFIG_FILE: configFilename,
5956
} as EnvironmentVariables)
6057

61-
createCredentialsFile(credentialsFilename, ['default'])
62-
createCredentialsFile(configFilename, ['default'])
58+
await createCredentialsFile(credentialsFilename, ['default'])
59+
await createCredentialsFile(configFilename, ['default'])
6360

6461
const foundFiles: string[] = await UserCredentialsUtils.findExistingCredentialsFilenames()
6562
assert.strictEqual(foundFiles.length, 2)
@@ -74,7 +71,7 @@ describe('UserCredentialsUtils', function () {
7471
AWS_CONFIG_FILE: configFilename,
7572
} as EnvironmentVariables)
7673

77-
createCredentialsFile(credentialsFilename, ['default'])
74+
await createCredentialsFile(credentialsFilename, ['default'])
7875

7976
const foundFiles: string[] = await UserCredentialsUtils.findExistingCredentialsFilenames()
8077
assert.strictEqual(foundFiles.length, 1)
@@ -90,7 +87,7 @@ describe('UserCredentialsUtils', function () {
9087
AWS_CONFIG_FILE: configFilename,
9188
} as EnvironmentVariables)
9289

93-
createCredentialsFile(configFilename, ['default'])
90+
await createCredentialsFile(configFilename, ['default'])
9491

9592
const foundFiles: string[] = await UserCredentialsUtils.findExistingCredentialsFilenames()
9693
assert.strictEqual(foundFiles.length, 1)
@@ -124,7 +121,7 @@ describe('UserCredentialsUtils', function () {
124121
profileName: profileName,
125122
secretKey: 'ABC',
126123
}
127-
createCredentialsFile(credentialsFilename, [profileName])
124+
await createCredentialsFile(credentialsFilename, [profileName])
128125
await UserCredentialsUtils.generateCredentialsFile(creds)
129126

130127
const sharedConfigFiles = await loadSharedConfigFiles({ credentials: Uri.file(credentialsFilename) })
@@ -144,10 +141,9 @@ describe('UserCredentialsUtils', function () {
144141
creds.secretKey,
145142
`creds.secretKey: "${profile.aws_access_key_id}" !== "${creds.secretKey}"`
146143
)
147-
await fs.access(credentialsFilename, fs.constants.R_OK).catch((_err) => assert(false, 'Should be readable'))
148-
await fs
149-
.access(credentialsFilename, fs.constants.W_OK)
150-
.catch((_err) => assert(false, 'Should be writeable'))
144+
145+
assert.ok(await fs.checkPerms(credentialsFilename, 'r--'))
146+
assert.ok(await fs.checkPerms(credentialsFilename, '-w-'))
151147
})
152148
})
153149

@@ -156,7 +152,7 @@ describe('UserCredentialsUtils', function () {
156152
const credentialsFilename = path.join(tempFolder, 'credentials-generation-test')
157153
const profileName = 'someRandomProfileName'
158154

159-
createCredentialsFile(credentialsFilename, [profileName])
155+
await createCredentialsFile(credentialsFilename, [profileName])
160156

161157
const sharedConfigFiles = await loadSharedConfigFiles({ credentials: Uri.file(credentialsFilename) })
162158
const profile = getSectionDataOrThrow(
@@ -168,7 +164,7 @@ describe('UserCredentialsUtils', function () {
168164
})
169165
})
170166

171-
function createCredentialsFile(filename: string, profileNames: string[]): void {
167+
async function createCredentialsFile(filename: string, profileNames: string[]): Promise<void> {
172168
let fileContents = ''
173169

174170
profileNames.forEach((profileName) => {
@@ -179,6 +175,6 @@ REGION = us-weast-3
179175
`
180176
})
181177

182-
fs.writeFileSync(filename, fileContents)
178+
await fs.writeFile(filename, fileContents)
183179
}
184180
})

packages/core/src/test/shared/extensionUtilities.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { extensionVersion } from '../../shared/vscode/env'
1919
import { sleep } from '../../shared/utilities/timeoutUtils'
2020
import globals from '../../shared/extensionGlobals'
2121
import { createQuickStartWebview } from '../../shared/extensionStartup'
22+
import { fs } from '../../shared'
2223

2324
describe('extensionUtilities', function () {
2425
describe('createQuickStartWebview', async function () {
@@ -33,7 +34,7 @@ describe('extensionUtilities', function () {
3334

3435
afterEach(async function () {
3536
if (tempDir) {
36-
await remove(tempDir)
37+
await fs.delete(tempDir)
3738
}
3839
})
3940

@@ -44,7 +45,7 @@ describe('extensionUtilities', function () {
4445
it('returns a webview with unaltered text if a valid file is passed without tokens', async function () {
4546
const filetext = 'this temp page does not have any tokens'
4647
const filepath = 'tokenless'
47-
await writeFile(path.join(context.extensionPath, filepath), filetext)
48+
await fs.writeFile(path.join(context.extensionPath, filepath), filetext)
4849
const webview = await createQuickStartWebview(context, filepath)
4950

5051
assert.strictEqual(typeof webview, 'object')
@@ -57,7 +58,7 @@ describe('extensionUtilities', function () {
5758
const basetext = 'this temp page has tokens: '
5859
const filetext = basetext + token
5960
const filepath = 'tokenless'
60-
await writeFile(path.join(context.extensionPath, filepath), filetext)
61+
await fs.writeFile(path.join(context.extensionPath, filepath), filetext)
6162
const webview = await createQuickStartWebview(context, filepath)
6263

6364
assert.strictEqual(typeof webview, 'object')

packages/core/src/test/shared/filesystemUtilities.test.ts

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

66
import assert from 'assert'
77
import * as os from 'os'
8-
import { writeFile, remove } from 'fs-extra'
98
import * as path from 'path'
109
import {
1110
fileExists,
@@ -15,6 +14,7 @@ import {
1514
makeTemporaryToolkitFolder,
1615
tempDirPath,
1716
} from '../../shared/filesystemUtilities'
17+
import { fs } from '../../shared'
1818

1919
describe('filesystemUtilities', function () {
2020
const targetFilename = 'findThisFile12345.txt'
@@ -27,14 +27,14 @@ describe('filesystemUtilities', function () {
2727
tempFolder = await makeTemporaryToolkitFolder()
2828
targetFilePath = path.join(tempFolder, targetFilename)
2929

30-
await writeFile(targetFilePath, 'Hello, World!', 'utf8')
30+
await fs.writeFile(targetFilePath, 'Hello, World!', 'utf8')
3131

3232
foldersToCleanUp.push(tempFolder)
3333
})
3434

3535
afterEach(async function () {
3636
for (const folder of foldersToCleanUp) {
37-
await remove(folder)
37+
await fs.delete(folder)
3838
}
3939
})
4040

@@ -45,17 +45,17 @@ describe('filesystemUtilities', function () {
4545
})
4646
it(`returns a filename that does not exist in the directory`, async function () {
4747
const dir = tempFolder
48-
await writeFile(path.join(dir, 'foo.txt'), '', 'utf8')
49-
await writeFile(path.join(dir, 'foo-0.txt'), '', 'utf8')
50-
await writeFile(path.join(dir, 'foo-1.txt'), '', 'utf8')
51-
await writeFile(path.join(dir, 'foo-2.txt'), '', 'utf8')
48+
await fs.writeFile(path.join(dir, 'foo.txt'), '', 'utf8')
49+
await fs.writeFile(path.join(dir, 'foo-0.txt'), '', 'utf8')
50+
await fs.writeFile(path.join(dir, 'foo-1.txt'), '', 'utf8')
51+
await fs.writeFile(path.join(dir, 'foo-2.txt'), '', 'utf8')
5252
assert.strictEqual(await getNonexistentFilename(dir, 'foo', '.txt', 99), 'foo-3.txt')
5353
assert.strictEqual(await getNonexistentFilename(dir, 'foo', '', 99), 'foo')
5454
})
5555
it(`returns "foo-RANDOM.txt" if max is reached`, async function () {
5656
const dir = tempFolder
57-
await writeFile(path.join(dir, 'foo.txt'), '', 'utf8')
58-
await writeFile(path.join(dir, 'foo-1.txt'), '', 'utf8')
57+
await fs.writeFile(path.join(dir, 'foo.txt'), '', 'utf8')
58+
await fs.writeFile(path.join(dir, 'foo-1.txt'), '', 'utf8')
5959
// Looks like "foo-75446d5d.txt".
6060
assert.ok(/^foo-[a-fA-F0-9]{8}.txt$/.test(await getNonexistentFilename(dir, 'foo', '.txt', 1)))
6161
})

packages/core/src/test/shared/fs/templateRegistry.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
import assert from 'assert'
77
import * as path from 'path'
88
import * as vscode from 'vscode'
9-
import * as fs from 'fs-extra'
10-
119
import {
1210
CloudFormationTemplateRegistry,
1311
getResourcesForHandler,
@@ -18,6 +16,7 @@ import { badYaml, makeSampleSamTemplateYaml, strToYamlFile } from '../cloudforma
1816
import { assertEqualPaths, toFile } from '../../testUtil'
1917
import * as CloudFormation from '../../../shared/cloudformation/cloudformation'
2018
import { WatchedItem } from '../../../shared/fs/watchedFiles'
19+
import { fs } from '../../../shared'
2120

2221
// TODO almost all of these tests should be moved to test WatchedFiles instead
2322
describe('CloudFormation Template Registry', async function () {
@@ -33,7 +32,7 @@ describe('CloudFormation Template Registry', async function () {
3332
})
3433

3534
afterEach(async function () {
36-
await fs.remove(tempFolder)
35+
await fs.delete(tempFolder)
3736
})
3837

3938
describe('addItem', async function () {
@@ -349,7 +348,7 @@ describe('CloudFormation Template Registry', async function () {
349348
})
350349

351350
afterEach(async function () {
352-
await fs.remove(tempFolder)
351+
await fs.delete(tempFolder)
353352
})
354353

355354
const resource: {

packages/core/src/test/shared/icons.test.ts

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

66
import assert from 'assert'
7-
import * as fs from 'fs-extra'
87
import * as path from 'path'
98
import { Uri, ThemeIcon } from 'vscode'
109
import { codicon, getIcon } from '../../shared/icons'
1110
import { makeTemporaryToolkitFolder, tryRemoveFolder } from '../../shared/filesystemUtilities'
11+
import { fs } from '../../shared'
1212

1313
describe('getIcon', function () {
1414
it('returns a ThemeIcon for `vscode` codicons', function () {
@@ -68,7 +68,7 @@ describe('getIcon', function () {
6868

6969
try {
7070
for (const p of paths) {
71-
await fs.mkdirp(path.dirname(p))
71+
await fs.mkdir(path.dirname(p))
7272
await fs.writeFile(p, '<svg></svg>')
7373
}
7474

@@ -87,7 +87,7 @@ describe('getIcon', function () {
8787
const logoPath = path.join(tempDir, 'aws', 'cdk', 'logo.svg')
8888

8989
try {
90-
await fs.mkdirp(path.dirname(logoPath))
90+
await fs.mkdir(path.dirname(logoPath))
9191
await fs.writeFile(logoPath, '<svg></svg>')
9292

9393
const icon = getIcon('aws-cdk-logo', false, tempDir)

0 commit comments

Comments
 (0)