Skip to content
This repository has been archived by the owner on Apr 26, 2018. It is now read-only.

Commit

Permalink
Merge pull request #68 from hongrich/specs-from-resource-path
Browse files Browse the repository at this point in the history
Load spec files from resource path if it's provided
  • Loading branch information
anaisbetts committed Apr 23, 2015
2 parents e7862a9 + dec3a23 commit 0379d56
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 23 deletions.
5 changes: 2 additions & 3 deletions build/tasks/spec-task.coffee
Expand Up @@ -41,8 +41,7 @@ module.exports = (grunt) ->
done = @async()
startTime = Date.now()
runCoreSpecs (error, results) ->
console.log error
console.log results
elapsedTime = Math.round((Date.now() - startTime) / 100) / 10
grunt.log.ok("Total spec time: #{elapsedTime}s")
done()
grunt.log.error("[Error]".red + " core spec failed") if results
done(!results)
5 changes: 3 additions & 2 deletions spec/spec-bootstrap.coffee
Expand Up @@ -7,6 +7,7 @@ app = remote.require 'app'

# Start the crash reporter before anything else.
require('crash-reporter').start(productName: @pkgJson.name, companyName: 'atom-shell-starter')
specRootPath = path.resolve(global.loadSettings.resourcePath, 'spec/')

if global.loadSettings.exitWhenDone
jasmineFn = require 'jasmine'
Expand All @@ -21,7 +22,7 @@ if global.loadSettings.exitWhenDone
jasmineEnv = jasmine.getEnv()
jasmineEnv.addReporter(reporter)

for specFilePath in fs.listTreeSync('spec/') when /-spec\.(coffee|js)$/.test specFilePath
for specFilePath in fs.listTreeSync(specRootPath) when /-spec\.(coffee|js)$/.test specFilePath
require specFilePath

jasmineEnv.execute()
Expand All @@ -35,7 +36,7 @@ else
require '../vendor/jasmine/lib/jasmine-2.1.3/jasmine-html'
require '../vendor/jasmine/lib/jasmine-2.1.3/boot'

for specFilePath in fs.listTreeSync('spec/') when /-spec\.(coffee|js)$/.test specFilePath
for specFilePath in fs.listTreeSync(specRootPath) when /-spec\.(coffee|js)$/.test specFilePath
require specFilePath

window.jasmineExecute()
9 changes: 3 additions & 6 deletions src/browser/application.coffee
Expand Up @@ -37,7 +37,6 @@ class Application
# :devMode - Boolean to determine if the application is running in dev mode.
# :test - Boolean to determine if the application is running in test mode.
# :exitWhenDone - Boolean to determine whether to automatically exit.
# :specDirectory - The directory to load specs from.
# :logfile - The file path to log output to.
openWithOptions: (options) ->
{test} = options
Expand All @@ -57,20 +56,19 @@ class Application
# options -
# :exitWhenDone - Boolean to determine whether to automatically exit.
# :resourcePath - The path to include specs from.
# :specDirectory - The directory to load specs from.
# :logfile - The file path to log output to.
openSpecsWindow: ({exitWhenDone, resourcePath, specDirectory, logFile}) ->
openSpecsWindow: ({exitWhenDone, resourcePath, logFile}) ->
if resourcePath isnt @resourcePath and not fs.existsSync(resourcePath)
resourcePath = @resourcePath

try
bootstrapScript = require.resolve(path.resolve(global.devResourcePath, 'spec', 'spec-bootstrap'))
bootstrapScript = require.resolve(path.resolve(resourcePath, 'spec', 'spec-bootstrap'))
catch error
bootstrapScript = require.resolve(path.resolve(__dirname, '..', '..', 'spec', 'spec-bootstrap'))

isSpec = true
devMode = true
new AppWindow({bootstrapScript, exitWhenDone, resourcePath, isSpec, devMode, specDirectory, logFile})
new AppWindow({bootstrapScript, exitWhenDone, resourcePath, isSpec, devMode, logFile})

# Opens up a new {AppWindow} and runs the application.
#
Expand All @@ -79,7 +77,6 @@ class Application
# :devMode - Boolean to determine if the application is running in dev mode.
# :test - Boolean to determine if the application is running in test mode.
# :exitWhenDone - Boolean to determine whether to automatically exit.
# :specDirectory - The directory to load specs from.
# :logfile - The file path to log output to.
openWindow: (options) ->
appWindow = new AppWindow(options)
Expand Down
13 changes: 1 addition & 12 deletions src/browser/main.coffee
Expand Up @@ -24,7 +24,6 @@ parseCommandLine = ->
.alias('h', 'help').boolean('h').describe('h', 'Print this usage message.')
.alias('l', 'log-file').string('l').describe('l', 'Log all output to file.')
.alias('r', 'resource-path').string('r').describe('r', 'Set the path to the App source directory and enable dev-mode.')
.alias('s', 'spec-directory').string('s').describe('s', 'Set the directory from which to run package specs (default: Atom\'s spec directory).')
.alias('t', 'test').boolean('t').describe('t', 'Run the specified specs and exit with error code on failures.')
.alias('v', 'version').boolean('v').describe('v', 'Print the version.')

Expand All @@ -45,21 +44,11 @@ parseCommandLine = ->
devMode = args['dev']
test = args['test']
exitWhenDone = test
specDirectory = args['spec-directory']
logFile = args['log-file']

if args['resource-path']
devMode = true
resourcePath = args['resource-path']
else
# Set resourcePath based on the specDirectory if running specs on atom core
if specDirectory?
packageDirectoryPath = path.join(specDirectory, '..')
packageManifestPath = path.join(packageDirectoryPath, 'package.json')
if fs.statSyncNoException(packageManifestPath)
try
packageManifest = JSON.parse(fs.readFileSync(packageManifestPath))
resourcePath = packageDirectoryPath if packageManifest.name is 'atom'

if devMode
resourcePath ?= global.devResourcePath
Expand All @@ -69,7 +58,7 @@ parseCommandLine = ->

resourcePath = path.resolve(resourcePath)

{resourcePath, devMode, test, exitWhenDone, specDirectory, logFile}
{resourcePath, devMode, test, exitWhenDone, logFile}

setupCoffeeScript = ->
CoffeeScript = null
Expand Down

0 comments on commit 0379d56

Please sign in to comment.