-
-
Notifications
You must be signed in to change notification settings - Fork 306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add flag to require modules before running tests #224
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
737aa42
Added rudimentary source map support
mstade 3f02033
Revert "Added rudimentary source map support"
mstade 7ae60f5
This implements `-r` and `--require` as command line options
mstade 4f81dbc
Use ~ for minimist and resolve dependency versions.
mstade d0ca885
Make single require check more readable
mstade 096d2e7
Add `-r,--require` documentation to README.md
mstade 2e57f22
Fix indent mistake
mstade ffa503a
Use regular ol' `if` instead of boolean operator in sanity check
mstade 4077efe
Fix spelling mistake in comment
mstade 9f02249
Unquote keys in object literals
mstade File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
var tap = require('tap'); | ||
var spawn = require('child_process').spawn; | ||
var trim = require('string.prototype.trim'); | ||
|
||
tap.test('requiring a single module', function (t) { | ||
t.plan(2); | ||
|
||
var tc = tap.createConsumer(); | ||
|
||
var rows = []; | ||
tc.on('data', function (r) { rows.push(r) }); | ||
tc.on('end', function () { | ||
var rs = rows.map(function (r) { | ||
if (r && typeof r === 'object') { | ||
return { id : r.id, ok : r.ok, name : trim(r.name) }; | ||
} | ||
else return r; | ||
}); | ||
t.same(rs, [ | ||
'TAP version 13', | ||
'module-a', | ||
{ id: 1, ok: true, name: 'loaded module a' }, | ||
'test-a', | ||
{ id: 2, ok: true, name: 'module-a loaded in same context'}, | ||
{ id: 3, ok: true, name: 'test ran after module-a was loaded'}, | ||
'tests 3', | ||
'pass 3', | ||
'ok' | ||
]); | ||
}); | ||
|
||
var ps = tape('-r ./require/a require/test-a.js'); | ||
ps.stdout.pipe(tc); | ||
ps.on('exit', function (code) { | ||
t.equal(code, 0); | ||
}); | ||
}); | ||
|
||
tap.test('requiring multiple modules', function (t) { | ||
t.plan(2); | ||
|
||
var tc = tap.createConsumer(); | ||
|
||
var rows = []; | ||
tc.on('data', function (r) { rows.push(r) }); | ||
tc.on('end', function () { | ||
var rs = rows.map(function (r) { | ||
if (r && typeof r === 'object') { | ||
return { id : r.id, ok : r.ok, name : trim(r.name) }; | ||
} | ||
else return r; | ||
}); | ||
t.same(rs, [ | ||
'TAP version 13', | ||
'module-a', | ||
{ id: 1, ok: true, name: 'loaded module a' }, | ||
'module-b', | ||
{ id: 2, ok: true, name: 'loaded module b' }, | ||
'test-a', | ||
{ id: 3, ok: true, name: 'module-a loaded in same context'}, | ||
{ id: 4, ok: true, name: 'test ran after module-a was loaded'}, | ||
'test-b', | ||
{ id: 5, ok: true, name: 'module-b loaded in same context'}, | ||
{ id: 6, ok: true, name: 'test ran after module-b was loaded'}, | ||
'tests 6', | ||
'pass 6', | ||
'ok' | ||
]); | ||
}); | ||
|
||
var ps = tape('-r ./require/a -r ./require/b require/test-a.js require/test-b.js'); | ||
ps.stdout.pipe(tc); | ||
ps.on('exit', function (code) { | ||
t.equal(code, 0); | ||
}); | ||
}); | ||
|
||
function tape(args) { | ||
var proc = require('child_process') | ||
var bin = __dirname + '/../bin/tape' | ||
|
||
return proc.spawn(bin, args.split(' '), { cwd: __dirname }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
var tape = require('../..'); | ||
|
||
tape.test('module-a', function(t) { | ||
t.pass('loaded module a') | ||
t.end() | ||
}) | ||
|
||
global.module_a = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
var tape = require('../..'); | ||
|
||
tape.test('module-b', function(t) { | ||
t.pass('loaded module b') | ||
t.end() | ||
}) | ||
|
||
global.module_b = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
var tape = require('../..'); | ||
|
||
tape.test('test-a', function(t) { | ||
t.ok(global.module_a, 'module-a loaded in same context') | ||
t.pass('test ran after module-a was loaded') | ||
t.end() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
var tape = require('../..'); | ||
|
||
tape.test('test-b', function(t) { | ||
t.ok(global.module_b, 'module-b loaded in same context') | ||
t.pass('test ran after module-b was loaded') | ||
t.end() | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could replace this if block with
var requires = [].concat(opts.require)
, fwiw (that would also avoid mutatingopts
)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did something similar previously, but @Raynos suggested the change to the
typeof
block instead. I don't really care much either way to be honest.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i guess either way is fine