-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding test for external basedir case
- Loading branch information
1 parent
1671dab
commit 2f95b6b
Showing
4 changed files
with
43 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
var browserify = require('../'); | ||
var vm = require('vm'); | ||
var test = require('tap').test; | ||
|
||
test('external', function (t) { | ||
t.plan(2); | ||
var baseDir = __dirname; | ||
var splitFile = baseDir + '/external_basedir/y.js'; | ||
var mainSrc = ''; | ||
var splitSrc = ''; | ||
var pending = 2; | ||
|
||
// main bundle should not include splitFile | ||
var b = browserify(baseDir + '/external_basedir/main.js', {basedir: baseDir}); | ||
b.external(splitFile); // no need to specify basedir option if it is already set for b | ||
b.bundle(function (err, src) { | ||
if (err) return t.fail(err); | ||
mainSrc = src; | ||
pending--; | ||
done(); | ||
}); | ||
|
||
// consider b2 as for split or vendor bundle | ||
var b2 = browserify([], {basedir: baseDir}); | ||
b2.require(splitFile, {expose: splitFile.replace(baseDir, '')}); | ||
b2.bundle(function (err, src) { | ||
if (err) return t.fail(err); | ||
splitSrc = src; | ||
pending--; | ||
done(); | ||
}); | ||
|
||
function done() { | ||
if (pending !== 0) { | ||
return; | ||
} | ||
vm.runInNewContext(splitSrc + mainSrc, { t: t }); | ||
} | ||
}); |
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,2 @@ | ||
t.equal(require('./x'), 'foo'); | ||
t.equal(require('./y'), 'bar'); |
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 @@ | ||
module.exports = 'foo'; |
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 @@ | ||
module.exports = 'bar'; |