Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- args = require('minimist')(process.argv.slice(2))
- fs = require 'fs'
- path = require 'path'
- async = require 'async'
- clientInclude = require('../server/test-utils/client-include.coffee')()
- TEST_FILES = args._
- loadWidget = (widgetType) ->
- widgetType = widgetType.replace /_sample\.json/, ""
- widgetType = widgetType.replace /_\d+\.json/, ""
- clientInclude.load "widgets/#{widgetType}.coffee"
- getFilePath = (file) ->
- path.resolve __dirname, "../client/tests/widget-fixtures/#{file}"
- loadAndParseFile = (filename) ->
- testFile = fs.readFileSync getFilePath(filename), "UTF-8"
- try
- return JSON.parse testFile
- catch e
- console.error "Unable to parse #{file}\nExiting with 1."
- process.exit 1
- saveToFile = (path, content, next) ->
- fs.writeFile path, content, (err) ->
- return next err if err
- console.log "Updated #{path}"
- return next null
- fileRoutine = (file, next) ->
- testObject = loadAndParseFile file
- widget = loadWidget testObject.type
- responseReducer = widget.createResponseReducer testObject.config, testObject.sharedConfig
- response = responseReducer testObject.reducerIn.map (data) -> {data}
- testObject.reducerOut = response
- saveToFile getFilePath(file), JSON.stringify(testObject, null, "\t"), next
- async.eachLimit TEST_FILES, 10, fileRoutine, (err) ->
- console.error "Unable to complete operation:", err if err
- console.log "Done!"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement