Skip to content

Commit 0ecc958

Browse files
committed
test: Add tests for quickedit readme
1 parent ca3a617 commit 0ecc958

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

packages/core/src/test/lambda/commands/editLambda.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
promptForSync,
1313
deployFromTemp,
1414
openLambdaFolderForEdit,
15+
getReadme,
1516
} from '../../../lambda/commands/editLambda'
1617
import { LambdaFunction } from '../../../lambda/commands/uploadLambda'
1718
import * as downloadLambda from '../../../lambda/commands/downloadLambda'
@@ -21,6 +22,8 @@ import * as messages from '../../../shared/utilities/messages'
2122
import fs from '../../../shared/fs/fs'
2223
import { LambdaFunctionNodeDecorationProvider } from '../../../lambda/explorer/lambdaFunctionNodeDecorationProvider'
2324
import path from 'path'
25+
import globals from '../../../shared/extensionGlobals'
26+
import { lambdaTempPath } from '../../../lambda/utils'
2427

2528
describe('editLambda', function () {
2629
let mockLambda: LambdaFunction
@@ -41,6 +44,10 @@ describe('editLambda', function () {
4144
let mkdirStub: sinon.SinonStub
4245
let promptDeployStub: sinon.SinonStub
4346
let readdirStub: sinon.SinonStub
47+
let readFileTextStub: sinon.SinonStub
48+
let writeFileStub: sinon.SinonStub
49+
let copyStub: sinon.SinonStub
50+
let asAbsolutePathStub: sinon.SinonStub
4451

4552
beforeEach(function () {
4653
mockLambda = {
@@ -75,6 +82,10 @@ describe('editLambda', function () {
7582
readdirStub = sinon.stub(fs, 'readdir').resolves([['file', vscode.FileType.File]])
7683
promptDeployStub = sinon.stub().resolves(true)
7784
sinon.replace(require('../../../lambda/commands/editLambda'), 'promptDeploy', promptDeployStub)
85+
readFileTextStub = sinon.stub(fs, 'readFileText').resolves('# Lambda Edit README')
86+
writeFileStub = sinon.stub(fs, 'writeFile').resolves()
87+
copyStub = sinon.stub(fs, 'copy').resolves()
88+
asAbsolutePathStub = sinon.stub(globals.context, 'asAbsolutePath').callsFake((p) => `/absolute/${p}`)
7889

7990
// Other stubs
8091
sinon.stub(utils, 'getLambdaDetails').returns({ fileName: 'index.js', functionName: 'test-function' })
@@ -268,4 +279,21 @@ describe('editLambda', function () {
268279
)
269280
})
270281
})
282+
283+
describe('getReadme', function () {
284+
it('reads markdown file and writes README.md to temp path', async function () {
285+
const result = await getReadme()
286+
287+
assert(readFileTextStub.calledOnce)
288+
assert(asAbsolutePathStub.calledWith(path.join('resources', 'markdown', 'lambdaEdit.md')))
289+
assert(writeFileStub.calledWith(path.join(lambdaTempPath, 'README.md'), '# Lambda Edit README'))
290+
assert.strictEqual(result, path.join(lambdaTempPath, 'README.md'))
291+
})
292+
293+
it('copies all required icon files', async function () {
294+
await getReadme()
295+
296+
assert.strictEqual(copyStub.callCount, 3)
297+
})
298+
})
271299
})

0 commit comments

Comments
 (0)