Skip to content

Commit

Permalink
Bundle auto rename if present
Browse files Browse the repository at this point in the history
  • Loading branch information
LakshSingla committed Jul 17, 2019
1 parent 03fde30 commit a369873
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions test/mocha/lib/mockUpdater.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
nock = require 'nock'
path = require 'path'
fs = require 'fs'

UPDATE_ENV_VAR = "IMJS_TESTS_UPDATE"
BUNDLES_FOLDER = path.join __dirname, 'bundledResponses'

shouldUpdate = ->
process.env[UPDATE_ENV_VAR] is "TRUE"

startUpdater = ->
if not shouldUpdate()
return

nock.recorder.recorder
output_objects: true

stopUpdater = (bundleName) ->
if not shouldUpdate()
return

fullPath = path.join BUNDLES_FOLDER, bundleName
console.log fullPath

if fs.existsSync fullPath
newPath = path.join BUNDLES_FOLDER, '.bak.' + bundleName
try
console.log "Bundle already existing. Renaming original #{bundleName} to .bak.#{bundleName}"
fs.renameSync fullPath, newPath
catch e then console.log "Unable to rename #{bundleName} to .bak.#{bundleName}"


module.exports =
startUpdater: startUpdater
stopUpdater: stopUpdater

0 comments on commit a369873

Please sign in to comment.