Sha256: 800e71f76d6e6e4fd8d9446761ab7413f09539a54f135d64cc971522a7793f5f

Contents?: true

Size: 1.46 KB

Versions: 7

Compression:

Stored size: 1.46 KB

Contents

var test = require('tape');
var vm = require('vm');
var concat = require('concat-stream');

var insert = require('../');
var bpack = require('browser-pack');
var mdeps = require('module-deps');

test('insert globals', function (t) {
    var expected = [ 'global' ];
    t.plan(2 + expected.length);
    
    var deps = mdeps()
    var pack = bpack({ raw: true });
    
    deps.pipe(pack);
    
    pack.pipe(concat(function (src) {
        var c = {
            t : t,
            a : 555,
        };
        c.self = c;
        vm.runInNewContext(src, c);
    }));
    
    deps.write({
        transform: function (file) {
            var tr = inserter(file)
            tr.on('global', function (name) {
                t.equal(name, expected.shift());
            });
            return tr;
        },
        global: true
    });
    deps.end(__dirname + '/global/main.js');
});

test('__filename and __dirname', function (t) {
    t.plan(2);
    
    var file = __dirname + '/global/filename.js';
    var deps = mdeps()
    var pack = bpack({ raw: true });
    
    deps.pipe(pack);
    
    pack.pipe(concat(function (src) {
        var c = {};
        vm.runInNewContext('require=' + src, c);
        var x = c.require(file);
        t.equal(x.filename, '/filename.js');
        t.equal(x.dirname, '/');
    }));
    
    deps.write({ transform: inserter, global: true });
    deps.end(file);
});

function inserter (file) {
    return insert(file, { basedir: __dirname + '/global' });
}

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
minimum_viable_product-0.0.11 test/dummy/node_modules/insert-module-globals/test/global.js
brwy_rails-0.0.6 test/dummy/node_modules/insert-module-globals/test/global.js
brwy_rails-0.0.5 test/dummy/node_modules/insert-module-globals/test/global.js
brwy_rails-0.0.4 test/dummy/node_modules/insert-module-globals/test/global.js
brwy_rails-0.0.3 test/dummy/node_modules/insert-module-globals/test/global.js
brwy_rails-0.0.2 test/dummy/node_modules/insert-module-globals/test/global.js
brwy_rails-0.0.1 test/dummy/node_modules/insert-module-globals/test/global.js