Sha256: 34aa1c42736ccca23ebedd48758b0bf64797541a4757fcb4cbeb8a76cdd3be63

Contents?: true

Size: 1.7 KB

Versions: 19

Compression:

Stored size: 1.7 KB

Contents

var test = require('tap').test;
var resolve = require('../');

test('mock', function (t) {
    t.plan(4);
    
    var files = {
        '/foo/bar/baz.js' : 'beep'
    };
    
    function opts (basedir) {
        return {
            basedir : basedir,
            isFile : function (file, cb) {
                cb(null, files.hasOwnProperty(file));
            },
            readFile : function (file, cb) {
                cb(null, files[file]);
            }
        }
    }
    
    resolve('./baz', opts('/foo/bar'), function (err, res) {
        if (err) t.fail(err);
        t.equal(res, '/foo/bar/baz.js');
    });
    
    resolve('./baz.js', opts('/foo/bar'), function (err, res) {
        if (err) t.fail(err);
        t.equal(res, '/foo/bar/baz.js');
    });
    
    resolve('baz', opts('/foo/bar'), function (err, res) {
        t.equal(err.message, "Cannot find module 'baz'");
    });
    
    resolve('../baz', opts('/foo/bar'), function (err, res) {
        t.equal(err.message, "Cannot find module '../baz'");
    });
});

test('mock package', function (t) {
    t.plan(1);
    
    var files = {
        '/foo/node_modules/bar/baz.js' : 'beep',
        '/foo/node_modules/bar/package.json' : JSON.stringify({
            main : './baz.js'
        })
    };
    
    function opts (basedir) {
        return {
            basedir : basedir,
            isFile : function (file, cb) {
                cb(null, files.hasOwnProperty(file));
            },
            readFile : function (file, cb) {
                cb(null, files[file]);
            }
        }
    }
    
    resolve('bar', opts('/foo'), function (err, res) {
        if (err) t.fail(err);
        t.equal(res, '/foo/node_modules/bar/baz.js');
    });
});

Version data entries

19 entries across 13 versions & 3 rubygems

Version Path
entangled-0.0.16 spec/dummy/public/node_modules/grunt-cli/node_modules/resolve/test/mock.js
entangled-0.0.15 spec/dummy/public/node_modules/grunt-cli/node_modules/resolve/test/mock.js
entangled-0.0.14 spec/dummy/public/node_modules/grunt-cli/node_modules/resolve/test/mock.js
entangled-0.0.13 spec/dummy/public/node_modules/grunt-cli/node_modules/resolve/test/mock.js
entangled-0.0.12 spec/dummy/public/node_modules/grunt-cli/node_modules/resolve/test/mock.js
entangled-0.0.11 spec/dummy/public/node_modules/grunt-cli/node_modules/resolve/test/mock.js
entangled-0.0.10 spec/dummy/public/node_modules/grunt-cli/node_modules/resolve/test/mock.js
sprockets-browserify-0.3.0 node_modules/browserify/node_modules/umd/node_modules/rfile/node_modules/resolve/test/mock.js
sprockets-browserify-0.2.0 node_modules/browserify/node_modules/browser-resolve/node_modules/resolve/test/mock.js
sprockets-browserify-0.2.0 node_modules/browserify/node_modules/umd/node_modules/rfile/node_modules/resolve/test/mock.js
sprockets-browserify-0.2.0 node_modules/browserify/node_modules/module-deps/node_modules/resolve/test/mock.js
ruby-wisp-source-0.8.0 vendor/node_modules/browserify/node_modules/browser-resolve/node_modules/resolve/test/mock.js
ruby-wisp-source-0.8.0 vendor/node_modules/browserify/node_modules/module-deps/node_modules/resolve/test/mock.js
ruby-wisp-source-0.8.0 vendor/node_modules/browserify/node_modules/umd/node_modules/rfile/node_modules/resolve/test/mock.js
ruby-wisp-source-0.7.0 vendor/node_modules/browserify/node_modules/umd/node_modules/rfile/node_modules/resolve/test/mock.js
ruby-wisp-source-0.7.0 vendor/node_modules/browserify/node_modules/module-deps/node_modules/resolve/test/mock.js
ruby-wisp-source-0.7.0 vendor/node_modules/browserify/node_modules/browser-resolve/node_modules/resolve/test/mock.js
sprockets-browserify-0.1.2 node_modules/module-deps/node_modules/resolve/test/mock.js
sprockets-browserify-0.1.0 node_modules/module-deps/node_modules/resolve/test/mock.js