Skip to content

Commit

Permalink
build(windows): Fix dredd tests for windows?
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisAlderson committed Dec 27, 2017
1 parent a3ff392 commit c2fd7a1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 31 deletions.
51 changes: 21 additions & 30 deletions dredd.hooks.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
// Import the neccesary modules.
// @flow
import del from 'del'
import dotenv from 'dotenv'
import 'dotenv/config'
// @flow-ignore
import hooks from 'hooks'
import mkdirp from 'mkdirp'
import pMap from 'p-map'
import { createWriteStream } from 'fs'
import {
Expand All @@ -25,11 +23,22 @@ import {
} from './src/models'
import { name } from './package'

dotenv.config()
process.env.TEMP_DIR = process.env.TEMP_DIR || join(...['tmp'])

const tempDir = process.env.TEMP_DIR
const models = []
const models = [{
c: AnimeMovie,
m: new AnimeMovie(testAnimeMovie)
}, {
c: AnimeShow,
m: new AnimeShow(testAnimeShow)
}, {
c: Movie,
m: new Movie(testMovie)
}, {
c: Show,
m: new Show(testShow)
}]

/**
* The database middleware to connect to MongoDb.
Expand All @@ -41,42 +50,25 @@ hooks.beforeAll((t, done) => {
database = new Database(PopApi, {
database: name
})

del.sync([tempDir])
mkdirp.sync(tempDir)
createWriteStream(join(...[
tempDir,
`${name}.log`
])).end()

return database.connect().then(() => {
models.push({
c: AnimeMovie,
m: new AnimeMovie(testAnimeMovie)
}, {
c: AnimeShow,
m: new AnimeShow(testAnimeShow)
}, {
c: Movie,
m: new Movie(testMovie)
}, {
c: Show,
m: new Show(testShow)
})

return pMap(models, model => {
return model.c.findOneAndUpdate({
_id: model.m.id
}, model.m, {
upsert: true,
new: true
}).exec()
.then(res => hooks.log(`Inserted content: '${res.id}'`))
}).then(res => hooks.log(`Inserted content: '${res.id}'`))
})
}).then(() => database.disconnect())
.then(() => hooks.log('beforeAll: ok'))
.then(() => done())
.catch(err => {
hooks.error(`Uhoh an error occurred during the beforeAll hook: '${err}'`)
hooks.error(`beforeAll: '${err}'`)
done()
})
})
Expand All @@ -86,14 +78,13 @@ hooks.afterAll((t, done) => {
return pMap(models, model => {
return model.c.findOneAndRemove({
_id: model.m.id
}, model.model).exec()
.then(res => hooks.log(`Removed content: '${res.id}'`))
}).then(res => hooks.log(`Removed content: '${res.id}'`))
})
}).then(() => database.disconnect())
.then(del.sync([tempDir]))
.then(done)
.then(() => hooks.log('afterAll: ok'))
.then(() => done())
.catch(err => {
hooks.error(`Uhoh an error occurred during the afterAll hook: '${err}'`)
hooks.error(`afterAll: '${err}'`)
done()
})
})
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"providers": "babel-node ./src/index.js --providers",
"start": "cross-env NODE_ENV=production node ./build/popcorn-api.js",
"test": "npm run test-dredd && npm run test-mocha",
"test-dredd": "cross-env NODE_ENV=test babel-node ./node_modules/.bin/dredd",
"test-dredd": "cross-env NODE_ENV=test babel-node ./node_modules/dredd/bin/dredd",
"test-mocha": "cross-env NODE_ENV=test nyc -r=lcov -r=text mocha --exit --recursive --timeout 10000"
},
"bin": {
Expand Down
1 change: 1 addition & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default {
input: './src/index.js',
external: [
...Object.keys(dependencies),
'cluster',
'fs',
'path'
],
Expand Down

0 comments on commit c2fd7a1

Please sign in to comment.