File: test.js

package info (click to toggle)
node-is-directory 0.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 116 kB
  • sloc: makefile: 7; sh: 2
file content (89 lines) | stat: -rw-r--r-- 2,375 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
'use strict';

require('mocha');
var assert = require('assert');
var isDirectory = require('./');

describe('isDirectory', function() {
  describe('async errors:', function() {
    it('should throw an error when the callback is missing:', function(cb) {
      try {
        isDirectory('foo');
        cb(new Error('expected an error'));
      } catch (err) {
        assert.equal(err.message, 'expected a callback function');
        cb();
      }
    });

    it('should handle errors for bad args', function(cb) {
      isDirectory(null, function(err) {
        assert(err);
        assert.equal(err.message, 'expected filepath to be a string');
        cb();
      });
    });
  });

  describe('async', function() {
    it('should return `true` if the path is a directory', function(cb) {
      isDirectory('node_modules', function(err, dir) {
        if (err) return cb(err);
        assert(dir);
        cb();
      });
    });

    it('should be true when a path is a directory', function(cb) {
      isDirectory('fixtures', function(err, dir) {
        if (err) return cb(err);
        assert(dir);
        cb();
      });
    });

    it('should be false for files that do not exist', function(cb) {
      isDirectory('fee-fie-foe', function(err, dir) {
        if (err) return cb(err);
        assert(!dir);
        cb();
      });
    });

    it('should be `false` if the path is not a directory', function(cb) {
      isDirectory('.eslintrc.json', function(err, dir) {
        if (err) return cb(err);
        assert(!dir);

        isDirectory('README.md', function(err, dir) {
          if (err) return cb(err);
          assert(!dir);
          cb();
        });
      });
    });
  });

  describe('sync', function() {
    it('should throw when invalid arguments are given', function(cb) {
      try {
        isDirectory.sync();
        cb(new Error('expected an error'));
      } catch (err) {
        assert.equal(err.message, 'expected filepath to be a string');
        cb();
      }
    });

    it('should return `true` if the path is a directory', function() {
      assert(isDirectory.sync('node_modules'));
    });

    it('should return `false` if the path is not a directory', function() {
      assert(!isDirectory.sync('.jshintrc'));
      assert(!isDirectory.sync('README.md'));
      assert(!isDirectory.sync('LICENSE'));
    });
  });
});