44'use strict' ;
55
66const fs = require ( 'fs' ) ;
7+ const path = require ( 'path' ) ;
78const chai = require ( 'chai' ) ;
89const sinon = require ( 'sinon' ) ;
910const sinonChai = require ( 'sinon-chai' ) ;
@@ -64,7 +65,7 @@ describe('removeNPMAbsolutePaths.js', function () {
6465 } ) ;
6566
6667 it ( 'fails if file path is invalid' , function ( ) {
67- const filePath = ` ${ __dirname } / FAKE_PATH/ module/ package.json` ;
68+ const filePath = path . join ( __dirname , ' FAKE_PATH' , ' module' , ' package.json' ) ;
6869 const promise = removeNPMAbsolutePaths ( filePath ) ;
6970 return expect ( promise ) . to . be . rejectedWith ( 'Can\'t read directory/file' )
7071 . then ( ( ) => {
@@ -76,7 +77,7 @@ describe('removeNPMAbsolutePaths.js', function () {
7677 } ) ;
7778
7879 it ( 'fails if file path is not package.json' , function ( ) {
79- const filePath = ` ${ __dirname } / data/ not_package_json/ module/ not_package.json` ;
80+ const filePath = path . join ( __dirname , ' data' , ' not_package_json' , ' module' , ' not_package.json' ) ;
8081 const promise = removeNPMAbsolutePaths ( filePath ) ;
8182 return expect ( promise ) . to . be . rejectedWith ( 'Invalid path provided' )
8283 . then ( ( ) => {
@@ -88,7 +89,7 @@ describe('removeNPMAbsolutePaths.js', function () {
8889 } ) ;
8990
9091 it ( 'fails if directory path is invalid' , function ( ) {
91- const dirPath = ` ${ __dirname } / FAKE_PATH` ;
92+ const dirPath = path . join ( __dirname , ' FAKE_PATH' ) ;
9293 const promise = removeNPMAbsolutePaths ( dirPath ) ;
9394 return expect ( promise ) . to . be . rejectedWith ( 'Can\'t read directory/file' )
9495 . then ( ( ) => {
@@ -100,8 +101,8 @@ describe('removeNPMAbsolutePaths.js', function () {
100101 } ) ;
101102
102103 it ( 'do nothing directory path doesn\'t contain package.json' , function ( ) {
103- const dirPath = ` ${ __dirname } / data/ not_package_json` ;
104- const filePath = ` ${ dirPath } / module/ package.json` ;
104+ const dirPath = path . join ( __dirname , ' data' , ' not_package_json' ) ;
105+ const filePath = path . join ( dirPath , ' module' , ' package.json' ) ;
105106 const promise = removeNPMAbsolutePaths ( dirPath ) ;
106107 return expect ( promise ) . be . fulfilled
107108 . then ( ( results ) => {
@@ -117,8 +118,8 @@ describe('removeNPMAbsolutePaths.js', function () {
117118
118119 describe ( 'directory path' , function ( ) {
119120 it ( 'return error on malformed files if file is malformed' , function ( ) {
120- const dirPath = ` ${ __dirname } / data/ malformed` ;
121- const filePath = ` ${ dirPath } / module/ package.json` ;
121+ const dirPath = path . join ( __dirname , ' data' , ' malformed' ) ;
122+ const filePath = path . join ( dirPath , ' module' , ' package.json' ) ;
122123 const promise = removeNPMAbsolutePaths ( dirPath ) ;
123124 return expect ( promise ) . be . fulfilled
124125 . then ( ( results ) => {
@@ -137,8 +138,8 @@ describe('removeNPMAbsolutePaths.js', function () {
137138 } ) ;
138139
139140 it ( 'rewrite pacakge.json if contains _fields' , function ( ) {
140- const dirPath = ` ${ __dirname } / data/ underscore_fields` ;
141- const filePath = ` ${ dirPath } / module/ package.json` ;
141+ const dirPath = path . join ( __dirname , ' data' , ' underscore_fields' ) ;
142+ const filePath = path . join ( dirPath , ' module' , ' package.json' ) ;
142143 const promise = removeNPMAbsolutePaths ( dirPath ) ;
143144 return expect ( promise ) . be . fulfilled
144145 . then ( ( results ) => {
@@ -157,8 +158,8 @@ describe('removeNPMAbsolutePaths.js', function () {
157158
158159 describe ( 'force' , function ( ) {
159160 it ( 'doesn\'t rewrite pacakge.json if doesn\'t contain _fields and force option isn\'t passed' , function ( ) {
160- const dirPath = ` ${ __dirname } / data/ no_underscore_fields` ;
161- const filePath = ` ${ dirPath } / module/ package.json` ;
161+ const dirPath = path . join ( __dirname , ' data' , ' no_underscore_fields' ) ;
162+ const filePath = path . join ( dirPath , ' module' , ' package.json' ) ;
162163 const promise = removeNPMAbsolutePaths ( dirPath ) ;
163164 return expect ( promise ) . be . fulfilled
164165 . then ( ( results ) => {
@@ -174,8 +175,8 @@ describe('removeNPMAbsolutePaths.js', function () {
174175 } ) ;
175176
176177 it ( 'rewrite pacakge.json if doesn\'t contain _fields and force option is passed' , function ( ) {
177- const dirPath = ` ${ __dirname } / data/ no_underscore_fields` ;
178- const filePath = ` ${ dirPath } / module/ package.json` ;
178+ const dirPath = path . join ( __dirname , ' data' , ' no_underscore_fields' ) ;
179+ const filePath = path . join ( dirPath , ' module' , ' package.json' ) ;
179180 const promise = removeNPMAbsolutePaths ( dirPath , { force : true } ) ;
180181 return expect ( promise ) . be . fulfilled
181182 . then ( ( results ) => {
@@ -193,7 +194,7 @@ describe('removeNPMAbsolutePaths.js', function () {
193194
194195 describe ( 'fields' , function ( ) {
195196 it ( 'return error if fields option is passed but is not an array' , function ( ) {
196- const dirPath = ` ${ __dirname } / data/ underscore_fields` ;
197+ const dirPath = path . join ( __dirname , ' data' , ' underscore_fields' ) ;
197198 const opts = {
198199 fields : 'string_value' ,
199200 } ;
@@ -208,7 +209,7 @@ describe('removeNPMAbsolutePaths.js', function () {
208209 } ) ;
209210
210211 it ( 'return error if fields option is passed but is empty' , function ( ) {
211- const dirPath = ` ${ __dirname } / data/ underscore_fields` ;
212+ const dirPath = path . join ( __dirname , ' data' , ' underscore_fields' ) ;
212213 const opts = {
213214 fields : [ ] ,
214215 } ;
@@ -223,8 +224,8 @@ describe('removeNPMAbsolutePaths.js', function () {
223224 } ) ;
224225
225226 it ( 'rewrite only user-specified fields in package.json if fields option is passed' , function ( ) {
226- const dirPath = ` ${ __dirname } / data/ underscore_fields` ;
227- const filePath = ` ${ dirPath } / module/ package.json` ;
227+ const dirPath = path . join ( __dirname , ' data' , ' underscore_fields' ) ;
228+ const filePath = path . join ( dirPath , ' module' , ' package.json' ) ;
228229 const opts = {
229230 fields : [ '_inBundle' , '_where' ] ,
230231 } ;
@@ -251,7 +252,7 @@ describe('removeNPMAbsolutePaths.js', function () {
251252
252253 describe ( 'file path' , function ( ) {
253254 it ( 'return error on malformed files if file is malformed' , function ( ) {
254- const filePath = ` ${ __dirname } / data/ malformed/ module/ package.json` ;
255+ const filePath = path . join ( __dirname , ' data' , ' malformed' , ' module' , ' package.json' ) ;
255256 const promise = removeNPMAbsolutePaths ( filePath ) ;
256257 return expect ( promise ) . be . fulfilled
257258 . then ( ( results ) => {
@@ -270,7 +271,7 @@ describe('removeNPMAbsolutePaths.js', function () {
270271 } ) ;
271272
272273 it ( 'rewrite file if contains _fields' , function ( ) {
273- const filePath = ` ${ __dirname } / data/ underscore_fields/ module/ package.json` ;
274+ const filePath = path . join ( __dirname , ' data' , ' underscore_fields' , ' module' , ' package.json' ) ;
274275 const promise = removeNPMAbsolutePaths ( filePath ) ;
275276 return expect ( promise ) . be . fulfilled
276277 . then ( ( results ) => {
@@ -289,7 +290,7 @@ describe('removeNPMAbsolutePaths.js', function () {
289290
290291 describe ( 'force' , function ( ) {
291292 it ( 'doesn\'t rewrite file if doesn\'t contain _fields and force option isn\'t passed' , function ( ) {
292- const filePath = ` ${ __dirname } / data/ no_underscore_fields/ module/ package.json` ;
293+ const filePath = path . join ( __dirname , ' data' , ' no_underscore_fields' , ' module' , ' package.json' ) ;
293294 const promise = removeNPMAbsolutePaths ( filePath ) ;
294295 return expect ( promise ) . be . fulfilled
295296 . then ( ( results ) => {
@@ -305,7 +306,7 @@ describe('removeNPMAbsolutePaths.js', function () {
305306 } ) ;
306307
307308 it ( 'rewrite file if doesn\'t contain _fields and force option is passed' , function ( ) {
308- const filePath = ` ${ __dirname } / data/ no_underscore_fields/ module/ package.json` ;
309+ const filePath = path . join ( __dirname , ' data' , ' no_underscore_fields' , ' module' , ' package.json' ) ;
309310 const promise = removeNPMAbsolutePaths ( filePath , { force : true } ) ;
310311 return expect ( promise ) . be . fulfilled
311312 . then ( ( results ) => {
@@ -323,7 +324,7 @@ describe('removeNPMAbsolutePaths.js', function () {
323324
324325 describe ( 'fields' , function ( ) {
325326 it ( 'return error if fields option is passed but is not an array' , function ( ) {
326- const filePath = ` ${ __dirname } / data/ underscore_fields/ module/ package.json` ;
327+ const filePath = path . join ( __dirname , ' data' , ' underscore_fields' , ' module' , ' package.json' ) ;
327328 const opts = {
328329 fields : 'string_value' ,
329330 } ;
@@ -338,7 +339,7 @@ describe('removeNPMAbsolutePaths.js', function () {
338339 } ) ;
339340
340341 it ( 'return error if fields option is passed but is empty' , function ( ) {
341- const filePath = ` ${ __dirname } / data/ underscore_fields/ module/ package.json` ;
342+ const filePath = path . join ( __dirname , ' data' , ' underscore_fields' , ' module' , ' package.json' ) ;
342343 const opts = {
343344 fields : [ ] ,
344345 } ;
@@ -353,7 +354,7 @@ describe('removeNPMAbsolutePaths.js', function () {
353354 } ) ;
354355
355356 it ( 'rewrite only user-specified fields in package.json if fields option is passed' , function ( ) {
356- const filePath = ` ${ __dirname } / data/ underscore_fields/ module/ package.json` ;
357+ const filePath = path . join ( __dirname , ' data' , ' underscore_fields' , ' module' , ' package.json' ) ;
357358 const opts = {
358359 fields : [ '_inBundle' , '_where' ] ,
359360 } ;
@@ -412,7 +413,7 @@ describe('removeNPMAbsolutePaths.js', function () {
412413 const err = new Error ( 'Can\'t read directory.' ) ;
413414 readdir . yields ( err ) ;
414415 clearCachedModuleSoNewMocksWork ( ) ;
415- const dirPath = ` ${ __dirname } / data/ underscore_fields` ;
416+ const dirPath = path . join ( __dirname , ' data' , ' underscore_fields' ) ;
416417 const promise = removeNPMAbsolutePaths ( dirPath ) ;
417418 return expect ( promise ) . be . fulfilled
418419 . then ( ( results ) => {
@@ -462,7 +463,7 @@ describe('removeNPMAbsolutePaths.js', function () {
462463 const err = new Error ( 'Can\'t read file.' ) ;
463464 readFile . yields ( err ) ;
464465 clearCachedModuleSoNewMocksWork ( ) ;
465- const filePath = ` ${ __dirname } / data/ underscore_fields/ module/ package.json` ;
466+ const filePath = path . join ( __dirname , ' data' , ' underscore_fields' , ' module' , ' package.json' ) ;
466467 const promise = removeNPMAbsolutePaths ( filePath ) ;
467468 return expect ( promise ) . be . fulfilled
468469 . then ( ( results ) => {
@@ -512,7 +513,7 @@ describe('removeNPMAbsolutePaths.js', function () {
512513 const err = new Error ( 'Can\'t write to file.' ) ;
513514 writeFile . yields ( err ) ;
514515 clearCachedModuleSoNewMocksWork ( ) ;
515- const filePath = ` ${ __dirname } / data/ underscore_fields/ module/ package.json` ;
516+ const filePath = path . join ( __dirname , ' data' , ' underscore_fields' , ' module' , ' package.json' ) ;
516517 const promise = removeNPMAbsolutePaths ( filePath ) ;
517518 return expect ( promise ) . be . fulfilled
518519 . then ( ( results ) => {
0 commit comments