Git Product home page Git Product logo

cucumbers-on-vine-hill's Introduction

Cucumbers on Vine Hill

Everyone's invited to my party:

Here's how they mingle:

Feature: Weather Forecast

  Scenario: Forecast for a city
    Given I am using the weather app
    When I open the forecast for London
    Then it should predict rain again
const cucumber = require('cucumber')
const hyperdom = require('hyperdom')
const vineHill = require('vinehill')
const browserMonkey = require('browser-monkey')
const Client = require('../../app/client')
const server = require('../../app/server')

const weatherUrl = 'http://weather.com'

cucumber.defineSupportCode(function ({ Given, When, Then }) {
  Given('I am using the weather app', function () {
    vineHill({ [weatherUrl]: server })
    hyperdom.append(document.body, new Client(weatherUrl))
    this.monkey = browserMonkey.component(document.body)
  })

  When('I open the forecast for London', function () {
    return this.monkey.click('Forecast for London')
  })

  Then('it should predict rain again', function () {
    return this.monkey.shouldFind('h1', { text: 'Rainy!' })
  })
})
const hyperdom = require('hyperdom')
const httpism = require('httpism/browser')
const html = hyperdom.html

module.exports = class WeatherAppClient {
  constructor(serverUrl) {
    this.api = httpism.client(serverUrl)
  }

  render() {
    return this.forecast ? this.renderForecast() : this.renderMenu()
  }

  renderMenu(model) {
    return html('button', { onclick: () => this.fetchForecast('london') },
      'Forecast for London')
  }

  fetchForecast(city) {
    return this.api.get('/cities/' + city)
      .then(weather => { this.forecast = weather.forecast })
  }

  renderForecast() {
    return html('h1', this.forecast)
  }
}
const path = require('path')
const express = require('express')
const app = express()

app.get('/cities/:city', (req, res) => {
  res.json({ forecast: 'Rainy!' })
})

app.use(express.static(path.join(__dirname, 'public')))

module.exports = app

Testing and developing

Install it:

npm install

Then you can run cucumber-electron with:

./cucumber

Or debug it in a browser window:

./cucumber --electron-debug

Hit cmd+r to re-run scenarios

Running the app in a browser

Run the server:

npm start

And point your browser at:

http://localhost:3001

cucumbers-on-vine-hill's People

Contributors

joshski avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

aslakhellesoy

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.