Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

passing "new" test

  • Loading branch information...
commit 9470f18f7b218ac3e184433222ee8103e3c11ba7 1 parent 49d382d
@substack authored
Showing with 87 additions and 0 deletions.
  1. +54 −0 test/multifile.js
  2. +23 −0 test/new.js
  3. +10 −0 test/sources/new.js
View
54 test/multifile.js
@@ -0,0 +1,54 @@
+var fritter = require('../');
+var test = require('tap').test;
+var path = require('path');
+var fs = require('fs');
+var vm = require('vm');
+
+var files = [ 'b.js', 'a.js' ].map(function (name) {
+ return fs.readFileSync(__dirname + '/sources/multifile/' + name, 'utf8');
+});
+
+test('multifile', function (t) {
+ t.plan(4);
+
+ var modules = {};
+ var fry = fritter({
+ require : function (name) {
+ return modules[name];
+ },
+ define : function (name, fn) {
+ modules[name] = {};
+ process.nextTick(function () {
+ fn(modules[name]);
+ });
+ },
+ setTimeout : setTimeout
+ }, { longStacks : true });
+ fry.include(files[0], { filename : './b.js' });
+ fry.include(files[1], { filename : './a.js' });
+
+ var src = ['./b.js','./a.js'].map(function (name,ix) {
+ return 'define(' + JSON.stringify(name) + ',function (exports){'
+ + fry.sources[ix]
+ + '})'
+ ;
+ }).join(';');
+
+ fry.on('error', function (err, c) {
+ t.equal(err, 'beep boop');
+ t.equal(c.current.filename, './b.js');
+
+ t.deepEqual(
+ c.stack.map(function (s) {
+ return s.filename + ':' + (fry.nameOf(s) || '');
+ }),
+ [ './b.js:', './b.js:setTimeout', './b.js:zzz',
+ './a.js:setTimeout', './a.js:' ]
+ );
+ });
+
+ process.on('uncaughtException', function (err) {
+ t.equal(err, 'beep boop');
+ });
+ vm.runInNewContext(src, fry.context);
+});
View
23 test/new.js
@@ -0,0 +1,23 @@
+var fritter = require('../');
+var vm = require('vm');
+var test = require('tap').test;
+
+var fs = require('fs');
+var src = fs.readFileSync(__dirname + '/sources/new.js', 'utf8');
+
+test('new', function (t) {
+ var context = { module : { exports : {} } };
+ var fry = fritter(src, context);
+
+ process.nextTick(function () {
+ var doom = context.module.exports;
+ t.equal(doom(3).gloom(10), 13);
+ t.end();
+ });
+
+ fry.on('error', function (err, c) {
+ fry.stop();
+ t.fail(err);
+ });
+ vm.runInNewContext(fry.source, fry.context);
+});
View
10 test/sources/new.js
@@ -0,0 +1,10 @@
+module.exports = Doom;
+
+function Doom (obj) {
+ if (!(this instanceof Doom)) return new Doom(obj);
+ this.value = obj;
+}
+
+Doom.prototype.gloom = function (n) {
+ return this.value + n;
+};
Please sign in to comment.
Something went wrong with that request. Please try again.