Skip to content

Commit

Permalink
Add test for scope tracking features in static-module@3
Browse files Browse the repository at this point in the history
  • Loading branch information
goto-bus-stop committed Jun 22, 2018
1 parent a365cb7 commit 27be82e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/files/scope-sentinel
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SCOPE_SENTINEL
9 changes: 9 additions & 0 deletions test/files/scope.js
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')
25 changes: 25 additions & 0 deletions test/scope.js
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');
});

});

0 comments on commit 27be82e

Please sign in to comment.