@@ -7,7 +7,7 @@ import assert from 'assert'
77import * as sinon from 'sinon'
88import { SafeEc2Instance } from '../../../shared/clients/ec2Client'
99import { getIconCode , getRemoveLinesCommand } from '../../../awsService/ec2/utils'
10- import { DefaultAwsContext , globals } from '../../../shared'
10+ import { DefaultAwsContext } from '../../../shared'
1111import { fs } from '../../../shared/fs/fs'
1212import { createTestWorkspaceFolder } from '../../testUtil'
1313import path from 'path'
@@ -58,23 +58,35 @@ describe('utils', async function () {
5858 } )
5959
6060 describe ( 'getRemoveLinesCommand' , async function ( ) {
61+ let tempPath : { uri : { fsPath : string } }
62+
63+ before ( async function ( ) {
64+ tempPath = await createTestWorkspaceFolder ( )
65+ } )
66+
67+ after ( async function ( ) {
68+ await fs . delete ( tempPath . uri . fsPath , { recursive : true , force : true } )
69+ } )
70+
6171 it ( 'removes lines prefixed by pattern' , async function ( ) {
62- const pattern = 'pattern'
6372 const lines = [ 'line1' , 'line2 pattern' , 'line3' , 'line4 pattern' , 'line5' , 'line6 pattern' , 'line7' ]
6473 const expected = [ 'line1' , 'line3' , 'line5' , 'line7' ]
65- const tempPath = await createTestWorkspaceFolder ( )
74+
75+ const lineToStr = ( ls : string [ ] ) => ls . join ( '\n' ) + '\n'
76+
6677 const textFile = path . join ( tempPath . uri . fsPath , 'test.txt' )
67- await fs . writeFile ( textFile , lines . join ( '\n' ) )
78+ const originalContent = lineToStr ( lines )
79+ await fs . writeFile ( textFile , originalContent )
6880
69- const [ command , ...args ] = getRemoveLinesCommand ( pattern , textFile ) . split ( ' ' )
81+ const [ command , ...args ] = getRemoveLinesCommand ( ' pattern' , textFile ) . split ( ' ' )
7082 const process = new ChildProcess ( command , args , { collect : true } )
7183 const result = await process . run ( )
7284
7385 assert . strictEqual ( result . exitCode , 0 , `ChildProcess failed with error=${ result . error } ` )
74- const newContent = await fs . readFileText ( textFile )
7586
76- assert . strictEqual ( newContent , expected . join ( '\n' ) + '\n' )
77- await fs . delete ( tempPath . uri . fsPath , { recursive : true , force : true } )
87+ const newContent = await fs . readFileText ( textFile )
88+ assert . notStrictEqual ( newContent , originalContent )
89+ assert . strictEqual ( newContent , lineToStr ( expected ) )
7890 } )
7991 } )
8092} )
0 commit comments