Skip to content

Commit

Permalink
Refactor helper to prepare for browser tests.
Browse files Browse the repository at this point in the history
* make global.testdouble, global.lodash
* requireSubject no longer calls require, just
reduces on the testdouble global (only required a 
change to one line of all the test code), all passing
  • Loading branch information
searls committed Sep 13, 2015
1 parent b9d631e commit 3e86bce
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"scripts": {
"start": "testem",
"test": "mocha -u mocha-gwt -R $npm_package_config_mocha_reporter --compilers coffee:coffee-script --recursive test/helper.coffee test/",
"test": "mocha -u mocha-gwt -R $npm_package_config_mocha_reporter --compilers coffee:coffee-script --recursive test/node-helper.coffee test/general-helper.coffee test/",

This comment has been minimized.

Copy link
@jasonkarns

jasonkarns Sep 14, 2015

Member

should we just have the node-helper require the general helper?

This comment has been minimized.

Copy link
@searls

searls Sep 14, 2015

Author Member

I don't really care.

"test:debug": "npm test -- --debug-brk",
"build": "browserify . --extension=.coffee -o $npm_package_config_build_file",
"audit:disc": "npm run build -- --full-paths && discify $npm_package_config_build_file --open",
Expand Down
Empty file added test/general-helper.coffee
Empty file.
2 changes: 1 addition & 1 deletion test/lib/testdouble-test.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
describe "testdouble.js", ->
Given -> @subject = requireSubject('lib/testdouble')
Given -> @subject = requireSubject()
describe "where all the functions are", ->
Then -> @subject.when == requireSubject('lib/when')
Then -> @subject.verify == requireSubject('lib/verify')
Expand Down
12 changes: 11 additions & 1 deletion test/helper.coffee → test/node-helper.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
global.testdouble = require('./../lib/testdouble')
global._ = require('lodash')
global.expect = require('chai').expect

# Stuff to pull into the common-helper
global.context = describe
global.requireSubject = (path) -> require("#{process.cwd()}/#{path}")
global.requireSubject = (path) ->
return testdouble unless path?

This comment has been minimized.

Copy link
@jasonkarns

jasonkarns Sep 14, 2015

Member

should we be explicit to return global.testdouble? I seem to remember a reason for this but can't recall, atm

This comment has been minimized.

Copy link
@searls

searls Sep 14, 2015

Author Member

I cannot imagine when it would matter in this file listing.

This comment has been minimized.

Copy link
@jasonkarns

jasonkarns Sep 14, 2015

Member

browserify automatically inserts a window reference in place of global but only when global is referenced. relying on the implicit global would fail if it were the only global reference. Of course, it clearly isn't the only global reference in this case since there are other explicit refs. But (I think) that was the nagging reason I had for always being explicit.

This comment has been minimized.

Copy link
@searls

searls via email Sep 14, 2015

Author Member

This comment has been minimized.

Copy link
@jasonkarns

jasonkarns via email Sep 14, 2015

Member

This comment has been minimized.

Copy link
@searls

searls Sep 14, 2015

Author Member

I thought we were talking about the global thing

This comment has been minimized.

Copy link
@jasonkarns

jasonkarns via email Sep 14, 2015

Member

This comment has been minimized.

Copy link
@jasonkarns

jasonkarns Sep 14, 2015

Member

It might be a browserify compulsion, or a jshint/jscs compulsion.

Oh!! It just came to me while responding... I remember the other reason I'm explicit about global/window. notAThing will throw a ReferenceError if undefined but window.notAThing doesn't (it's just an undefined property reference). When writing libs, i'd rather coerce to an evil, hard-to-trace undefined than throw exceptions in userland.

So I guess a combination of reference error avoidance, browserify behavior, and jshint/jscs lashings have gotten me in the habit of being explicit about globals. Ironically, the (only ?) time I still use implicit globals is in my tests. Which started this whole convo. woops

[lib, pathComponents...] = path.split('/')
_.reduce pathComponents, (memo, nextProp) ->
console.log "HEYY", testdouble, "memo:", memo, "next:", nextProp
memo[nextProp]
, testdouble

global.xThen = ->

Expand Down

0 comments on commit 3e86bce

Please sign in to comment.