Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. args = require('minimist')(process.argv.slice(2))
  2. fs = require 'fs'
  3. path = require 'path'
  4. async = require 'async'
  5. clientInclude = require('../server/test-utils/client-include.coffee')()
  6.  
  7. TEST_FILES = args._
  8.  
  9. loadWidget = (widgetType) ->
  10.     widgetType = widgetType.replace /_sample\.json/, ""
  11.     widgetType = widgetType.replace /_\d+\.json/, ""
  12.     clientInclude.load "widgets/#{widgetType}.coffee"
  13.  
  14. getFilePath = (file) ->
  15.     path.resolve __dirname, "../client/tests/widget-fixtures/#{file}"
  16.  
  17. loadAndParseFile = (filename) ->
  18.     testFile = fs.readFileSync getFilePath(filename), "UTF-8"
  19.     try
  20.         return JSON.parse testFile
  21.     catch e
  22.         console.error "Unable to parse #{file}\nExiting with 1."
  23.         process.exit 1
  24.  
  25. saveToFile = (path, content, next) ->
  26.     fs.writeFile path, content, (err) ->
  27.         return next err if err
  28.         console.log "Updated #{path}"
  29.         return next null
  30.  
  31. fileRoutine = (file, next) ->
  32.     testObject = loadAndParseFile file
  33.     widget = loadWidget testObject.type
  34.     responseReducer = widget.createResponseReducer testObject.config, testObject.sharedConfig
  35.     response = responseReducer testObject.reducerIn.map (data) -> {data}
  36.     testObject.reducerOut = response
  37.     saveToFile getFilePath(file), JSON.stringify(testObject, null, "\t"), next
  38.  
  39.  
  40. async.eachLimit TEST_FILES, 10, fileRoutine, (err) ->
  41.     console.error "Unable to complete operation:", err if err
  42.     console.log "Done!"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement