@@ -19,24 +19,34 @@ import { IEnvironmentService } from 'vs/platform/environment/common/environment'
1919import { BackupService } from 'vs/platform/backup/node/backupService' ;
2020
2121suite ( 'BackupService' , ( ) => {
22+ const parentDir = path . join ( os . tmpdir ( ) , 'vsctests' , 'service' )
23+ const backupHome = path . join ( parentDir , 'Backups' ) ;
24+ const backupWorkspacesHome = path . join ( backupHome , 'workspaces.json' ) ;
25+
2226 const fooFile = Uri . file ( platform . isWindows ? 'C:\\foo' : '/foo' ) ;
2327 const barFile = Uri . file ( platform . isWindows ? 'C:\\bar' : '/bar' ) ;
2428 const bazFile = Uri . file ( platform . isWindows ? 'C:\\baz' : '/baz' ) ;
2529
26- let environmentService : IEnvironmentService ;
2730 let backupService : BackupService ;
2831
2932 setup ( done => {
30- environmentService = TestEnvironmentService ;
33+ const environmentService = TestEnvironmentService ;
34+
3135 backupService = new BackupService ( environmentService ) ;
36+ backupService . setBackupPathsForTest ( backupHome , backupWorkspacesHome ) ;
3237
33- // Delete any existing backups completely, this in itself is a test to ensure that the
34- // the backupHome directory is re-created
35- extfs . del ( environmentService . backupHome , os . tmpdir ( ) , done ) ;
38+ // Delete any existing backups completely and then re-create it.
39+ extfs . del ( backupHome , os . tmpdir ( ) , ( ) => {
40+ pfs . mkdirp ( backupHome ) . then ( ( ) => {
41+ pfs . writeFileAndFlush ( backupWorkspacesHome , '' ) . then ( ( ) => {
42+ done ( ) ;
43+ } ) ;
44+ } ) ;
45+ } ) ;
3646 } ) ;
3747
3848 teardown ( done => {
39- extfs . del ( environmentService . backupHome , os . tmpdir ( ) , done ) ;
49+ extfs . del ( backupHome , os . tmpdir ( ) , done ) ;
4050 } ) ;
4151
4252 test ( 'pushWorkspaceBackupPathsSync should persist paths to workspaces.json' , ( ) => {
@@ -96,7 +106,7 @@ suite('BackupService', () => {
96106 const backupResource = barFile ;
97107 const workspaceHash = crypto . createHash ( 'md5' ) . update ( workspaceResource . fsPath ) . digest ( 'hex' ) ;
98108 const filePathHash = crypto . createHash ( 'md5' ) . update ( backupResource . fsPath ) . digest ( 'hex' ) ;
99- const expectedPath = Uri . file ( path . join ( environmentService . backupHome , workspaceHash , 'file' , filePathHash ) ) . fsPath ;
109+ const expectedPath = Uri . file ( path . join ( backupHome , workspaceHash , 'file' , filePathHash ) ) . fsPath ;
100110 assert . equal ( backupService . getBackupResource ( backupResource ) . fsPath , expectedPath ) ;
101111 } ) ;
102112
@@ -107,7 +117,7 @@ suite('BackupService', () => {
107117 const backupResource = Uri . from ( { scheme : 'untitled' } ) ;
108118 const workspaceHash = crypto . createHash ( 'md5' ) . update ( workspaceResource . fsPath ) . digest ( 'hex' ) ;
109119 const filePathHash = crypto . createHash ( 'md5' ) . update ( backupResource . fsPath ) . digest ( 'hex' ) ;
110- const expectedPath = Uri . file ( path . join ( environmentService . backupHome , workspaceHash , 'untitled' , filePathHash ) ) . fsPath ;
120+ const expectedPath = Uri . file ( path . join ( backupHome , workspaceHash , 'untitled' , filePathHash ) ) . fsPath ;
111121 assert . equal ( backupService . getBackupResource ( backupResource ) . fsPath , expectedPath ) ;
112122 } ) ;
113123
@@ -118,7 +128,7 @@ suite('BackupService', () => {
118128 const backupResource = barFile ;
119129 const workspaceHash = crypto . createHash ( 'md5' ) . update ( workspaceResource . fsPath ) . digest ( 'hex' ) ;
120130 const filePathHash = crypto . createHash ( 'md5' ) . update ( backupResource . fsPath ) . digest ( 'hex' ) ;
121- const expectedPath = Uri . file ( path . join ( environmentService . backupHome , workspaceHash , 'file' , filePathHash ) ) . fsPath ;
131+ const expectedPath = Uri . file ( path . join ( backupHome , workspaceHash , 'file' , filePathHash ) ) . fsPath ;
122132 assert . equal ( backupService . getBackupResource ( backupResource ) . fsPath , expectedPath ) ;
123133 } ) ;
124134
@@ -129,7 +139,7 @@ suite('BackupService', () => {
129139 const backupResource = Uri . from ( { scheme : 'untitled' } ) ;
130140 const workspaceHash = crypto . createHash ( 'md5' ) . update ( workspaceResource . fsPath ) . digest ( 'hex' ) ;
131141 const filePathHash = crypto . createHash ( 'md5' ) . update ( backupResource . fsPath ) . digest ( 'hex' ) ;
132- const expectedPath = Uri . file ( path . join ( environmentService . backupHome , workspaceHash , 'untitled' , filePathHash ) ) . fsPath ;
142+ const expectedPath = Uri . file ( path . join ( backupHome , workspaceHash , 'untitled' , filePathHash ) ) . fsPath ;
133143 assert . equal ( backupService . getBackupResource ( backupResource ) . fsPath , expectedPath ) ;
134144 } ) ;
135145
@@ -149,7 +159,7 @@ suite('BackupService', () => {
149159 const workspaceResource = fooFile ;
150160 backupService . setCurrentWorkspace ( workspaceResource ) ;
151161 const workspaceHash = crypto . createHash ( 'md5' ) . update ( workspaceResource . fsPath ) . digest ( 'hex' ) ;
152- const untitledBackupDir = path . join ( environmentService . backupHome , workspaceHash , 'untitled' ) ;
162+ const untitledBackupDir = path . join ( backupHome , workspaceHash , 'untitled' ) ;
153163 const untitledBackup1 = path . join ( untitledBackupDir , 'bar' ) ;
154164 const untitledBackup2 = path . join ( untitledBackupDir , 'foo' ) ;
155165 pfs . mkdirp ( untitledBackupDir ) . then ( ( ) => {
0 commit comments