aboutsummaryrefslogtreecommitdiff
path: root/node_modules/resolve/test/resolver_sync.js
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2017-05-28 00:38:50 +0200
committerFlorian Dold <florian.dold@gmail.com>2017-05-28 00:40:43 +0200
commit7fff4499fd915bcea3fa93b1aa8b35f4fe7a6027 (patch)
tree6de9a1aebd150a23b7f8c273ec657a5d0a18fe3e /node_modules/resolve/test/resolver_sync.js
parent963b7a41feb29cc4be090a2446bdfe0c1f1bcd81 (diff)
add linting (and some initial fixes)
Diffstat (limited to 'node_modules/resolve/test/resolver_sync.js')
-rw-r--r--node_modules/resolve/test/resolver_sync.js241
1 files changed, 157 insertions, 84 deletions
diff --git a/node_modules/resolve/test/resolver_sync.js b/node_modules/resolve/test/resolver_sync.js
index 598253171..2bc361020 100644
--- a/node_modules/resolve/test/resolver_sync.js
+++ b/node_modules/resolve/test/resolver_sync.js
@@ -1,180 +1,253 @@
+var path = require('path');
var test = require('tape');
var resolve = require('../');
test('foo', function (t) {
- var dir = __dirname + '/resolver';
-
+ var dir = path.join(__dirname, 'resolver');
+
t.equal(
- resolve.sync('./foo', { basedir : dir }),
- dir + '/foo.js'
+ resolve.sync('./foo', { basedir: dir }),
+ path.join(dir, 'foo.js')
);
-
+
t.equal(
- resolve.sync('./foo.js', { basedir : dir }),
- dir + '/foo.js'
+ resolve.sync('./foo.js', { basedir: dir }),
+ path.join(dir, 'foo.js')
);
-
+
t.throws(function () {
- resolve.sync('foo', { basedir : dir });
+ resolve.sync('foo', { basedir: dir });
});
-
+
t.end();
});
test('bar', function (t) {
- var dir = __dirname + '/resolver';
-
+ var dir = path.join(__dirname, 'resolver');
+
t.equal(
- resolve.sync('foo', { basedir : dir + '/bar' }),
- dir + '/bar/node_modules/foo/index.js'
+ resolve.sync('foo', { basedir: path.join(dir, 'bar') }),
+ path.join(dir, 'bar/node_modules/foo/index.js')
);
t.end();
});
test('baz', function (t) {
- var dir = __dirname + '/resolver';
-
+ var dir = path.join(__dirname, 'resolver');
+
t.equal(
- resolve.sync('./baz', { basedir : dir }),
- dir + '/baz/quux.js'
+ resolve.sync('./baz', { basedir: dir }),
+ path.join(dir, 'baz/quux.js')
);
t.end();
});
test('biz', function (t) {
- var dir = __dirname + '/resolver/biz/node_modules';
+ var dir = path.join(__dirname, 'resolver/biz/node_modules');
t.equal(
- resolve.sync('./grux', { basedir : dir }),
- dir + '/grux/index.js'
+ resolve.sync('./grux', { basedir: dir }),
+ path.join(dir, 'grux/index.js')
);
-
+
t.equal(
- resolve.sync('tiv', { basedir : dir + '/grux' }),
- dir + '/tiv/index.js'
+ resolve.sync('tiv', { basedir: path.join(dir, 'grux') }),
+ path.join(dir, 'tiv/index.js')
);
-
+
t.equal(
- resolve.sync('grux', { basedir : dir + '/tiv' }),
- dir + '/grux/index.js'
+ resolve.sync('grux', { basedir: path.join(dir, 'tiv') }),
+ path.join(dir, 'grux/index.js')
);
t.end();
});
test('normalize', function (t) {
- var dir = __dirname + '/resolver/biz/node_modules/grux';
+ var dir = path.join(__dirname, 'resolver/biz/node_modules/grux');
t.equal(
- resolve.sync('../grux', { basedir : dir }),
- dir + '/index.js'
+ resolve.sync('../grux', { basedir: dir }),
+ path.join(dir, 'index.js')
);
t.end();
});
test('cup', function (t) {
- var dir = __dirname + '/resolver';
+ var dir = path.join(__dirname, 'resolver');
t.equal(
resolve.sync('./cup', {
- basedir : dir,
- extensions : [ '.js', '.coffee' ]
+ basedir: dir,
+ extensions: ['.js', '.coffee']
}),
- dir + '/cup.coffee'
+ path.join(dir, 'cup.coffee')
);
-
+
t.equal(
- resolve.sync('./cup.coffee', {
- basedir : dir
- }),
- dir + '/cup.coffee'
+ resolve.sync('./cup.coffee', { basedir: dir }),
+ path.join(dir, 'cup.coffee')
);
-
+
t.throws(function () {
resolve.sync('./cup', {
- basedir : dir,
- extensions : [ '.js' ]
- })
+ basedir: dir,
+ extensions: ['.js']
+ });
});
-
+
t.end();
});
test('mug', function (t) {
- var dir = __dirname + '/resolver';
+ var dir = path.join(__dirname, 'resolver');
t.equal(
- resolve.sync('./mug', { basedir : dir }),
- dir + '/mug.js'
+ resolve.sync('./mug', { basedir: dir }),
+ path.join(dir, 'mug.js')
);
-
+
t.equal(
resolve.sync('./mug', {
- basedir : dir,
- extensions : [ '.coffee', '.js' ]
+ basedir: dir,
+ extensions: ['.coffee', '.js']
}),
- dir + '/mug.coffee'
+ path.join(dir, 'mug.coffee')
);
-
+
t.equal(
resolve.sync('./mug', {
- basedir : dir,
- extensions : [ '.js', '.coffee' ]
+ basedir: dir,
+ extensions: ['.js', '.coffee']
}),
- dir + '/mug.js'
+ path.join(dir, 'mug.js')
);
-
+
t.end();
});
test('other path', function (t) {
- var resolverDir = __dirname + '/resolver';
- var dir = resolverDir + '/bar';
- var otherDir = resolverDir + '/other_path';
+ var resolverDir = path.join(__dirname, 'resolver');
+ var dir = path.join(resolverDir, 'bar');
+ var otherDir = path.join(resolverDir, 'other_path');
- var path = require('path');
-
t.equal(
resolve.sync('root', {
- basedir : dir,
- paths: [otherDir] }),
- resolverDir + '/other_path/root.js'
+ basedir: dir,
+ paths: [otherDir]
+ }),
+ path.join(resolverDir, 'other_path/root.js')
);
-
+
t.equal(
resolve.sync('lib/other-lib', {
- basedir : dir,
- paths: [otherDir] }),
- resolverDir + '/other_path/lib/other-lib.js'
+ basedir: dir,
+ paths: [otherDir]
+ }),
+ path.join(resolverDir, 'other_path/lib/other-lib.js')
);
t.throws(function () {
- resolve.sync('root', { basedir : dir, });
+ resolve.sync('root', { basedir: dir });
});
-
+
t.throws(function () {
resolve.sync('zzz', {
- basedir : dir,
- paths: [otherDir] });
+ basedir: dir,
+ paths: [otherDir]
+ });
});
-
+
t.end();
});
test('incorrect main', function (t) {
- var resolverDir = __dirname + '/resolver';
- var dir = resolverDir + '/incorrect_main';
+ var resolverDir = path.join(__dirname, 'resolver');
+ var dir = path.join(resolverDir, 'incorrect_main');
t.equal(
- resolve.sync('./incorrect_main', { basedir : resolverDir }),
- dir + '/index.js'
- )
+ resolve.sync('./incorrect_main', { basedir: resolverDir }),
+ path.join(dir, 'index.js')
+ );
- t.end()
+ t.end();
});
test('#25: node modules with the same name as node stdlib modules', function (t) {
- var resolverDir = __dirname + '/resolver/punycode';
+ var resolverDir = path.join(__dirname, 'resolver/punycode');
+
+ t.equal(
+ resolve.sync('punycode', { basedir: resolverDir }),
+ path.join(resolverDir, 'node_modules/punycode/index.js')
+ );
+
+ t.end();
+});
+
+var stubStatSync = function stubStatSync(fn) {
+ var fs = require('fs');
+ var statSync = fs.statSync;
+ try {
+ fs.statSync = function () {
+ throw new EvalError('Unknown Error');
+ };
+ return fn();
+ } finally {
+ fs.statSync = statSync;
+ }
+};
+
+test('#79 - re-throw non ENOENT errors from stat', function (t) {
+ var dir = path.join(__dirname, 'resolver');
+
+ stubStatSync(function () {
+ t.throws(function () {
+ resolve.sync('foo', { basedir: dir });
+ }, /Unknown Error/);
+ });
+ t.end();
+});
+
+test('#52 - incorrectly resolves module-paths like "./someFolder/" when there is a file of the same name', function (t) {
+ var dir = path.join(__dirname, 'resolver');
+
+ t.equal(
+ resolve.sync('./foo', { basedir: path.join(dir, 'same_names') }),
+ path.join(dir, 'same_names/foo.js')
+ );
t.equal(
- resolve.sync('punycode', { basedir : resolverDir }),
- resolverDir + '/node_modules/punycode/index.js'
- )
+ resolve.sync('./foo/', { basedir: path.join(dir, 'same_names') }),
+ path.join(dir, 'same_names/foo/index.js')
+ );
+ t.end();
+});
+
+test('sync: #121 - treating an existing file as a dir when no basedir', function (t) {
+ var testFile = path.basename(__filename);
+
+ t.test('sanity check', function (st) {
+ st.equal(
+ resolve.sync('./' + testFile),
+ __filename,
+ 'sanity check'
+ );
+ st.end();
+ });
- t.end()
+ t.test('with a fake directory', function (st) {
+ function run() { return resolve.sync('./' + testFile + '/blah'); }
+
+ st.throws(run, 'throws an error');
+
+ try {
+ run();
+ } catch (e) {
+ st.equal(e.code, 'MODULE_NOT_FOUND', 'error code matches require.resolve');
+ st.equal(
+ e.message,
+ 'Cannot find module \'./' + testFile + '/blah\' from \'' + __dirname + '\'',
+ 'can not find nonexistent module'
+ );
+ }
+
+ st.end();
+ });
+
+ t.end();
});