-
-
Notifications
You must be signed in to change notification settings - Fork 306
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #224 from mstade/source-map-support
Add flag to require modules before running tests
- Loading branch information
Showing
8 changed files
with
160 additions
and
3 deletions.
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() | ||
}) |