Skip to content
This repository was archived by the owner on Sep 22, 2020. It is now read-only.

Commit d4f7040

Browse files
committed
Removed bin/test in favor of starting services on a per-test level directly in node
1 parent a0302f1 commit d4f7040

File tree

6 files changed

+89
-33
lines changed

6 files changed

+89
-33
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ node_js:
55
sudo: false
66
script:
77
- "npm run lint"
8-
- "bin/test"
8+
- "npm test"
99
services:
1010
- docker

bin/test

Lines changed: 0 additions & 29 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"scripts": {
3939
"prepublish": "bin/build",
4040
"lint": "eslint src",
41-
"test": "bin/test --verbose"
41+
"test": "ava --verbose"
4242
},
4343
"ava": {
4444
"require": [

test/BeanstalkDriver.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,19 @@ import { serial as test } from 'ava'
22

33
import './helpers/TestJob'
44
import './helpers/Listener'
5+
import './helpers/Service'
6+
57
import '../src/Drivers/BeanstalkDriver'
68

9+
const service = new Service(test, 'beanstalk', {
10+
image: 'kusmierz/beanstalkd',
11+
port: 11300
12+
})
13+
714
test.beforeEach(t => {
815
t.context.driver = new BeanstalkDriver(null, {
916
host: 'localhost',
10-
port: process.env.BEANSTALK_PORT
17+
port: service.port
1118
})
1219

1320
return t.context.driver.connect()

test/RabbitDriver.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,19 @@ import { serial as test } from 'ava'
22

33
import './helpers/TestJob'
44
import './helpers/Listener'
5+
import './helpers/Service'
6+
57
import '../src/Drivers/RabbitDriver'
68

9+
const service = new Service(test, 'rabbitmq', {
10+
image: 'rabbitmq:3.7-alpine',
11+
port: 5672
12+
})
13+
714
test.beforeEach(t => {
815
t.context.driver = new RabbitDriver(null, {
916
host: 'localhost',
10-
port: process.env.RABBIT_PORT
17+
port: service.port
1118
})
1219

1320
return t.context.driver.connect()

test/helpers/Service.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
const { promisify } = require('util')
2+
const execFile = promisify(require('child_process').execFile)
3+
4+
export class Service {
5+
6+
constructor(test, service, { image, port }) {
7+
this.service = service
8+
this.config = {
9+
image,
10+
port: {
11+
host: 43210 + port,
12+
container: port
13+
}
14+
}
15+
16+
test.before(() => this.start())
17+
test.after.always(() => this.stop())
18+
}
19+
20+
get port() {
21+
return this.config.port.host
22+
}
23+
24+
async start() {
25+
Log.comment(`${this.service} starting`)
26+
const { image, port: { host, container } } = this.config
27+
28+
// Clean up old containers
29+
await this.exec('rm', '--force', this._container, this._containerWait).catch(() => { })
30+
31+
// Start the container
32+
await this.exec(
33+
'run',
34+
`--name=${this._container}`,
35+
'-d',
36+
'-p', `${host}:${container}`,
37+
image
38+
)
39+
40+
// Wait for the container to become avaiable
41+
Log.comment(`${this.service} waiting`)
42+
await this.exec(
43+
'run',
44+
'--rm',
45+
`--name=${this._containerWait}`,
46+
`--link=grind-${this.service}:${this.service}`,
47+
'dadarek/wait-for-dependencies',
48+
`${this.service}:${container}`
49+
)
50+
Log.comment(`${this.service} started`)
51+
}
52+
53+
async stop() {
54+
Log.comment(`${this.service} stopping`)
55+
await this.exec('stop', this._container).catch(() => { })
56+
await this.exec('rm', this._container).catch(() => { })
57+
}
58+
59+
get _container() {
60+
return `grind-${this.service}`
61+
}
62+
63+
get _containerWait() {
64+
return `grind-wait-for-${this.service}`
65+
}
66+
67+
exec(...args) {
68+
return execFile('docker', args)
69+
}
70+
71+
}

0 commit comments

Comments
 (0)