Skip to content

Commit

Permalink
Initial integration test
Browse files Browse the repository at this point in the history
tests the ability of roots to
* make a new project
* watch said project
* reload the brower with changes to said project
  • Loading branch information
samccone committed May 23, 2014
1 parent 2da59be commit 199ee6a
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 2 deletions.
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,12 @@
"roots-util": "0.0.4",
"chai-fs": "0.0.3",
"mockery": "1.4.x",
"coffeelint": "1.3.x"
"coffeelint": "1.3.x",
"dill": "^0.3.0"
},
"scripts": {
"test": "npm run lint && mocha",
"test": "npm run lint && mocha && npm run integration",
"integration": "dill test/features --require test/steps/ -f pretty --driver=phantomjs",
"lint": "find lib/ -name '*.coffee' | xargs coffeelint",
"coverage": "make build; istanbul cover _mocha --report html -- -R spec && open coverage/index.html && make unbuild",
"coveralls": "make build; istanbul cover _mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | coveralls && rm -rf ./coverage; make unbuild"
Expand Down
9 changes: 9 additions & 0 deletions test/features/live_reload.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Feature: Live reloading of the browser

Background:
Given I have a roots project
And I am watching it

Scenario: Reloading on file change
When I replace "views/index.jade" with "<h1><span>wow such magic</span></h1>"
Then I should a "h1" tag with "wow such magic"
10 changes: 10 additions & 0 deletions test/steps/editor.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
fs = require("fs")
Path = require("path")
rootPath = Path.resolve(__dirname, 'rage')

module.exports = ->
@When /^I replace "([^"]*)" with "([^"]*)"$/, (filePath, content) ->
fs.writeFileSync(Path.join(rootPath, filePath), content)

@Then /^I should a "([^"]*)" tag with "([^"]*)"$/, (tag, content) ->
new @Widget({root: tag}).read("span").should.eventually.eql(content)
42 changes: 42 additions & 0 deletions test/steps/util.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
Roots = require("../../")
When = require("when")
path = require("path").resolve(__dirname, 'rage')
rimraf = require("rimraf")
Server = require("../../lib/local_server")

on_error = (cli, server, err) -> server.show_error(Error(err).stack)
on_start = (cli, server) -> server.compiling()
on_done = (cli, server) -> server.reload()

module.exports = ->
@After ->
When.Promise (resolve) ->
rimraf path, ->
console.log arguments
resolve()

@Given /^I have a roots project$/, ->
Roots.new(
path: path
overrides:
name: "doge-hunter"
description: "data love geordi"
)

@Given /^I am watching it$/, ->
_this = this

When.Promise (resolve) ->
project = new Roots(path)
server = new Server(project, project.root)
watcher = project.watch()
cli = {}

server.start(1111)

watcher.on('start', on_start.bind(null, cli, server))
watcher.on('error', on_error.bind(null, cli, server))
watcher.on('done', on_done.bind(null, cli, server))

watcher.once 'done', ->
_this.driver.get("http://127.0.0.1:1111/").then -> resolve()

0 comments on commit 199ee6a

Please sign in to comment.