Socket
Book a DemoInstallSign in
Socket

gulp-mock-module

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-mock-module

A file replacement plugin for grunt

1.0.10
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

gulp-mock-module NPM version

A module replacement plugin for gulp. It serves mock files by changing the require/import target from the target module onto the mock for that module.

Read me for gulp 3

Usage

First, install gulp-mock-module as a development dependency:

npm install --save-dev gulp-mock-module
# or
yarn add --dev gulp-mock-module

Then, add it to your gulpfile.js:

const mock = require("gulp-mock-module");
const path = require("path");
const { src, dest } = require("gulp");

function replaceTemplate() {
  return src(["file.js"])
    .pipe(
      mock(
        ["module1", "module2"],
        path.resolve(process.cwd(), "folder-that-contains-the-mocks")
      )
    )
    .pipe(dest("build/"));
}

exports.replaceTemplate = replaceTemplate;

Where file.js is a file containing import references to module1 and module2

// file.js

const module1 = require("path-to-module1/module1");
// or
import module2 from "path-to-module2/module2";

/**
 *
 * DOING SOMETHING AMAZING, I GUESS
 *
 */

API

gulp-mock-module only takes in two parameters

mock(targetModules, mockDirectory);

targetModules

Type: String[]

The names for the modules to replace with a mock.

The names can either be the name of the file itself (module1.js), or the name of the folder containing the index.js that you're importing (module2/index.js)

Note: file extensions are not used in the process so do not include them - the format should be the same as the name you use during the import syntax.

As for the supported file types or the languages of the files - Currently, this is only being used for typescript and javascript files.

["module1", "module2"];

mockDirectory

Type: String

The location of the folder that contains the mocks.

Note: This has not been tested for relative paths, so use path.resolve()

path.resolve(process.cwd(), "src", "mocks");

Keywords

gulp

FAQs

Package last updated on 26 Jul 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.