-
-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for scope tracking features in static-module@3
- Loading branch information
1 parent
a365cb7
commit 27be82e
Showing
3 changed files
with
35 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 @@ | ||
SCOPE_SENTINEL |
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,9 @@ | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var dynamicallyCreatedFilename = path.join('/files/', 'somefile'); | ||
fs.readFileSync(__dirname + dynamicallyCreatedFilename + __dirname, 'utf8'); | ||
function x (fs) { | ||
fs.readFileSync('doesNotExist') | ||
} | ||
fs.readFileSync(__dirname + '/scope-sentinel') | ||
require('fs').readFileSync(__dirname + '/scope-sentinel') |
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,25 @@ | ||
var test = require('tap').test; | ||
var browserify = require('browserify'); | ||
var path = require('path'); | ||
|
||
test('scope', function (t) { | ||
t.plan(4); | ||
|
||
var b = browserify({ node: true }); | ||
b.add(__dirname + '/files/scope'); | ||
b.transform(path.dirname(__dirname)); | ||
|
||
b.bundle(function (err, src) { | ||
if (err) t.fail(err); | ||
t.pass('build success'); | ||
src = src.toString(); | ||
console.log(src) | ||
t.ok(src.indexOf("require('fs')") !== -1, 'kept the require call'); | ||
var sentinel = new Buffer('SCOPE_SENTINEL\n', 'utf8').toString('base64') | ||
var i = src.indexOf(sentinel); | ||
t.ok(i !== -1, 'read the file'); | ||
i = src.indexOf(sentinel, i + 10); | ||
t.ok(i !== -1, 'did the require("fs").readFileSync'); | ||
}); | ||
|
||
}); |