2014-02-24 05:09:05 +04:00
|
|
|
_ = require 'underscore-plus'
|
|
|
|
fs = require 'fs-plus'
|
|
|
|
{Git} = require 'atom'
|
2013-11-14 21:03:58 +04:00
|
|
|
path = require 'path'
|
2014-02-24 05:11:38 +04:00
|
|
|
require './spec-helper'
|
2013-11-14 21:03:58 +04:00
|
|
|
|
|
|
|
requireSpecs = (specDirectory, specType) ->
|
2014-03-12 00:01:28 +04:00
|
|
|
for specFilePath in fs.listTreeSync(specDirectory) when /-spec\.(coffee|js)$/.test specFilePath
|
2013-11-14 21:03:58 +04:00
|
|
|
require specFilePath
|
|
|
|
|
|
|
|
# Set spec directory on spec for setting up the project in spec-helper
|
|
|
|
setSpecDirectory(specDirectory)
|
|
|
|
|
|
|
|
setSpecField = (name, value) ->
|
|
|
|
specs = jasmine.getEnv().currentRunner().specs()
|
|
|
|
return if specs.length is 0
|
|
|
|
for index in [specs.length-1..0]
|
|
|
|
break if specs[index][name]?
|
|
|
|
specs[index][name] = value
|
|
|
|
|
|
|
|
setSpecType = (specType) ->
|
|
|
|
setSpecField('specType', specType)
|
|
|
|
|
|
|
|
setSpecDirectory = (specDirectory) ->
|
|
|
|
setSpecField('specDirectory', specDirectory)
|
|
|
|
|
|
|
|
runAllSpecs = ->
|
2013-11-22 02:55:25 +04:00
|
|
|
{resourcePath} = atom.getLoadSettings()
|
2014-03-18 11:57:16 +04:00
|
|
|
|
2013-11-14 21:03:58 +04:00
|
|
|
fixturesPackagesPath = path.join(__dirname, 'fixtures', 'packages')
|
2013-11-20 05:31:41 +04:00
|
|
|
packagePaths = atom.packages.getAvailablePackageNames().map (packageName) ->
|
|
|
|
atom.packages.resolvePackagePath(packageName)
|
2013-11-14 21:03:58 +04:00
|
|
|
packagePaths = _.groupBy packagePaths, (packagePath) ->
|
|
|
|
if packagePath.indexOf("#{fixturesPackagesPath}#{path.sep}") is 0
|
|
|
|
'fixtures'
|
2013-11-22 02:55:25 +04:00
|
|
|
else if packagePath.indexOf("#{resourcePath}#{path.sep}") is 0
|
2013-11-14 21:03:58 +04:00
|
|
|
'bundled'
|
|
|
|
else
|
|
|
|
'user'
|
|
|
|
|
|
|
|
# Run bundled package specs
|
|
|
|
requireSpecs(path.join(packagePath, 'spec')) for packagePath in packagePaths.bundled ? []
|
|
|
|
setSpecType('bundled')
|
|
|
|
|
|
|
|
# Run user package specs
|
|
|
|
requireSpecs(path.join(packagePath, 'spec')) for packagePath in packagePaths.user ? []
|
|
|
|
setSpecType('user')
|
|
|
|
|
|
|
|
if specDirectory = atom.getLoadSettings().specDirectory
|
|
|
|
requireSpecs(specDirectory)
|
|
|
|
setSpecType('user')
|
|
|
|
else
|
|
|
|
runAllSpecs()
|