Permalink
Browse files

chore(dogfood): use devlab to test devlab, fix/cleanup tests

  • Loading branch information...
Fluidbyte committed May 26, 2017
1 parent b783842 commit 692a817811976a48c3b0d998b8525eeee9f6c834
Showing with 73 additions and 45 deletions.
  1. +4 −2 .travis.yml
  2. +5 −1 README.md
  3. +18 −0 devlab.yml
  4. +3 −2 package.json
  5. +1 −0 src/index.js
  6. +4 −1 src/services.js
  7. +3 −0 src/utils.js
  8. +8 −21 test/src/args.spec.js
  9. +12 −4 test/src/config.spec.js
  10. +0 −2 test/src/index.spec.js
  11. +2 −1 test/src/tempdir.spec.js
  12. +12 −0 test/src/utils.spec.js
  13. +1 −11 yarn.lock
View
@@ -15,14 +15,16 @@ notifications:
before_install:
- sudo apt-get update > /dev/null
- sudo apt-get -y -o Dpkg::Options::="--force-confnew" install docker-engine=17.04.0~ce-0~ubuntu-trusty > /dev/null
- yarn add global devlab
install:
- yarn install
- devlab install
script:
- yarn test
- devlab test
after_success:
- sudo chmod -R 777 node_modules/ && sudo chmod -R 777 ~/.npm
- yarn global add codecov
- codecov -f coverage/lcov.info
View
@@ -260,7 +260,11 @@ If running `docker run -d --rm <container>` causes this error the `--rm` flag ca
### Tests
To run tests, fork & clone the repository then run `yarn install && yarn test`.
Devlab can be run via `yarn`/`npm` scripts, but is also setup to run development tasks using Devlab.
Ensure you have the latest version installed then run:
`devlab install test` or `yarn install && yarn test`.
### End-to-End Tests
View
@@ -0,0 +1,18 @@
from: technologyadvice/devlab
env:
- TMP=/tmp
volumes:
- /var/run/docker.sock:/var/run/docker.sock
tasks:
install: yarn install
test: yarn test
test:cover: yarn run test:cover
test:watch: yarn run test:watch
e2e: yarn run e2e
lint: yarn run lint
build: yarn run build
build:mac: yarn run build:mac
build:linux: yarn run build:linux
build:windows: yarn run build:windows
env: env | sort
shell: /bin/sh
View
@@ -26,9 +26,9 @@
},
"preferGlobal": true,
"scripts": {
"test": "npm run lint && npm run test:cover",
"test": "npm run lint -s && npm run test:cover -s",
"test:cover": "istanbul cover _mocha test/src/**/*.spec.js",
"test:watch": "nodemon --exec \"npm run test:cover || exit 1\"",
"test:watch": "nodemon --exec \"npm run test:cover -s || exit 1\"",
"e2e": "node test/system/run.js",
"lint": "standard --fix --verbose | snazzy",
"build": "npm run build:mac && npm run build:linux && npm run build:windows",
@@ -59,6 +59,7 @@
"nodemon": "^1.11.0",
"pkg": "^3.0.4",
"proxyquire": "^1.7.11",
"rimraf": "^2.6.1",
"sinon": "^1.17.0",
"sinon-chai": "^2.8.0",
"snazzy": "^6.0.0",
View
@@ -21,6 +21,7 @@ global.instanceId = require('shortid').generate()
const instance = {
checkForUpdates: () => {
const notifier = updateNotifier({ pkg })
/* istanbul ignore else: don't need to test that it wasn't called */
if (notifier.update) output.warn(`Update available: ${notifier.update.latest}`)
},
/**
View
@@ -107,7 +107,10 @@ const services = {
_.filter(svc => _.test(/dl_/, svc.name)),
_.map(svc => proc.run(['stop', '-t', svc.stopTimeSecs, svc.name], true)
.then(() => cfg.rmOnShutdown ? proc.run(['rm', svc.name], true) : Promise.resolve())
.catch(() => errors.push(svc.name))
.catch(() => {
/* istanbul ignore next: difficult to make a container shutdown fail reliably */
errors.push(svc.name)
})
)
])(services.running))
.then(() => {
View
@@ -10,6 +10,9 @@ const cmp = require('semver-compare')
const pad = (len, str) => str.length < len ? str + ' '.repeat(len - str.length) : str
const utils = {
/**
* Outputs all available tasks in devlab config
*/
tasks: () => {
const cfg = require('./config').load()
const tasks = _.keys(cfg.tasks)
View
@@ -60,30 +60,15 @@ describe('args', () => {
})
})
describe('tasks', () => {
const confPath = `${process.cwd()}/devlab.yml`
before(() => {
fs.writeFileAsync(confPath, [
'tasks:',
' stuff: echo "stuff" > /dev/null',
' lint: eslint .',
' ci: stuff test'
].join('\n'))
beforeEach(() => {
sinon.stub(utils, 'tasks')
})
after(() => {
fs.unlinkAsync(confPath)
afterEach(() => {
utils.tasks.restore()
})
it('pretty prints all tasks in the config', () => {
it('calls utils tasks method to list available tasks', () => {
args.tasks()
expect(console.log).to.have.been.calledWithExactly([
'',
'Tasks:',
' stuff echo "stuff" > /dev/null',
' lint eslint .',
' ci stuff test'
].join('\n'))
expect(utils.tasks).to.be.calledOnce()
expect(process.exit).to.be.calledWith(0)
})
})
@@ -188,10 +173,12 @@ describe('args', () => {
})
})
it('calls args init method if `init` is passed', () => {
sinon.stub(process, 'cwd', () => __dirname)
sandbox.stub(args, 'init')
args.raw = { _: [ 'init' ] }
return args.parse().then(() => {
expect(args.init).to.be.calledOnce()
process.cwd.restore()
})
})
it('skips init process if `init` is called but config already exists', () => {
View
@@ -1,14 +1,22 @@
const config = require('src/config')
const Promise = require('bluebird')
const fs = Promise.promisifyAll(require('fs'))
const path = require('path')
const rimraf = require('rimraf')
describe('config', () => {
const confPath = path.resolve(__dirname, '/tmp/devlab.yml')
beforeEach(() => {
sinon.stub(process, 'cwd', () => path.resolve(__dirname, '/tmp'))
return fs.writeFileAsync(confPath, 'from: node:4')
})
afterEach((done) => {
process.cwd.restore()
rimraf(`${__dirname}/tmp`, done)
})
describe('load', () => {
const confPath = `${process.cwd()}/devlab.yml`
beforeEach(() => fs.writeFileAsync(confPath, 'from: node:4'))
afterEach(() => fs.unlinkAsync(confPath))
it('loads the $CWD/devlab.yml default config location', () => {
expect(config.load()).to.deep.equal({ from: 'node:4' })
expect(config.load()).to.be.an('object')
})
it('loads the devlab.yml from a custom path when specified', () => {
expect(config.load(confPath)).to.deep.equal({ from: 'node:4' })
View
@@ -34,9 +34,7 @@ describe('index', () => {
describe('checkForUpdates', () => {
it('warns user if an update is available', () => {
expect(mockUpdateNotifier).not.to.have.been.called()
instance.checkForUpdates()
expect(mockUpdateNotifier).to.have.been.calledOnce()
expect(mockUpdateNotifier).to.have.been.calledWithExactly({ pkg })
expect(output.warn).to.be.calledWith(`Update available: ${mockUpdateNotifierInstance.update.latest}`)
View
@@ -22,11 +22,12 @@ describe('tempdir', () => {
delete process.env.DEVLAB_TMP
})
it('uses /tmp if DEVLAB_TMP is not available', () => {
process.env.DEVLAB_TMP = '/var'
process.env.DEVLAB_TMP = '/nope'
expect(tempdir()).to.equal('/tmp')
delete process.env.DEVLAB_TMP
})
it('uses /tmp if DEVLAB_TMP not set', () => {
delete process.env.DEVLAB_TMP
expect(tempdir()).to.equal('/tmp')
})
it('uses os-tmpdir if DEVLAB_TMP and /tmp not available', () => {
View
@@ -12,6 +12,18 @@ const fixtureIds = fixtures.ps.ids.split('\n').filter(Boolean)
const fixtureAllIds = fixtures.ps.allIds.split('\n').filter(Boolean)
describe('utils', () => {
describe('tasks', () => {
beforeEach(() => {
sinon.stub(console, 'log')
})
afterEach(() => {
console.log.restore()
})
it('loads config and outputs tasks to the console', () => {
utils.tasks()
expect(console.log.firstCall.args[0]).to.include('Tasks')
})
})
describe('cleanup', () => {
beforeEach(() => {
sandbox.stub(cp, 'execSync', cmd => {
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

0 comments on commit 692a817

Please sign in to comment.