Sha256: ed72eedf0a7553a8a2ac24403ce01e649febd9be33b9fa17e998e09d538dc178

Contents?: true

Size: 1.46 KB

Versions: 26

Compression:

Stored size: 1.46 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) {
                return files.hasOwnProperty(file)
            },
            readFileSync : function (file) {
                return files[file]
            }
        }
    }
    
    t.equal(
        resolve.sync('./baz', opts('/foo/bar')),
        '/foo/bar/baz.js'
    );
    
    t.equal(
        resolve.sync('./baz.js', opts('/foo/bar')),
        '/foo/bar/baz.js'
    );
    
    t.throws(function () {
        resolve.sync('baz', opts('/foo/bar'));
    });

    t.throws(function () {
        resolve.sync('../baz', opts('/foo/bar'));
    });
});

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) {
                return files.hasOwnProperty(file)
            },
            readFileSync : function (file) {
                return files[file]
            }
        }
    }
    
    t.equal(
        resolve.sync('bar', opts('/foo')),
        '/foo/node_modules/bar/baz.js'
    );
});

Version data entries

26 entries across 16 versions & 5 rubygems

Version Path
entangled-0.0.16 spec/dummy/public/node_modules/grunt-cli/node_modules/resolve/test/mock_sync.js
entangled-0.0.15 spec/dummy/public/node_modules/grunt-cli/node_modules/resolve/test/mock_sync.js
entangled-0.0.14 spec/dummy/public/node_modules/grunt-cli/node_modules/resolve/test/mock_sync.js
entangled-0.0.13 spec/dummy/public/node_modules/grunt-cli/node_modules/resolve/test/mock_sync.js
entangled-0.0.12 spec/dummy/public/node_modules/grunt-cli/node_modules/resolve/test/mock_sync.js
entangled-0.0.11 spec/dummy/public/node_modules/grunt-cli/node_modules/resolve/test/mock_sync.js
entangled-0.0.10 spec/dummy/public/node_modules/grunt-cli/node_modules/resolve/test/mock_sync.js
trans-0.5.10 template/node_modules/gulp/node_modules/liftoff/node_modules/resolve/test/mock_sync.js
trans-0.5.9 template/node_modules/gulp/node_modules/liftoff/node_modules/resolve/test/mock_sync.js
sprockets-browserify-0.3.0 node_modules/browserify/node_modules/module-deps/node_modules/resolve/test/mock_sync.js
sprockets-browserify-0.3.0 node_modules/browserify/node_modules/browser-resolve/node_modules/resolve/test/mock_sync.js
sprockets-browserify-0.3.0 node_modules/browserify/node_modules/umd/node_modules/rfile/node_modules/resolve/test/mock_sync.js
cssesc-source-0.1.0 vendor/node_modules/istanbul/node_modules/resolve/test/mock_sync.js
sprockets-browserify-0.2.0 node_modules/browserify/node_modules/umd/node_modules/rfile/node_modules/resolve/test/mock_sync.js
sprockets-browserify-0.2.0 node_modules/browserify/node_modules/module-deps/node_modules/resolve/test/mock_sync.js
sprockets-browserify-0.2.0 node_modules/browserify/node_modules/browser-resolve/node_modules/resolve/test/mock_sync.js
ruby-wisp-source-0.8.0 vendor/node_modules/browserify/node_modules/browser-resolve/node_modules/resolve/test/mock_sync.js
ruby-wisp-source-0.8.0 vendor/node_modules/browserify/node_modules/module-deps/node_modules/resolve/test/mock_sync.js
ruby-wisp-source-0.8.0 vendor/node_modules/browserify/node_modules/umd/node_modules/rfile/node_modules/resolve/test/mock_sync.js
ruby-wisp-source-0.7.0 vendor/node_modules/browserify/node_modules/browser-resolve/node_modules/resolve/test/mock_sync.js