Files
atom/build/tasks/spec-task.coffee
Antonio Scandurra 61d8c6852c Remove non-Mac run-specs code and use ELECTRON_ENABLE_LOGGING=true
* Remove Windows/Linux run-specs code. There is little value in keeping those
  code paths, given that we don't run specs on those platforms; if we ever need
  it again, we can restore it from the git history.
* Use ELECTRON_ENABLE_LOGGING=true. This allows us to capture the output of
  calls to `console.warn` and `console.log`, which are useful to log out Grim
  deprecations.
* Remove `logDeprecations` in build/spec-task.coffee. This method used to format the output captured on stderr to strip out "[Console]" noise from deprecations.
  This code path was not running anymore because we started using stdio:
  'inherit' in #10838, which prevents stderr output to be captured. This doesn't
  seem a huge deal, so long as those deprecations get logged to screen.
2016-04-14 15:07:50 +02:00

93 lines
3.0 KiB
CoffeeScript

fs = require 'fs'
path = require 'path'
temp = require('temp').track()
_ = require 'underscore-plus'
async = require 'async'
module.exports = (grunt) ->
{isAtomPackage, spawn} = require('./task-helpers')(grunt)
packageSpecQueue = null
getAppPath = ->
contentsDir = grunt.config.get('atom.contentsDir')
path.join(contentsDir, 'MacOS', 'Atom')
runPackageSpecs = (callback) ->
failedPackages = []
rootDir = grunt.config.get('atom.shellAppDir')
resourcePath = process.cwd()
appPath = getAppPath()
packageSpecQueue = async.queue (packagePath, callback) ->
options =
cmd: appPath
args: ['--test', "--resource-path=#{resourcePath}", path.join(packagePath, 'spec')]
opts:
cwd: packagePath
env: _.extend({}, process.env, ELECTRON_ENABLE_LOGGING: true, ATOM_PATH: rootDir)
grunt.log.ok "Launching #{path.basename(packagePath)} specs."
spawn options, (error) ->
failedPackages.push path.basename(packagePath) if error
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'))
continue unless isAtomPackage(packagePath)
packageSpecQueue.push(packagePath)
packageSpecQueue.concurrency = 1
packageSpecQueue.drain = -> callback(null, failedPackages)
runCoreSpecs = (callback) ->
appPath = getAppPath()
resourcePath = process.cwd()
coreSpecsPath = path.resolve('spec')
options =
cmd: appPath
args: ['--test', "--resource-path=#{resourcePath}", coreSpecsPath, "--user-data-dir=#{temp.mkdirSync('atom-user-data-dir')}"]
opts:
env: _.extend({}, process.env, {ATOM_INTEGRATION_TESTS_ENABLED: true, ELECTRON_ENABLE_LOGGING: true})
stdio: 'inherit'
grunt.log.ok "Launching core specs."
spawn options, (error, results) ->
callback(null, error)
grunt.registerTask 'run-specs', 'Run the specs', ->
done = @async()
startTime = Date.now()
specs =
if process.env.ATOM_SPECS_TASK is 'packages'
[runPackageSpecs]
else if process.env.ATOM_SPECS_TASK is 'core'
[runCoreSpecs]
else
[runCoreSpecs, runPackageSpecs]
async.series specs, (error, results) ->
failedPackages = []
coreSpecFailed = null
if process.env.ATOM_SPECS_TASK is 'packages'
[failedPackages] = results
else if process.env.ATOM_SPECS_TASK is 'core'
[coreSpecFailed] = results
else
[coreSpecFailed, failedPackages] = results
elapsedTime = Math.round((Date.now() - startTime) / 100) / 10
grunt.log.ok("Total spec time: #{elapsedTime}s")
failures = failedPackages
failures.push "atom core" if coreSpecFailed
grunt.log.error("[Error]".red + " #{failures.join(', ')} spec(s) failed") if failures.length > 0
done(not coreSpecFailed and failedPackages.length is 0)