Skip to content
This repository has been archived by the owner on Mar 18, 2021. It is now read-only.

Commit

Permalink
Properly interrup the currently running test
Browse files Browse the repository at this point in the history
closes #27
resolves #26
  • Loading branch information
kevgo committed Aug 21, 2016
1 parent 96b4c85 commit ea1036e
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 11 deletions.
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- update "repeatLastTest" command to new format
- compatibility with Node 4 in addition to 5 and 6
- terminates the currently running test before starting a new one


## 0.0.7
Expand Down
4 changes: 4 additions & 0 deletions example-applications/long-running-tests/bin/run-long-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env node

require('http').createServer( (req, res) => { res.end('hello world\n') } )
.listen(3000, '127.0.0.1', () => { console.log('Server running') })
4 changes: 4 additions & 0 deletions example-applications/long-running-tests/bin/run-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

echo "Testing $1"
echo "done testing $1"
8 changes: 8 additions & 0 deletions example-applications/long-running-tests/tertestrial.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
actions:

- match:
command: 'bin/run-long-test'

- match:
filename: 'foo'
command: 'bin/run-test foo'
23 changes: 23 additions & 0 deletions features/immediate-start.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Feature: tests start immediately

As a developer kicking off a test
I want that it starts right away without waiting for the current test to finish
So that I don't get slowed down by currently running tests I no longer need.

- when Tertestrial receives the signal to run a test,
it terminates the currently running test and starts the new one right away


Scenario: Tertestrial receives a test command while another test is still running
Given Tertestrial is running inside the "long-running-tests" example application
When sending the command:
"""
{}
"""
Then the long-running test is running
When sending the command:
"""
{"filename": "foo"}
"""
Then the long-running test is no longer running
And I see "Testing foo"
16 changes: 16 additions & 0 deletions features/steps/steps.ls
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ require! {
'chai' : {expect}
'fs'
'path'
'request'
'wait' : {wait, wait-until}
'wait-until' : wait-until-async
}


Expand Down Expand Up @@ -75,6 +77,7 @@ module.exports = ->
@create-file 'tertestrial.yml', configuration



@Then /^I see "([^"]*)"$/ (expected-text, done) ->
@process.wait expected-text, done

Expand All @@ -87,6 +90,19 @@ module.exports = ->
@file-exists filename


@Then /^the long-running test is (no longer )?running$/ (!expect-running, done) ->
checker = (cb) ->
request 'http://localhost:3000', (err) ->
if expect-running
cb err
else
cb !err

wait-until-async!.condition checker
.interval 10
.times 100
.done -> done!

@Then /^the process ends$/ (done) ->
wait-until (~> @process.ended), done

Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
"o-tools": "0.5.1",
"o-tools-livescript": "1.1.2",
"observable-process": "3.1.0",
"rimraf": "2.5.4"
"request": "2.74.0",
"rimraf": "2.5.4",
"wait-until": "0.0.2"
},
"engines": {
"npm": ">= 3.0.0"
Expand Down
37 changes: 27 additions & 10 deletions src/command-runner.ls
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,34 @@ class CommandRunner
# the last test command that was sent from the editor
@current-command = ''

# the currently running test process
@current-process = null

run-command: (command) ~>

run-command: (command, done) ~>
reset-terminal!

if command.action-set
@set-actionset command.action-set
@re-run-last-test command if @current-command
if @current-command
@re-run-last-test done
else
done?!
return

if command.repeat-last-test
if @current-command?.length is 0 then return error "No previous test run"
return @re-run-last-test command
@re-run-last-test done
return

unless template = @_get-template(command) then return error "no matching action found for #{JSON.stringify command}"
@current-command = command
@_run-test fill-template(template, command)
@_run-test fill-template(template, command), done


re-run-last-test: (command) ->
unless template = @_get-template(@current-command) then return error "cannot find a template for '#{command}'"
@_run-test fill-template(template, @current-command)
re-run-last-test: (done) ->
unless template = @_get-template(@current-command) then return error "cannot find a template for '#{@current-command}'"
@_run-test fill-template(template, @current-command), done


set-actionset: (@current-action-set-id) ->
Expand Down Expand Up @@ -111,10 +118,20 @@ class CommandRunner
Object.keys(command).length > 0


_run-test: (command) ->
console.log bold "#{command}\n"
spawn 'sh' ['-c', command], stdio: 'inherit'
_run-test: (command, done) ->
@_stop-running-test ~>
console.log bold "#{command}\n"
@current-process = spawn 'sh' ['-c', command], stdio: 'inherit'
done?!


_stop-running-test: (done) ->
| !@current-process => return done!
| @current-process?.exit-code? => return done!
| @current-process?.killed => return done!
@current-process
..on 'exit', -> done!
..kill!


module.exports = CommandRunner

0 comments on commit ea1036e

Please sign in to comment.