npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gulp-expect-file

v2.0.0

Published

Expect files in pipes for gulp.js

Downloads

17,528

Readme

gulp-expect-file NPM version Build Status Dependency Status

Expectation on generated files for gulp 3/4

This plugin is intended for testing other gulp plugin.

Screen Shot

Usage

First, install gulp-expect-file as a development dependency:

npm install --save-dev gulp-expect-file

Then, add it to your gulpfile.js:

var expect = require("gulp-expect-file");

gulp.task("copy", function () {
  gulp
    .src(["src/foo.txt"])
    .pipe(gulp.dest("dest/"))
    .pipe(expect("dest/foo.txt"));
});

API

expect(expectation)

expectation

Type: String, Array, Object or Function

It describes the expectation of files on pipe.

| expectation | meaning | | -------------------------------------- | -------------------------------------------------------------- | | "foo.txt" | Expects foo.txt on pipe | | "*.txt" | Expects any files matching glob *.txt on pipe | | ["a.txt", "b.txt"] | Expects a.txt and b.txt both on pipe | | {"a.txt": true, "b.txt": true} | Expects a.txt and b.txt both on pipe (same as above) | | {"foo.txt": "text"} | Expects foo.txt with contents that has "text" as substring | | {"foo.txt": /pattern/} | Expects foo.txt with contents that matches /pattern/ | | function (file) { ... } | Call the tester function for each file on pipe | | {"foo.txt": function (file) { ... }} | Call the tester function for foo.txt |

A tester function is called with vinyl File object of target file.

It can return true, null, undefined for passing that file. false, String of error message, or any other value will fail testing on that file.

Sync version:

function (file) {
  return /\.txt$/.test(file.path);
}

Async version:

function (file, callback) {
  process.nextTick(function () {
    if (/\.txt$/.test(file.path)) {
      callback('not txt file');
    } else {
      callback();
    }
  });
}

expect(options, expectation)

options.reportUnexpected

Type: Boolean Default: true

If true, files not matching any expectation will be reported as failure.

For example, if a.txt and b.txt are on the pipe, expect(['a.txt']) will report that b.txt is unexpected.

gulp.src(["a.txt", "b.txt"]).pipe(expect(["a.txt"]));

// => FAIL: b.txt unexpected

options.reportMissing

Type: Boolean Default: true

If true, expected files that are not on the pipe will be reported as failure.

For example, if a.txt is on the pipe, expect(['a.txt', 'b.txt']) will report that b.txt is missing.

gulp.src(["a.txt"]).pipe(expect(["a.txt", "b.txt"]));

// => FAIL: Missing 1 expected files: b.txt

options.checkRealFile

Type: Boolean Default: false

If true, it also checks if the real file exists on the file system by fs.exists().

gulp
  .src(["exist.txt", "nonexist.txt"])
  .pipe(expect({ checkRealFile: true }, "*.txt"));

// => FAIL: nonexist.txt not exists on filesystem

options.errorOnFailure

Type: Boolean Default: false

If true, it emits error event when expectations got failed.

gulp
  .src(["a.txt"])
  .pipe(expect({ errorOnFailure: true }, ["b.txt"]))
  .on("error", function (err) {
    console.error(err);
  });

options.silent

Type: Boolean Default: false

If true, it does not report any results.

options.verbose

Type: Boolean Default: false

If true, it reports files that passed the expectation.

expect.real([options,] expectation)

This is just a shortcut for expect({ checkRealFile: true }, expectation).