@@ -12,6 +12,7 @@ import {
1212 promptForSync ,
1313 deployFromTemp ,
1414 openLambdaFolderForEdit ,
15+ getReadme ,
1516} from '../../../lambda/commands/editLambda'
1617import { LambdaFunction } from '../../../lambda/commands/uploadLambda'
1718import * as downloadLambda from '../../../lambda/commands/downloadLambda'
@@ -21,6 +22,8 @@ import * as messages from '../../../shared/utilities/messages'
2122import fs from '../../../shared/fs/fs'
2223import { LambdaFunctionNodeDecorationProvider } from '../../../lambda/explorer/lambdaFunctionNodeDecorationProvider'
2324import path from 'path'
25+ import globals from '../../../shared/extensionGlobals'
26+ import { lambdaTempPath } from '../../../lambda/utils'
2427
2528describe ( '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