How to use stf-syrup - 10 common examples

To help you get started, we’ve selected a few stf-syrup examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github openstf / stf / lib / units / device / plugins / store.js View on Github external
var syrup = require('stf-syrup')

var logger = require('../../../util/logger')
var wire = require('../../../wire')
var wireutil = require('../../../wire/util')

module.exports = syrup.serial()
  .dependency(require('../support/router'))
  .dependency(require('../support/push'))
  .dependency(require('../support/adb'))
  .define(function(options, router, push, adb) {
    var log = logger.createLogger('device:plugins:store')

    router.on(wire.StoreOpenMessage, function(channel) {
      log.info('Opening Play Store')

      var reply = wireutil.reply(options.serial)
      adb.startActivity(options.serial, {
          action: 'android.intent.action.MAIN'
        , component: 'com.android.vending/.AssetBrowserActivity'
          // FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
          // FLAG_ACTIVITY_BROUGHT_TO_FRONT
          // FLAG_ACTIVITY_NEW_TASK
github openstf / stf / lib / units / device / support / push.js View on Github external
var syrup = require('stf-syrup')

var Promise = require('bluebird')

var logger = require('../../../util/logger')
var srv = require('../../../util/srv')
var zmqutil = require('../../../util/zmqutil')

module.exports = syrup.serial()
  .define(function(options) {
    var log = logger.createLogger('device:support:push')

    // Output
    var push = zmqutil.socket('push')

    return Promise.map(options.endpoints.push, function(endpoint) {
        return srv.resolve(endpoint).then(function(records) {
          return srv.attempt(records, function(record) {
            log.info('Sending output to "%s"', record.url)
            push.connect(record.url)
            return Promise.resolve(true)
          })
        })
      })
      .return(push)
github openstf / stf / lib / units / device / support / sub.js View on Github external
var syrup = require('stf-syrup')

var zmq = require('zmq')
var Promise = require('bluebird')

var logger = require('../../../util/logger')
var wireutil = require('../../../wire/util')
var srv = require('../../../util/srv')
var lifecycle = require('../../../util/lifecycle')

module.exports = syrup.serial()
  .define(function(options) {
    var log = logger.createLogger('device:support:sub')

    // Input
    var sub = zmq.socket('sub')

    return Promise.map(options.endpoints.sub, function(endpoint) {
        return srv.resolve(endpoint).then(function(records) {
          return srv.attempt(records, function(record) {
            log.info('Receiving input from "%s"', record.url)
            sub.connect(record.url)
            return Promise.resolve(true)
          })
        })
      })
      .then(function() {
github openstf / stf / lib / units / device / plugins / screenshot.js View on Github external
var http = require('http')
var util = require('util')

var syrup = require('stf-syrup')
var Promise = require('bluebird')

var logger = require('../../../util/logger')
var wire = require('../../../wire')
var wireutil = require('../../../wire/util')

module.exports = syrup.serial()
  .dependency(require('../support/router'))
  .dependency(require('../support/push'))
  .dependency(require('../support/storage'))
  .dependency(require('./display'))
  .define(function(options, router, push, storage, display) {
    var log = logger.createLogger('device:plugins:screenshot')
    var plugin = Object.create(null)

    plugin.capture = function() {
      log.info('Capturing screenshot from %s', display.url)

      return new Promise(function(resolve, reject) {
        var req = http.get(display.url)

        function responseListener(res) {
          if (res.statusCode !== 200) {
github openstf / stf / lib / units / device / plugins / cleanup.js View on Github external
var syrup = require('stf-syrup')
var Promise = require('bluebird')
var _ = require('lodash')

var logger = require('../../../util/logger')

module.exports = syrup.serial()
  .dependency(require('../support/adb'))
  .dependency(require('../resources/service'))
  .dependency(require('./group'))
  .define(function(options, adb, service, group) {
    var log = logger.createLogger('device:plugins:cleanup')
    var plugin = Object.create(null)

    function listPackages() {
      return adb.getPackages(options.serial)
    }

    function uninstallPackage(pkg) {
      log.info('Cleaning up package "%s"', pkg)
      return adb.uninstall(options.serial, pkg)
        .catch(function(err) {
          log.warn('Unable to clean up package "%s"', pkg, err)
github openstf / stf / lib / units / device / plugins / util / data.js View on Github external
var syrup = require('stf-syrup')
var deviceData = require('stf-device-db')

var logger = require('../../../../util/logger')

module.exports = syrup.serial()
  .dependency(require('./identity'))
  .define(function(options, identity) {
    var log = logger.createLogger('device:plugins:data')

    function find() {
      var data = deviceData.find(identity)
      if (!data) {
        log.warn('Unable to find device data', identity)
      }
      return data
    }

    return find()
  })
github openstf / stf / lib / units / device / plugins / util / identity.js View on Github external
var syrup = require('stf-syrup')

var devutil = require('../../../../util/devutil')
var logger = require('../../../../util/logger')

module.exports = syrup.serial()
  .dependency(require('../../support/properties'))
  .dependency(require('./display'))
  .dependency(require('./phone'))
  .define(function(options, properties, display, phone) {
    var log = logger.createLogger('device:plugins:identity')

    function solve() {
      log.info('Solving identity')
      var identity = devutil.makeIdentity(options.serial, properties)
      identity.display = display.properties
      identity.phone = phone
      return identity
    }

    return solve()
  })
github openstf / stf / lib / units / device / support / adb.js View on Github external
var syrup = require('stf-syrup')

var adbkit = require('adbkit')

var logger = require('../../../util/logger')
var promiseutil = require('../../../util/promiseutil')

module.exports = syrup.serial()
  .define(function(options) {
    var log = logger.createLogger('device:support:adb')
    var adb = adbkit.createClient({
      host: options.adbHost
    , port: options.adbPort
    })
    adb.Keycode = adbkit.Keycode

    function ensureBootComplete() {
      return promiseutil.periodicNotify(
          adb.waitBootComplete(options.serial)
        , 1000
        )
        .progressed(function() {
          log.info('Waiting for boot to complete')
        })
github openstf / stf / lib / units / device / support / http.js View on Github external
var http = require('http')
var util = require('util')

var syrup = require('stf-syrup')
var express = require('express')

var logger = require('../../../util/logger')

module.exports = syrup.serial()
  .define(function(options) {
    var log = logger.createLogger('device:support:http')
      , port = options.ports.pop()
      , app = express()
      , server = http.createServer(app)

    app.set('strict routing', true)
    app.set('case sensitive routing', true)
    app.set('public url', util.format(
      'http://%s:%s'
    , options.publicIp
    , port
    ))

    server.listen(port)
github openstf / stf / lib / units / device / plugins / screen / options.js View on Github external
var syrup = require('stf-syrup')
var _ = require('lodash')

module.exports = syrup.serial()
  .define(function(options) {
    var plugin = Object.create(null)

    plugin.devicePort = 9002
    plugin.publicPort = options.screenPort
    plugin.publicUrl = _.template(options.screenWsUrlPattern)({
      publicIp: options.publicIp
    , publicPort: plugin.publicPort
    , serial: options.serial
    })

    return plugin
  })

stf-syrup

Promise-based, configuration-less dependency injection.

Apache-2.0
Latest version published 9 years ago

Package Health Score

39 / 100
Full package analysis

Popular stf-syrup functions