Welcome to mirror list, hosted at ThFree Co, Russian Federation.

lookup-files.spec.js « acceptance « test « mocha-3.1.0 « lib « tests - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5d4a48d8af2644a704134ca86b2332a1a0dd93a5 (plain)
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
90
'use strict';

var utils = require('../../lib/utils');
var fs = require('fs');
var path = require('path');
var os = require('os');
var mkdirp = require('mkdirp');
var rimraf = require('rimraf');

describe('lookupFiles', function() {
  var tmpDir = path.join(os.tmpDir(), 'mocha-lookup-files');
  var existsSync = fs.existsSync;
  var tmpFile = path.join.bind(path, tmpDir);
  var symlinkSupported = false;

  (function testSymlinkSupport() {
    makeTempDir();

    fs.writeFileSync(tmpFile('mocha-utils.js'), 'yippy skippy ying yang yow');
    try {
      fs.symlinkSync(tmpFile('mocha-utils.js'), tmpFile('mocha-utils-link.js'));
      symlinkSupported = true;
    } catch (ignored) {
      // ignored
    } finally {
      removeTempDir();
    }
  }());

  beforeEach(function() {
    makeTempDir();

    fs.writeFileSync(tmpFile('mocha-utils.js'), 'yippy skippy ying yang yow');
    if (symlinkSupported) {
      fs.symlinkSync(tmpFile('mocha-utils.js'), tmpFile('mocha-utils-link.js'));
    }
  });

  (symlinkSupported ? it : it.skip)('should not choke on symlinks', function() {
    expect(utils.lookupFiles(tmpDir, ['js'], false))
      .to
      .contain(tmpFile('mocha-utils-link.js'))
      .and
      .contain(tmpFile('mocha-utils.js'))
      .and
      .have
      .length(2);
    expect(existsSync(tmpFile('mocha-utils-link.js')))
      .to
      .be(true);
    fs.renameSync(tmpFile('mocha-utils.js'), tmpFile('bob'));
    expect(existsSync(tmpFile('mocha-utils-link.js')))
      .to
      .be(false);
    expect(utils.lookupFiles(tmpDir, ['js'], false))
      .to
      .eql([]);
  });

  it('should accept a glob "path" value', function() {
    var res = utils.lookupFiles(tmpFile('mocha-utils*'), ['js'], false)
      .map(path.normalize.bind(path));

    var expectedLength = 0;
    var ex = expect(res)
      .to
      .contain(tmpFile('mocha-utils.js'));
    expectedLength++;

    if (symlinkSupported) {
      ex = ex.and
        .contain(tmpFile('mocha-utils-link.js'));
      expectedLength++;
    }

    ex.and
      .have
      .length(expectedLength);
  });

  afterEach(removeTempDir);

  function makeTempDir() {
    mkdirp.sync(tmpDir);
  }

  function removeTempDir() {
    rimraf.sync(tmpDir);
  }
});