buddy

node MVC discord bot
Log | Files | Refs | README

resolver_sync.js (3862B)


      1 var test = require('tape');
      2 var resolve = require('../');
      3 
      4 test('foo', function (t) {
      5     var dir = __dirname + '/resolver';
      6     
      7     t.equal(
      8         resolve.sync('./foo', { basedir : dir }),
      9         dir + '/foo.js'
     10     );
     11     
     12     t.equal(
     13         resolve.sync('./foo.js', { basedir : dir }),
     14         dir + '/foo.js'
     15     );
     16     
     17     t.throws(function () {
     18         resolve.sync('foo', { basedir : dir });
     19     });
     20     
     21     t.end();
     22 });
     23 
     24 test('bar', function (t) {
     25     var dir = __dirname + '/resolver';
     26     
     27     t.equal(
     28         resolve.sync('foo', { basedir : dir + '/bar' }),
     29         dir + '/bar/node_modules/foo/index.js'
     30     );
     31     t.end();
     32 });
     33 
     34 test('baz', function (t) {
     35     var dir = __dirname + '/resolver';
     36     
     37     t.equal(
     38         resolve.sync('./baz', { basedir : dir }),
     39         dir + '/baz/quux.js'
     40     );
     41     t.end();
     42 });
     43 
     44 test('biz', function (t) {
     45     var dir = __dirname + '/resolver/biz/node_modules';
     46     t.equal(
     47         resolve.sync('./grux', { basedir : dir }),
     48         dir + '/grux/index.js'
     49     );
     50     
     51     t.equal(
     52         resolve.sync('tiv', { basedir : dir + '/grux' }),
     53         dir + '/tiv/index.js'
     54     );
     55     
     56     t.equal(
     57         resolve.sync('grux', { basedir : dir + '/tiv' }),
     58         dir + '/grux/index.js'
     59     );
     60     t.end();
     61 });
     62 
     63 test('normalize', function (t) {
     64     var dir = __dirname + '/resolver/biz/node_modules/grux';
     65     t.equal(
     66         resolve.sync('../grux', { basedir : dir }),
     67         dir + '/index.js'
     68     );
     69     t.end();
     70 });
     71 
     72 test('cup', function (t) {
     73     var dir = __dirname + '/resolver';
     74     t.equal(
     75         resolve.sync('./cup', {
     76             basedir : dir,
     77             extensions : [ '.js', '.coffee' ]
     78         }),
     79         dir + '/cup.coffee'
     80     );
     81     
     82     t.equal(
     83         resolve.sync('./cup.coffee', {
     84             basedir : dir
     85         }),
     86         dir + '/cup.coffee'
     87     );
     88     
     89     t.throws(function () {
     90         resolve.sync('./cup', {
     91             basedir : dir,
     92             extensions : [ '.js' ]
     93         })
     94     });
     95     
     96     t.end();
     97 });
     98 
     99 test('mug', function (t) {
    100     var dir = __dirname + '/resolver';
    101     t.equal(
    102         resolve.sync('./mug', { basedir : dir }),
    103         dir + '/mug.js'
    104     );
    105     
    106     t.equal(
    107         resolve.sync('./mug', {
    108             basedir : dir,
    109             extensions : [ '.coffee', '.js' ]
    110         }),
    111         dir + '/mug.coffee'
    112     );
    113     
    114     t.equal(
    115         resolve.sync('./mug', {
    116             basedir : dir,
    117             extensions : [ '.js', '.coffee' ]
    118         }),
    119         dir + '/mug.js'
    120     );
    121     
    122     t.end();
    123 });
    124 
    125 test('other path', function (t) {
    126     var resolverDir = __dirname + '/resolver';
    127     var dir = resolverDir + '/bar';
    128     var otherDir = resolverDir + '/other_path';
    129 
    130     var path = require('path');
    131     
    132     t.equal(
    133         resolve.sync('root', {
    134             basedir : dir,
    135             paths: [otherDir] }),
    136         resolverDir + '/other_path/root.js'
    137     );
    138     
    139     t.equal(
    140         resolve.sync('lib/other-lib', {
    141             basedir : dir,
    142             paths: [otherDir] }),
    143         resolverDir + '/other_path/lib/other-lib.js'
    144     );
    145 
    146     t.throws(function () {
    147         resolve.sync('root', { basedir : dir, });
    148     });
    149     
    150     t.throws(function () {
    151         resolve.sync('zzz', {
    152             basedir : dir,
    153             paths: [otherDir] });
    154     });
    155     
    156     t.end();
    157 });
    158 
    159 test('incorrect main', function (t) {
    160     var resolverDir = __dirname + '/resolver';
    161     var dir = resolverDir + '/incorrect_main';
    162 
    163     t.equal(
    164         resolve.sync('./incorrect_main', { basedir : resolverDir }),
    165         dir + '/index.js'
    166     )
    167 
    168     t.end()
    169 });
    170 
    171 test('#25: node modules with the same name as node stdlib modules', function (t) {
    172     var resolverDir = __dirname + '/resolver/punycode';
    173 
    174     t.equal(
    175         resolve.sync('punycode', { basedir : resolverDir }),
    176         resolverDir + '/node_modules/punycode/index.js'
    177     )
    178 
    179     t.end()
    180 });