mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-27 01:25:42 -05:00
Add istanbul coverage npm script
This commit is contained in:
parent
831bc38573
commit
21fcc01cca
4 changed files with 59 additions and 12 deletions
2
.istanbul.yml
Normal file
2
.istanbul.yml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
instrumentation:
|
||||||
|
root: ./server
|
43
bin/coverage.js
Normal file
43
bin/coverage.js
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
fs = require('fs')
|
||||||
|
child_process = require('child_process')
|
||||||
|
|
||||||
|
// Have to convert all CS server files to JS for coverage to work.
|
||||||
|
// Walk through folders in server/ and compile each .coffee file,
|
||||||
|
// keeping a list of generated files so they can be deleted later.
|
||||||
|
|
||||||
|
var directories = ['./server']
|
||||||
|
var convertedFiles = [];
|
||||||
|
console.log('Convert server coffeescript files.')
|
||||||
|
|
||||||
|
while(directories.length) {
|
||||||
|
directory = directories.pop()
|
||||||
|
console.log('*', directory)
|
||||||
|
|
||||||
|
fs.readdirSync(directory).forEach((fileOrDir) => {
|
||||||
|
absPath = directory + '/' + fileOrDir
|
||||||
|
stat = fs.statSync(absPath)
|
||||||
|
|
||||||
|
// .coffee => .js
|
||||||
|
if(stat.isFile() && fileOrDir.endsWith('.coffee')) {
|
||||||
|
child_process.execSync(`coffee -c ${absPath}`)
|
||||||
|
convertedFiles.push(absPath.replace('.coffee', '.js'))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add to list of directories to walk
|
||||||
|
if(stat.isDirectory()) {
|
||||||
|
directories.push(absPath);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run Istanbul
|
||||||
|
console.log(`Converted ${convertedFiles.length} server coffeescript files. Running tests...`)
|
||||||
|
child_process.execSync('istanbul cover ./node_modules/jasmine/bin/jasmine.js')
|
||||||
|
|
||||||
|
// Cleanup
|
||||||
|
console.log('Coverage report generated. Deleting converted files...')
|
||||||
|
for (file of convertedFiles) {
|
||||||
|
fs.unlinkSync(file)
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('Done.')
|
|
@ -45,7 +45,8 @@
|
||||||
"smoke-local": "COCO_SMOKE_DOMAIN='local' nightwatch",
|
"smoke-local": "COCO_SMOKE_DOMAIN='local' nightwatch",
|
||||||
"smoke-next": "COCO_SMOKE_DOMAIN='next' nightwatch",
|
"smoke-next": "COCO_SMOKE_DOMAIN='next' nightwatch",
|
||||||
"smoke-prod": "COCO_SMOKE_DOMAIN='prod' nightwatch",
|
"smoke-prod": "COCO_SMOKE_DOMAIN='prod' nightwatch",
|
||||||
"smoke-staging": "COCO_SMOKE_DOMAIN='staging' nightwatch"
|
"smoke-staging": "COCO_SMOKE_DOMAIN='staging' nightwatch",
|
||||||
|
"coverage": "node ./bin/coverage.js"
|
||||||
},
|
},
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
|
@ -111,6 +112,7 @@
|
||||||
"css-brunch": "^1.7.0",
|
"css-brunch": "^1.7.0",
|
||||||
"fs-extra": "^0.26.2",
|
"fs-extra": "^0.26.2",
|
||||||
"http-proxy": "^1.13.2",
|
"http-proxy": "^1.13.2",
|
||||||
|
"istanbul": "^0.4.5",
|
||||||
"jade-brunch": "1.7.5",
|
"jade-brunch": "1.7.5",
|
||||||
"jasmine": "2.4.1",
|
"jasmine": "2.4.1",
|
||||||
"javascript-brunch": "> 1.0 < 1.8",
|
"javascript-brunch": "> 1.0 < 1.8",
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
Product = require '../../models/Product'
|
Product = require '../../models/Product'
|
||||||
errors = require '../../commons/errors'
|
errors = require '../../commons/errors'
|
||||||
config = require '../../../server_config'
|
config = require '../../../server_config'
|
||||||
|
wrap = require 'co-express'
|
||||||
|
|
||||||
module.exports.get = (req, res) ->
|
module.exports.get = wrap (req, res) ->
|
||||||
|
|
||||||
Product.find().lean().exec (err, products) ->
|
products = yield Product.find()
|
||||||
return errors.serverError(res) if err
|
names = (product.name for product in products)
|
||||||
names = (product.name for product in products)
|
unless config.isProduction
|
||||||
unless config.isProduction
|
for product in initProducts
|
||||||
for product in initProducts
|
if not _.contains(names, product.name)
|
||||||
if not _.contains(names, product.name)
|
# upsert products in initProducts if they DNE
|
||||||
# upsert products in initProducts if they DNE
|
products.push(product)
|
||||||
products.push(product)
|
new Product(product).save _.noop
|
||||||
new Product(product).save _.noop
|
res.send(products)
|
||||||
res.send(products)
|
|
||||||
|
|
||||||
###
|
###
|
||||||
Stub data, used in tests and dev environment.
|
Stub data, used in tests and dev environment.
|
||||||
|
|
Loading…
Reference in a new issue