mocha 5.0.1 → 5.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/utils.js CHANGED
@@ -1,21 +1,14 @@
1
1
  'use strict';
2
2
 
3
- /* eslint-env browser */
4
-
5
3
  /**
6
4
  * Module dependencies.
7
5
  */
8
6
 
9
- var basename = require('path').basename;
10
7
  var debug = require('debug')('mocha:watch');
11
- var exists = require('fs').existsSync;
8
+ var fs = require('fs');
12
9
  var glob = require('glob');
13
10
  var path = require('path');
14
11
  var join = path.join;
15
- var readdirSync = require('fs').readdirSync;
16
- var statSync = require('fs').statSync;
17
- var watchFile = require('fs').watchFile;
18
- var lstatSync = require('fs').lstatSync;
19
12
  var he = require('he');
20
13
 
21
14
  /**
@@ -60,7 +53,7 @@ exports.watch = function (files, fn) {
60
53
  var options = { interval: 100 };
61
54
  files.forEach(function (file) {
62
55
  debug('file %s', file);
63
- watchFile(file, options, function (curr, prev) {
56
+ fs.watchFile(file, options, function (curr, prev) {
64
57
  if (prev.mtime < curr.mtime) {
65
58
  fn(file);
66
59
  }
@@ -94,11 +87,11 @@ exports.files = function (dir, ext, ret) {
94
87
 
95
88
  var re = new RegExp('\\.(' + ext.join('|') + ')$');
96
89
 
97
- readdirSync(dir)
90
+ fs.readdirSync(dir)
98
91
  .filter(ignored)
99
92
  .forEach(function (path) {
100
93
  path = join(dir, path);
101
- if (lstatSync(path).isDirectory()) {
94
+ if (fs.lstatSync(path).isDirectory()) {
102
95
  exports.files(path, ext, ret);
103
96
  } else if (path.match(re)) {
104
97
  ret.push(path);
@@ -469,40 +462,40 @@ exports.canonicalize = function canonicalize (value, stack, typeHint) {
469
462
  * Lookup file names at the given `path`.
470
463
  *
471
464
  * @api public
472
- * @param {string} path Base path to start searching from.
465
+ * @param {string} filepath Base path to start searching from.
473
466
  * @param {string[]} extensions File extensions to look for.
474
467
  * @param {boolean} recursive Whether or not to recurse into subdirectories.
475
468
  * @return {string[]} An array of paths.
476
469
  */
477
- exports.lookupFiles = function lookupFiles (path, extensions, recursive) {
470
+ exports.lookupFiles = function lookupFiles (filepath, extensions, recursive) {
478
471
  var files = [];
479
472
 
480
- if (!exists(path)) {
481
- if (exists(path + '.js')) {
482
- path += '.js';
473
+ if (!fs.existsSync(filepath)) {
474
+ if (fs.existsSync(filepath + '.js')) {
475
+ filepath += '.js';
483
476
  } else {
484
- files = glob.sync(path);
477
+ files = glob.sync(filepath);
485
478
  if (!files.length) {
486
- throw new Error("cannot resolve path (or pattern) '" + path + "'");
479
+ throw new Error("cannot resolve path (or pattern) '" + filepath + "'");
487
480
  }
488
481
  return files;
489
482
  }
490
483
  }
491
484
 
492
485
  try {
493
- var stat = statSync(path);
486
+ var stat = fs.statSync(filepath);
494
487
  if (stat.isFile()) {
495
- return path;
488
+ return filepath;
496
489
  }
497
490
  } catch (err) {
498
491
  // ignore error
499
492
  return;
500
493
  }
501
494
 
502
- readdirSync(path).forEach(function (file) {
503
- file = join(path, file);
495
+ fs.readdirSync(filepath).forEach(function (file) {
496
+ file = path.join(filepath, file);
504
497
  try {
505
- var stat = statSync(file);
498
+ var stat = fs.statSync(file);
506
499
  if (stat.isDirectory()) {
507
500
  if (recursive) {
508
501
  files = files.concat(lookupFiles(file, extensions, recursive));
@@ -514,7 +507,7 @@ exports.lookupFiles = function lookupFiles (path, extensions, recursive) {
514
507
  return;
515
508
  }
516
509
  var re = new RegExp('\\.(?:' + extensions.join('|') + ')$');
517
- if (!stat.isFile() || !re.test(file) || basename(file)[0] === '.') {
510
+ if (!stat.isFile() || !re.test(file) || path.basename(file)[0] === '.') {
518
511
  return;
519
512
  }
520
513
  files.push(file);
@@ -597,7 +590,7 @@ exports.stackTraceFilter = function () {
597
590
 
598
591
  // Clean up cwd(absolute)
599
592
  if (/\(?.+:\d+:\d+\)?$/.test(line)) {
600
- line = line.replace(cwd, '');
593
+ line = line.replace('(' + cwd, '(');
601
594
  }
602
595
 
603
596
  list.push(line);