pulsar/tasks/spec-task.coffee

64 lines
2.2 KiB
CoffeeScript
Raw Normal View History

fs = require 'fs'
path = require 'path'
2013-10-15 20:34:59 +04:00
_ = require 'underscore-plus'
async = require 'async'
module.exports = (grunt) ->
2013-10-11 20:43:37 +04:00
{isAtomPackage, spawn} = require('./task-helpers')(grunt)
packageSpecQueue = null
2013-10-11 22:36:26 +04:00
runPackageSpecs = (callback) ->
passed = true
rootDir = grunt.config.get('atom.shellAppDir')
2013-10-11 22:36:26 +04:00
appDir = grunt.config.get('atom.appDir')
atomPath = path.join(appDir, 'atom.sh')
apmPath = path.join(appDir, 'node_modules/.bin/apm')
packageSpecQueue = async.queue (packagePath, callback) ->
options =
2013-10-11 20:08:36 +04:00
cmd: apmPath
2013-10-11 20:08:57 +04:00
args: ['test', '--path', atomPath]
opts:
cwd: packagePath
env: _.extend({}, process.env, ATOM_PATH: rootDir)
2013-10-11 20:07:49 +04:00
grunt.log.writeln("Launching #{path.basename(packagePath)} specs.")
spawn options, (error, results, code) ->
2013-10-14 22:39:29 +04:00
grunt.log.writeln()
passed = passed and code is 0
callback()
modulesDirectory = path.resolve('node_modules')
for packageDirectory in fs.readdirSync(modulesDirectory)
packagePath = path.join(modulesDirectory, packageDirectory)
continue unless grunt.file.isDir(path.join(packagePath, 'spec'))
2013-10-11 20:43:37 +04:00
continue unless isAtomPackage(packagePath)
packageSpecQueue.push(packagePath)
packageSpecQueue.concurrency = 1
packageSpecQueue.drain = -> callback(null, passed)
2013-10-11 22:36:26 +04:00
runCoreSpecs = (callback) ->
contentsDir = grunt.config.get('atom.contentsDir')
appPath = path.join(contentsDir, 'MacOS', 'Atom')
resourcePath = process.cwd()
coreSpecsPath = path.resolve('spec')
options =
cmd: appPath
args: ['--test', "--resource-path=#{resourcePath}", "--spec-directory=#{coreSpecsPath}"]
spawn options, (error, results, code) ->
2013-10-14 22:39:29 +04:00
grunt.log.writeln()
packageSpecQueue.concurrency = 2
callback(null, code is 0)
2013-10-11 22:36:26 +04:00
grunt.registerTask 'run-specs', 'Run the specs', ->
done = @async()
2013-10-12 01:46:26 +04:00
startTime = Date.now()
async.parallel [runCoreSpecs, runPackageSpecs], (error, results) ->
[coreSpecPassed, packageSpecsPassed] = results
2013-10-12 01:47:45 +04:00
elapsedTime = Math.round((Date.now() - startTime) / 100) / 10
grunt.log.writeln("Total spec time: #{elapsedTime}s")
done(coreSpecPassed and packageSpecsPassed)