@@ -71,12 +71,10 @@ describe('A root logger.', () => {
71
71
72
72
describe ( 'Logger version handling' , ( ) => {
73
73
test ( 'Should not fail if package.json does not exist' , ( ) => {
74
- const packageFilePath = path . resolve ( __dirname , 'package.json' ) ;
75
-
76
74
// Temporarily rename package.json to simulate its absence
77
- const tempFilePath = `${ packageFilePath } .bak` ;
78
- if ( fs . existsSync ( packageFilePath ) ) {
79
- fs . renameSync ( packageFilePath , tempFilePath ) ;
75
+ const tempFilePath = `${ versionFilePath } .bak` ;
76
+ if ( fs . existsSync ( versionFilePath ) ) {
77
+ fs . renameSync ( versionFilePath , tempFilePath ) ;
80
78
}
81
79
82
80
setContext ( context , 'unit-test' ) ;
@@ -89,17 +87,15 @@ describe('Logger version handling', () => {
89
87
90
88
// Restore package.json
91
89
if ( fs . existsSync ( tempFilePath ) ) {
92
- fs . renameSync ( tempFilePath , packageFilePath ) ;
90
+ fs . renameSync ( tempFilePath , versionFilePath ) ;
93
91
}
94
92
} ) ;
95
93
96
94
test ( 'Should log version from package.json' , ( ) => {
97
- const packageFilePath = path . resolve ( __dirname , 'package.json' ) ;
98
-
99
95
// Create a mock package.json file
100
- const originalPackageData = fs . existsSync ( packageFilePath ) ? fs . readFileSync ( packageFilePath , 'utf-8' ) : null ;
96
+ const originalPackageData = fs . existsSync ( versionFilePath ) ? fs . readFileSync ( packageFilePath , 'utf-8' ) : null ;
101
97
const mockPackageData = JSON . stringify ( { version : '1.0.0' } ) ;
102
- fs . writeFileSync ( packageFilePath , mockPackageData ) ;
98
+ fs . writeFileSync ( versionFilePath , mockPackageData ) ;
103
99
104
100
setContext ( context , 'unit-test' ) ;
105
101
@@ -111,9 +107,9 @@ describe('Logger version handling', () => {
111
107
112
108
// Restore the original package.json file
113
109
if ( originalPackageData ) {
114
- fs . writeFileSync ( packageFilePath , originalPackageData ) ;
110
+ fs . writeFileSync ( versionFilePath , originalPackageData ) ;
115
111
} else {
116
- fs . unlinkSync ( packageFilePath ) ;
112
+ fs . unlinkSync ( versionFilePath ) ;
117
113
}
118
114
} ) ;
119
115
} ) ;
0 commit comments