Skip to content

Commit

Permalink
[test] setup local testling
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasMadsen committed Aug 19, 2013
1 parent acf97ef commit cc9683b
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"version": "1.0.7",
"description": "Builtins that were extracted from node-browser-resolve on which browserify depends",
"main": "index.js",
"scripts": {
"test": "tape test/node/* && browserify --transform ./test/browserify-transform.js test/browser/* | testling"

This comment has been minimized.

Copy link
@alexgorbatchev

alexgorbatchev Sep 23, 2013

Owner

I can't seem to get npm test to work with this set up after install browserify and testling

This comment has been minimized.

Copy link
@AndreasMadsen

AndreasMadsen Sep 23, 2013

Author Collaborator

That is odd, could you open an issue and post some more details (like error or where it stops). The only thing special about my setup is that I'm using tape-testing/testling#47

This comment has been minimized.

Copy link
@AndreasMadsen

AndreasMadsen Sep 23, 2013

Author Collaborator

@AndreasMadsen browserify and testling aren't on the dependencies list and breaks testing with this set up. Did you have any reason not to include them into devdeps? It would create a weird circular dependency... not sure how that would work.

Alternatively, test set up should be described in the readme.

Ah, that is embarrassing. No there is no reason also as long testling is in devDependencies its not a circular dependency so I doubt it will be an issue.

},
"repository": {
"type": "git",
"url": "git://github.com/alexgorbatchev/node-browser-builtins.git"
Expand All @@ -22,5 +25,8 @@
"buffer-browserify": "0.1.x",
"zlib-browserify": "0.0.x",
"constants-browserify": "0.0.x"
},
"devDependencies": {
"tape": "1.0.x"
}
}
42 changes: 42 additions & 0 deletions test/browserify-transform.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

// This transformer changes the require calls so they don't point to the
// browserify buildins (older version of this module).

var path = require('path');
var util = require('util');
var stream = require('stream');
var buildins = require('../index.js');

function RequireRedirect() {
if (!(this instanceof RequireRedirect)) return new RequireRedirect();
stream.Transform.call(this);
this.buffers = [];
}
module.exports = RequireRedirect;
util.inherits(RequireRedirect, stream.Transform);

RequireRedirect.prototype._transform = function (chunk, encoding, done) {
this.buffers.push(chunk);
done(null);
};

// NOTE: this is an incomplete require RegExp, but for internal use here
// its fine.
var REQUIRE_REGEX = /require\((?:"|')([^"']+)(?:"|')\)/g;

var RELATIVE_DIR = path.resolve(__dirname, '..');

RequireRedirect.prototype._flush = function (done) {
var file = Buffer.concat(this.buffers).toString();

file = file.replace(REQUIRE_REGEX, function (source, name) {
if (buildins.hasOwnProperty(name)) {
return "require('" + buildins[name] + "')";
} else {
return source;
}
});

this.push(file);
done(null);
};

0 comments on commit cc9683b

Please sign in to comment.