gulp-expect-file 1.0.2 → 3.0.0

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/README.md CHANGED
@@ -1,8 +1,8 @@
1
- # gulp-expect-file [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-image]][daviddm-url]
1
+ # gulp-expect-file [![NPM version][npm-image]][npm-url] [![Build Status][gh-image]][gh-url]
2
2
 
3
- > Expectation on generated files for gulp 3/4
3
+ > Expectation on generated files for Gulp 4
4
4
 
5
- This plugin is intended for testing other gulp plugin.
5
+ This plugin is intended for testing other Gulp plugin.
6
6
 
7
7
  ![Screen Shot](http://pioug.github.io/gulp-expect-file/screenshot.png)
8
8
 
@@ -19,11 +19,8 @@ Then, add it to your `gulpfile.js`:
19
19
  ```js
20
20
  var expect = require("gulp-expect-file");
21
21
 
22
- gulp.task("copy", function() {
23
- gulp
24
- .src(["src/foo.txt"])
25
- .pipe(gulp.dest("dest/"))
26
- .pipe(expect("dest/foo.txt"));
22
+ gulp.task("copy", function () {
23
+ gulp.src(["src/foo.txt"]).pipe(gulp.dest("dest/")).pipe(expect("dest/foo.txt"));
27
24
  });
28
25
  ```
29
26
 
@@ -114,9 +111,7 @@ Default: `false`
114
111
  If true, it also checks if the real file exists on the file system by `fs.exists()`.
115
112
 
116
113
  ```js
117
- gulp
118
- .src(["exist.txt", "nonexist.txt"])
119
- .pipe(expect({ checkRealFile: true }, "*.txt"));
114
+ gulp.src(["exist.txt", "nonexist.txt"]).pipe(expect({ checkRealFile: true }, "*.txt"));
120
115
 
121
116
  // => FAIL: nonexist.txt not exists on filesystem
122
117
  ```
@@ -132,7 +127,7 @@ If true, it emits `error` event when expectations got failed.
132
127
  gulp
133
128
  .src(["a.txt"])
134
129
  .pipe(expect({ errorOnFailure: true }, ["b.txt"]))
135
- .on("error", function(err) {
130
+ .on("error", function (err) {
136
131
  console.error(err);
137
132
  });
138
133
  ```
@@ -157,7 +152,5 @@ This is just a shortcut for `expect({ checkRealFile: true }, expectation)`.
157
152
 
158
153
  [npm-url]: https://npmjs.org/package/gulp-expect-file
159
154
  [npm-image]: https://img.shields.io/npm/v/gulp-expect-file.svg
160
- [travis-url]: https://travis-ci.org/pioug/gulp-expect-file
161
- [travis-image]: https://img.shields.io/travis/pioug/gulp-expect-file.svg
162
- [daviddm-url]: https://david-dm.org/pioug/gulp-expect-file
163
- [daviddm-image]: https://img.shields.io/david/pioug/gulp-expect-file.svg
155
+ [gh-url]: https://github.com/pioug/gulp-expect-file/actions/workflows/test.yml
156
+ [gh-image]: https://github.com/pioug/gulp-expect-file/actions/workflows/test.yml/badge.svg
package/index.js CHANGED
@@ -5,17 +5,16 @@ var ExpectationError = require("./lib/errors").ExpectationError;
5
5
  var log = require("fancy-log");
6
6
  var PluginError = require("plugin-error");
7
7
  var through = require("through2");
8
- var xtend = require("xtend");
9
8
  var colors = require("ansi-colors");
10
9
 
11
10
  module.exports = expect;
12
11
 
13
- module.exports.real = function(options, expectation) {
12
+ module.exports.real = function (options, expectation) {
14
13
  if (!expectation) {
15
14
  expectation = options;
16
15
  options = {};
17
16
  }
18
- options = xtend({ checkRealFile: true }, options);
17
+ options = Object.assign({ checkRealFile: true }, options);
19
18
  return expect(options, expectation);
20
19
  };
21
20
 
@@ -28,16 +27,16 @@ function expect(options, expectation) {
28
27
  throw new PluginError("gulp-expect-file", "Expectation required");
29
28
  }
30
29
 
31
- options = xtend(
30
+ options = Object.assign(
32
31
  {
33
32
  reportUnexpected: true,
34
33
  reportMissing: true,
35
34
  checkRealFile: false,
36
35
  errorOnFailure: false,
37
36
  silent: false,
38
- verbose: false
37
+ verbose: false,
39
38
  },
40
- options
39
+ options,
41
40
  );
42
41
 
43
42
  try {
@@ -59,7 +58,7 @@ function expect(options, expectation) {
59
58
  numTests++;
60
59
 
61
60
  var _this = this;
62
- fileTester.test(file, function(err) {
61
+ fileTester.test(file, function (err) {
63
62
  if (err && !options.reportUnexpected) {
64
63
  if (err instanceof ExpectationError && err.message === "unexpected") {
65
64
  err = null;
@@ -95,10 +94,7 @@ function expect(options, expectation) {
95
94
  if (numFailures > 0 && options.errorOnFailure) {
96
95
  this.emit(
97
96
  "error",
98
- new PluginError(
99
- "gulp-expect-file",
100
- "Failed " + numFailures + " expectations"
101
- )
97
+ new PluginError("gulp-expect-file", "Failed " + numFailures + " expectations"),
102
98
  );
103
99
  }
104
100
 
@@ -108,20 +104,13 @@ function expect(options, expectation) {
108
104
 
109
105
  function reportFailure(file, err) {
110
106
  if (err instanceof ExpectationError) {
111
- options.silent ||
112
- log(
113
- colors.red("\u2717 FAIL:"),
114
- colors.magenta(file.relative),
115
- "is",
116
- err.message
117
- );
107
+ if (!options.silent) {
108
+ log(colors.red("\u2717 FAIL:"), colors.magenta(file.relative), "is", err.message);
109
+ }
118
110
  } else {
119
- options.silent ||
120
- log(
121
- colors.red("\u2717 ERROR:"),
122
- colors.magenta(file.relative) + ":",
123
- err.message || err
124
- );
111
+ if (!options.silent) {
112
+ log(colors.red("\u2717 ERROR:"), colors.magenta(file.relative) + ":", err.message || err);
113
+ }
125
114
  }
126
115
  }
127
116
 
@@ -133,7 +122,7 @@ function expect(options, expectation) {
133
122
 
134
123
  function reportMissing(rules) {
135
124
  var missings = rules
136
- .map(function(r) {
125
+ .map(function (r) {
137
126
  return r.toString();
138
127
  })
139
128
  .join(", ");
@@ -143,13 +132,13 @@ function expect(options, expectation) {
143
132
  "Missing",
144
133
  colors.cyan(rules.length),
145
134
  "expected files:",
146
- colors.magenta(missings)
135
+ colors.magenta(missings),
147
136
  );
148
137
  }
149
138
  }
150
139
 
151
140
  function reportSummary() {
152
- options.silent ||
141
+ if (!options.silent) {
153
142
  log(
154
143
  "Tested",
155
144
  colors.cyan(numTests),
@@ -158,8 +147,9 @@ function expect(options, expectation) {
158
147
  "passes,",
159
148
  colors.cyan(numFailures),
160
149
  "failures:",
161
- numFailures > 0 ? colors.bgRed.white("FAIL") : colors.green("PASS")
150
+ numFailures > 0 ? colors.bgRed.white("FAIL") : colors.green("PASS"),
162
151
  );
152
+ }
163
153
  }
164
154
 
165
155
  return through.obj(eachFile, endStream);
@@ -7,13 +7,12 @@ var wrapAssertion = require("./util").wrapAssertion;
7
7
  var Minimatch = require("minimatch").Minimatch;
8
8
  var fs = require("fs");
9
9
  var async = require("async");
10
- var xtend = require("xtend");
11
10
 
12
11
  module.exports = FileTester;
13
12
 
14
13
  function FileTester(expectation, options) {
15
14
  this.rules = parseExpectation(expectation);
16
- this.options = xtend({ checkRealFile: false }, options);
15
+ this.options = Object.assign({ checkRealFile: false }, options);
17
16
  }
18
17
 
19
18
  function parseExpectation(expectation) {
@@ -27,11 +26,8 @@ function parseExpectation(expectation) {
27
26
  case "function":
28
27
  return [new Rule(null, expectation)];
29
28
  case "object":
30
- return Object.keys(expectation).map(function(path) {
31
- return new Rule(
32
- path,
33
- expectation[path] === true ? null : expectation[path]
34
- );
29
+ return Object.keys(expectation).map(function (path) {
30
+ return new Rule(path, expectation[path] === true ? null : expectation[path]);
35
31
  });
36
32
  default:
37
33
  throw new TypeError("Unknown expectation type");
@@ -39,7 +35,7 @@ function parseExpectation(expectation) {
39
35
  }
40
36
 
41
37
  function checkFileExists(file, callback) {
42
- fs.exists(file.path, function(exists) {
38
+ fs.exists(file.path, function (exists) {
43
39
  if (exists) {
44
40
  callback();
45
41
  } else {
@@ -48,19 +44,19 @@ function checkFileExists(file, callback) {
48
44
  });
49
45
  }
50
46
 
51
- FileTester.prototype.test = function(file, callback) {
47
+ FileTester.prototype.test = function (file, callback) {
52
48
  var _this = this;
53
49
  var matchedAny = false;
54
50
  async.eachSeries(
55
51
  this.rules,
56
- function(rule, next) {
52
+ function (rule, next) {
57
53
  if (!rule.matchFilePath(file.relative)) {
58
54
  return next(null);
59
55
  }
60
56
  matchedAny = true;
61
57
  rule.testFile(file, next);
62
58
  },
63
- function(err) {
59
+ function (err) {
64
60
  if (err) {
65
61
  return callback(err);
66
62
  }
@@ -73,12 +69,12 @@ FileTester.prototype.test = function(file, callback) {
73
69
  } else {
74
70
  callback();
75
71
  }
76
- }
72
+ },
77
73
  );
78
74
  };
79
75
 
80
- FileTester.prototype.getUnusedRules = function() {
81
- return this.rules.filter(function(rule) {
76
+ FileTester.prototype.getUnusedRules = function () {
77
+ return this.rules.filter(function (rule) {
82
78
  return !rule.isUsed();
83
79
  });
84
80
  };
@@ -90,7 +86,7 @@ function Rule(path, tester) {
90
86
  this.used = false;
91
87
  }
92
88
 
93
- Rule.prototype.matchFilePath = function(path) {
89
+ Rule.prototype.matchFilePath = function (path) {
94
90
  if (this.minimatch) {
95
91
  return this.minimatch.match(path);
96
92
  } else {
@@ -98,7 +94,7 @@ Rule.prototype.matchFilePath = function(path) {
98
94
  }
99
95
  };
100
96
 
101
- Rule.prototype.testFile = function(file, callback) {
97
+ Rule.prototype.testFile = function (file, callback) {
102
98
  this.used = true;
103
99
  if (this.tester) {
104
100
  this.tester(file, callback);
@@ -107,23 +103,22 @@ Rule.prototype.testFile = function(file, callback) {
107
103
  }
108
104
  };
109
105
 
110
- Rule.prototype.isUsed = function() {
106
+ Rule.prototype.isUsed = function () {
111
107
  return this.used;
112
108
  };
113
109
 
114
- Rule.prototype.toString = function() {
110
+ Rule.prototype.toString = function () {
115
111
  return this.path || "(custom)";
116
112
  };
117
113
 
118
- Rule.wrapTester = function(tester) {
114
+ Rule.wrapTester = function (tester) {
119
115
  if (typeof tester === "function") {
120
116
  return wrapAssertion(tester);
121
117
  }
122
118
 
123
- var stringTester =
124
- tester instanceof StringTester ? tester : new StringTester(tester);
119
+ var stringTester = tester instanceof StringTester ? tester : new StringTester(tester);
125
120
  var streamTester = new StreamTester(stringTester);
126
- return function(file, callback) {
121
+ return function (file, callback) {
127
122
  if (file.isNull()) {
128
123
  callback(new ExpectationError("not read"));
129
124
  } else if (file.isStream()) {
@@ -13,36 +13,40 @@ function StreamTester(contentsTester) {
13
13
  }
14
14
  }
15
15
 
16
- StreamTester.prototype.test = function(stream, callback) {
16
+ StreamTester.prototype.test = function (stream, callback) {
17
17
  var spyStream = this.createStream();
18
18
  var yielded = false;
19
19
  return stream
20
20
  .pipe(spyStream)
21
- .on("error", function(err) {
22
- yielded || callback(err);
21
+ .on("error", function (err) {
22
+ if (!yielded) {
23
+ callback(err);
24
+ }
23
25
  yielded = true;
24
26
  })
25
- .on("end", function() {
26
- yielded || callback(null);
27
+ .on("end", function () {
28
+ if (!yielded) {
29
+ callback(null);
30
+ }
27
31
  yielded = true;
28
32
  });
29
33
  };
30
34
 
31
- StreamTester.prototype.createStream = function() {
35
+ StreamTester.prototype.createStream = function () {
32
36
  var contentsTester = this.contentsTester;
33
37
  var contents = "";
34
38
  return through(
35
- function(chunk, encoding, cb) {
39
+ function (chunk, encoding, cb) {
36
40
  contents += chunk.toString();
37
41
  this.push(chunk);
38
42
  return cb();
39
43
  },
40
- function(cb) {
44
+ function (cb) {
41
45
  var _this = this;
42
- contentsTester.test(contents, function(err) {
46
+ contentsTester.test(contents, function (err) {
43
47
  _this.emit("error", err);
44
48
  cb();
45
49
  });
46
- }
50
+ },
47
51
  );
48
52
  };
@@ -9,14 +9,14 @@ function StringTester(expectation) {
9
9
  this.tester = this.parseExpectation(expectation);
10
10
  }
11
11
 
12
- StringTester.prototype.test = function(target, callback) {
12
+ StringTester.prototype.test = function (target, callback) {
13
13
  this.tester(target, callback);
14
14
  };
15
15
 
16
- StringTester.prototype.parseExpectation = function(expectation) {
16
+ StringTester.prototype.parseExpectation = function (expectation) {
17
17
  if (expectation instanceof Array) {
18
18
  var expectations = expectation.map(this.parseExpectation.bind(this));
19
- return function(target, callback) {
19
+ return function (target, callback) {
20
20
  async.applyEachSeries(expectations, target)(callback);
21
21
  };
22
22
  }
@@ -26,12 +26,15 @@ StringTester.prototype.parseExpectation = function(expectation) {
26
26
  }
27
27
 
28
28
  if (typeof expectation === "string") {
29
- return wrapAssertion(function(target) {
30
- return target.indexOf(expectation) >= 0;
31
- }, "not containing " + JSON.stringify(expectation));
29
+ return wrapAssertion(
30
+ function (target) {
31
+ return target.indexOf(expectation) >= 0;
32
+ },
33
+ "not containing " + JSON.stringify(expectation),
34
+ );
32
35
  }
33
36
  if (expectation instanceof RegExp) {
34
- return wrapAssertion(function(target) {
37
+ return wrapAssertion(function (target) {
35
38
  return expectation.test(target);
36
39
  }, "not matching " + expectation.toString());
37
40
  }
package/lib/util.js CHANGED
@@ -2,13 +2,13 @@
2
2
 
3
3
  var ExpectationError = require("./errors").ExpectationError;
4
4
 
5
- module.exports.wrapAssertion = function(func, errorMessage) {
5
+ module.exports.wrapAssertion = function (func, errorMessage) {
6
6
  if (!errorMessage) {
7
7
  errorMessage = "failed assertion" + (func.name ? " on " + func.name : "");
8
8
  }
9
- return function(target, callback) {
9
+ return function (target, callback) {
10
10
  var yielded = false;
11
- var castReturn = function(result) {
11
+ var castReturn = function (result) {
12
12
  if (yielded) return;
13
13
  if (result === true || result === null || result === undefined) {
14
14
  callback(null);
package/package.json CHANGED
@@ -1,41 +1,46 @@
1
1
  {
2
2
  "name": "gulp-expect-file",
3
- "version": "1.0.2",
4
- "author": "Kota Saito <kotas.nico@gmail.com>",
5
- "copyright": "2014 Kota Saito",
3
+ "version": "3.0.0",
6
4
  "description": "Expect files in pipes for gulp.js",
7
- "license": "MIT",
5
+ "keywords": [
6
+ "expect",
7
+ "gulpplugin",
8
+ "test"
9
+ ],
8
10
  "homepage": "https://github.com/pioug/gulp-expect-file/",
9
11
  "bugs": "https://github.com/pioug/gulp-expect-file/issues",
12
+ "license": "MIT",
13
+ "author": "Kota Saito <kotas.nico@gmail.com>",
10
14
  "repository": {
11
15
  "type": "git",
12
16
  "url": "git://github.com/pioug/gulp-expect-file.git"
13
17
  },
14
18
  "main": "index.js",
15
19
  "scripts": {
16
- "test": "node_modules/.bin/mocha"
20
+ "test": "node_modules/.bin/mocha",
21
+ "lint": "oxlint --deny-warnings . --ignore-path .oxignore",
22
+ "format": "oxfmt --write \"**/*.{js,json,yml,yaml,md}\"",
23
+ "format:check": "oxfmt --check \"**/*.{js,json,yml,yaml,md}\""
17
24
  },
18
- "keywords": [
19
- "gulpplugin",
20
- "test",
21
- "expect"
22
- ],
23
25
  "dependencies": {
24
26
  "ansi-colors": "^4.1.1",
25
- "async": "^3.1.0",
26
- "fancy-log": "^1.3.3",
27
- "minimatch": "^3.0.4",
28
- "plugin-error": "^1.0.1",
29
- "through2": "^3.0.1",
30
- "vinyl": "^2.2.0",
31
- "xtend": "^4.0.2"
27
+ "async": "^3.2.0",
28
+ "fancy-log": "^2.0.0",
29
+ "minimatch": "^10.2.2",
30
+ "plugin-error": "^2.0.1",
31
+ "through2": "^4.0.2",
32
+ "vinyl": "^3.0.1"
32
33
  },
33
34
  "devDependencies": {
34
- "eslint": "^6.7.1",
35
- "mocha": "^6.2.2",
35
+ "mocha": "^12.0.0-beta-9",
36
36
  "mock-require": "^3.0.3",
37
- "prettier": "^1.19.1",
37
+ "oxfmt": "^0.34.0",
38
+ "oxlint": "^1.49.0",
38
39
  "should": "^13.2.3",
39
- "temp": "^0.9.1"
40
- }
40
+ "temp": "^0.9.4"
41
+ },
42
+ "engines": {
43
+ "node": ">=24.0.0"
44
+ },
45
+ "copyright": "2014 Kota Saito"
41
46
  }
package/.eslintrc DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "extends": "eslint:recommended",
3
- "env": {
4
- "node": true,
5
- "mocha": true
6
- }
7
- }