Permalink
Browse files

Added a fix for CoffeeScript testing so that CoffeeScript will be imp…

…orted from directories relative to the testing file.
  • Loading branch information...
1 parent b814ed3 commit 9e2eac09d7853badab07bea6bd02964aa4626872 @leeola committed Aug 24, 2012
Showing with 9 additions and 9 deletions.
  1. +2 −1 HISTORY.md
  2. +7 −8 lib/bin.coffee
View
@@ -2,7 +2,8 @@
0.0.5 /
==================
- *
+ * Added a fix for CoffeeScript testing so that it will import from
+ directories relative to the specified testing file.
0.0.4 / 2012-08-23
==================
View
@@ -63,13 +63,10 @@ exec = (input) ->
# Parse the opts, with a possible input override.
opts = nomnom.parse input
- # If the user specified coffee usage, import immediately.
- if opts.coffee is true
- import_coffee()
-
for user_file in opts.files
# Resolve the path relative to the cwd.
file = path.join process.cwd(), user_file
+ dirname = path.dirname file
# Check if the file specified by the user even exists.
if not existsSync(file)
@@ -95,7 +92,10 @@ exec = (input) ->
index_file = path.join file, 'index.coffee'
stat = fs.statSync index_file
if path.extname(index_file) is '.coffee'
- import_coffee()
+ import_coffee dirname
+ # If the user specified coffee usage, import immediately.
+ else if opts.coffee is true
+ import_coffee dirname
# Import the target file/directory, then simply run dork.
@@ -110,7 +110,6 @@ exec = (input) ->
# dork instance*!
# To solve this issue, we use the same dork module that the target file
# should be using when it calls `require 'dork'`.
- dirname = path.dirname file
dork = require resolve.sync 'dork', basedir: dirname
# Define any patterns provided.
@@ -124,9 +123,9 @@ exec = (input) ->
# Desc:
# A simple function to attempt to import coffee, or fail with a meaningful
# message if coffee is not found.
-import_coffee = ->
+import_coffee = (basedir) ->
try
- require 'coffee-script'
+ require resolve.sync 'coffee-script', basedir: basedir
catch e
if e.message is "Cannot find module 'coffee-script'"
throw new Error 'CoffeeScript must be installed manually to test '+

0 comments on commit 9e2eac0

Please sign in to comment.