require 'window'

measure 'spec suite require time', ->
  fsUtils = require 'fs-utils'
  path = require 'path'
  require 'spec-helper'

  requireSpecs = (directoryPath, specType) ->
    for specPath in fsUtils.listTreeSync(path.join(directoryPath, 'spec')) when /-spec\.coffee$/.test specPath
      require specPath

  setSpecType = (specType) ->
    for spec in jasmine.getEnv().currentRunner().specs() when not spec.specType?
      spec.specType = specType

  # Run core specs
  requireSpecs(window.resourcePath)
  setSpecType('core')

  # Run bundled package specs
  for packagePath in fsUtils.listTreeSync(config.nodeModulesDirPath) when atom.isInternalPackage(packagePath)
    requireSpecs(packagePath, 'bundled')
  setSpecType('bundled')

  # Run user package specs
  for packagePath in fsUtils.listTreeSync(config.userPackagesDirPath)
    requireSpecs(packagePath, 'user')
  setSpecType('user')

fs = require 'fs'

require 'window'

measure 'spec suite require time', ->
  fsUtils = require 'fs-utils'
  path = require 'path'
  require 'spec-helper'

  requireSpecs = (directoryPath, specType) ->
    for specPath in fsUtils.listTreeSync(path.join(directoryPath, 'spec')) when /-spec\.coffee$/.test specPath
      require specPath

  setSpecType = (specType) ->
    for spec in jasmine.getEnv().currentRunner().specs() when not spec.specType?
      spec.specType = specType

  # Run core specs
  requireSpecs(window.resourcePath)
  setSpecType('core')

  # Run bundled package specs
  if fsUtils.isDirectorySync(config.nodeModulesDirPath)
    for packageName in fs.readdirSync(config.nodeModulesDirPath)
      packagePath = path.join(config.nodeModulesDirPath, packageName)
      requireSpecs(packagePath, 'bundled') if atom.isInternalPackage(packagePath)
    setSpecType('bundled')

  # Run user package specs
  if fsUtils.isDirectorySync(config.userPackagesDirPath)
    for packageName in fs.readdirSync(config.userPackagesDirPath)
      requireSpecs(path.join(config.userPackagesDirPath, packageName))
    setSpecType('user')

Use fs.readdirSync() for listing package directories
Use fs.readdirSync() for listing package directories

Previously fsUtils.listTreeSync() was used which returns every path
in the tree, not just paths directly underneath the root path.

This speeds up the spec suite require time by not stat'ing the entire
node_modules directory.
