File: run.js

package info (click to toggle)
node-cookie-jar 0.3.1-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 92 kB
  • sloc: javascript: 174; makefile: 2
file content (40 lines) | stat: -rw-r--r-- 880 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
var spawn = require('child_process').spawn
  , exitCode = 0
  , timeout = 10000
  , fs = require('fs')
  ;

fs.readdir(__dirname, function (e, files) {
  if (e) throw e

  var tests = files.filter(function (f) {return f.slice(0, 'test-'.length) === 'test-'})

  var next = function () {
    if (tests.length === 0) process.exit(exitCode);

    var file = tests.shift()
    console.log(file)
    var proc = spawn('node', [ 'tests/' + file ])

    var killed = false
    var t = setTimeout(function () {
      proc.kill()
      exitCode += 1
      console.error(file + ' timeout')
      killed = true
    }, timeout)

    proc.stdout.pipe(process.stdout)
    proc.stderr.pipe(process.stderr)
    proc.on('exit', function (code) {
      if (code && !killed) console.error(file + ' failed')
      exitCode += code || 0
      clearTimeout(t)
      next()
    })
  }
  next()
    
})