2013-10-11 04:22:14 +04:00
|
|
|
fs = require 'fs'
|
|
|
|
path = require 'path'
|
|
|
|
|
2013-10-15 20:34:59 +04:00
|
|
|
_ = require 'underscore-plus'
|
2013-10-11 04:22:14 +04:00
|
|
|
async = require 'async'
|
|
|
|
|
|
|
|
module.exports = (grunt) ->
|
2013-10-11 20:43:37 +04:00
|
|
|
{isAtomPackage, spawn} = require('./task-helpers')(grunt)
|
2013-10-11 04:22:14 +04:00
|
|
|
|
2013-10-12 00:26:09 +04:00
|
|
|
packageSpecQueue = null
|
|
|
|
|
2013-10-11 22:36:26 +04:00
|
|
|
runPackageSpecs = (callback) ->
|
2013-10-11 04:22:14 +04:00
|
|
|
passed = true
|
2013-10-11 20:38:08 +04:00
|
|
|
rootDir = grunt.config.get('atom.shellAppDir')
|
2013-10-11 22:36:26 +04:00
|
|
|
appDir = grunt.config.get('atom.appDir')
|
2013-10-11 20:21:15 +04:00
|
|
|
atomPath = path.join(appDir, 'atom.sh')
|
|
|
|
apmPath = path.join(appDir, 'node_modules/.bin/apm')
|
2013-10-11 04:22:14 +04:00
|
|
|
|
2013-10-12 00:26:09 +04:00
|
|
|
packageSpecQueue = async.queue (packagePath, callback) ->
|
2013-10-11 04:22:14 +04:00
|
|
|
options =
|
2013-10-11 20:08:36 +04:00
|
|
|
cmd: apmPath
|
2013-10-11 20:08:57 +04:00
|
|
|
args: ['test', '--path', atomPath]
|
2013-10-11 04:22:14 +04:00
|
|
|
opts:
|
|
|
|
cwd: packagePath
|
2013-10-11 20:38:08 +04:00
|
|
|
env: _.extend({}, process.env, ATOM_PATH: rootDir)
|
2013-10-11 20:07:49 +04:00
|
|
|
grunt.log.writeln("Launching #{path.basename(packagePath)} specs.")
|
2013-10-11 04:22:14 +04:00
|
|
|
spawn options, (error, results, code) ->
|
2013-10-14 22:39:29 +04:00
|
|
|
grunt.log.writeln()
|
2013-10-11 04:22:14 +04:00
|
|
|
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)
|
2013-10-12 00:26:09 +04:00
|
|
|
packageSpecQueue.push(packagePath)
|
2013-10-11 04:22:14 +04:00
|
|
|
|
2013-10-12 00:26:09 +04:00
|
|
|
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()
|
2013-10-12 00:26:09 +04:00
|
|
|
packageSpecQueue.concurrency = 2
|
2013-10-11 22:47:06 +04:00
|
|
|
callback(null, code is 0)
|
2013-10-11 22:36:26 +04:00
|
|
|
|
|
|
|
grunt.registerTask 'run-specs', 'Run the specs', ->
|
2013-10-11 22:47:06 +04:00
|
|
|
done = @async()
|
2013-10-12 01:46:26 +04:00
|
|
|
startTime = Date.now()
|
2013-10-11 22:47:06 +04:00
|
|
|
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")
|
2013-10-11 22:47:06 +04:00
|
|
|
done(coreSpecPassed and packageSpecsPassed)
|