Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

prunk

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prunk - npm Package Compare versions

Comparing version 1.2.0 to 1.2.1

17

index.js

@@ -5,5 +5,18 @@ //

//
// Author: Daniel Koch <daniel@suitsoft.eu>
// Version: 1.0.0
// Author: Daniel Koch
// Version: 1.2.1
//
// Copyright 2016 Daniel Koch
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

@@ -10,0 +23,0 @@ // Require node's `module` module that provides

2

package.json
{
"name": "prunk",
"version": "1.2.0",
"version": "1.2.1",
"description": "A mocking utility for node.js require",

@@ -5,0 +5,0 @@ "main": "index.js",

# prunk
prunk is a mocking utility for node.js `require()`. It allows you to
mock or suppress imports based on their name, regular expressions or
mock, suppress or alias imports based on their name, regular expressions or
custom test functions.

@@ -20,9 +20,7 @@

SCSS files so that the import in node would fail.
At this point, you either can introduce a pre-compiler, loader or whatever
your test framework supports or you can simply mock the import.
```jsx
```javascript
// MyComp.js
import { Component } from 'react';
import 'style.scss';
import './style.scss';

@@ -34,2 +32,5 @@ export default class Mycomp extends Component {

At this point, you either can introduce a pre-compiler, a loader or whatever
your test framework supports or you can simply make sure the stylesheet does not get imported.
```javascript

@@ -39,6 +40,6 @@ // MyComp.spec.js

prunk.mock('style.scss', 'no scss, dude.');
prunk.mock('./style.scss', 'no scss, dude.');
// or
prunk.mock( function(req) { return 'style.scss' === req; }, 'no scss, dude');
// or better
prunk.mock( req => './style.scss' === req, 'no scss, dude');
// or
prunk.mock( /\.(css|scss|sass)$/, 'no styles, dude');

@@ -49,3 +50,7 @@

In the test, `require()` is used instead of `import` because some pre-compilers
---
**Note:**
In this example, `require()` is used instead of `import` because some pre-compilers
move all imports to the top of the file and that would make the mocking impossible.

@@ -55,5 +60,7 @@ If you use mocha you can leverage it's [compiler](https://mochajs.org/#usage) configuration for that.

---
The example above uses `.mock()` to replace the required module contents.
If you just want to make sure some things don't get imported in the first place you can suppress them.
Then, they will always return `undefined`;
If you just want to make sure some things don't get imported at all you can suppress them.
Then, they will always return `undefined`.

@@ -64,6 +71,6 @@ ```javascript

prunk.suppress('style.scss');
prunk.suppress('./style.scss');
// or
prunk.suppress( function(req) { return 'style.scss' === req; } );
// or better
prunk.suppress( req => './style.scss' === req );
// or
prunk.suppress( /\.(css|scss|sass)$/ );

@@ -74,2 +81,14 @@

Maybe mocking an import is more than just a one-liner. You can then alias it to another file.
```javascript
const prunk = require('prunk');
prunk.alias('./style.scss', './style.js');
// or
prunk.alias(/style\.(scss)$/, 'js') // Replaces the first group
// or
prunk.alias( what => './style.scss' === what, () => './style.js' );
```
## API

@@ -120,2 +139,3 @@

Removes all mocks.
This function returns the prunk object so that you can chain calls.

@@ -135,3 +155,3 @@

var mockStyles = (req) => 'style.css' === req;
prunk.mock( mockStyles, 'no css, dude.');
prunk.suppress( mockStyles );
```

@@ -143,4 +163,4 @@

```javascript
prunk.mock( 'style.css', 'no css, dude.' );
prunk.mock( /\.(css|scss|sass|less)/, 'no styles, dude.');
prunk.suppress( 'style.css' );
prunk.suppress( /\.(css|scss|sass|less)/ );
```

@@ -155,2 +175,3 @@

imports.
This function returns the prunk object so that you can chain calls.

@@ -161,2 +182,3 @@

Removes all suppressed imports.
This function returns the prunk object so that you can chain calls.

@@ -214,2 +236,3 @@

Removes the alias for the given test.
This function returns the prunk object so that you can chain calls.

@@ -220,6 +243,7 @@

Removes all aliases.
This function returns the prunk object so that you can chain calls.
## Documentation
## More ocumentation
[Documented source](https://dak0rn.github.io/prunk/).
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc