pulsar/spec/spec-suite.coffee

43 lines
1.5 KiB
CoffeeScript
Raw Normal View History

2013-03-15 19:09:56 +04:00
measure 'spec suite require time', ->
2013-09-20 00:51:53 +04:00
{_, fs, Git} = require 'atom'
path = require 'path'
2013-09-18 01:54:33 +04:00
require './spec-helper'
requireSpecs = (specDirectory, specType) ->
2013-09-18 05:58:41 +04:00
for specFilePath in fs.listTreeSync(specDirectory) when /-spec\.coffee$/.test specFilePath
require specFilePath
setSpecType = (specType) ->
for spec in jasmine.getEnv().currentRunner().specs() when not spec.specType?
spec.specType = specType
runAllSpecs = ->
# Only run core specs when resource path is the Atom repository
if Git.exists(window.resourcePath)
requireSpecs(path.join(window.resourcePath, 'spec'))
setSpecType('core')
fixturesPackagesPath = path.join(__dirname, 'fixtures', 'packages')
packagePaths = atom.getAvailablePackageNames().map (packageName) -> atom.resolvePackagePath(packageName)
packagePaths = _.groupBy packagePaths, (packagePath) ->
if packagePath.indexOf("#{fixturesPackagesPath}#{path.sep}") is 0
'fixtures'
else if packagePath.indexOf("#{window.resourcePath}#{path.sep}") is 0
'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()