Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/darmody/babel-plugin-stub
a babel plugin helps you easily mock your code (usually when you debug it) without modify the source code.
https://github.com/darmody/babel-plugin-stub
babel babel-plugin stub
Last synced: about 11 hours ago
JSON representation
a babel plugin helps you easily mock your code (usually when you debug it) without modify the source code.
- Host: GitHub
- URL: https://github.com/darmody/babel-plugin-stub
- Owner: Darmody
- Created: 2020-07-21T09:44:33.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-01-06T12:03:12.000Z (about 2 years ago)
- Last Synced: 2024-04-16T09:20:03.867Z (9 months ago)
- Topics: babel, babel-plugin, stub
- Language: TypeScript
- Homepage:
- Size: 1.29 MB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# babel-plugin-stub
> a babel plugin help you stubbing code easily (usually when you test/debug it) without modify the source code.
It's a handy tool help you temporary modify code when you dubug for some spcial cases.
You can also use it combine with testing framework (e.g. Jest) for method stub or mocking!## Install
Using npm:
```bash
npm install --save-dev babel-plugin-stub
```or using yarn:
```bash
yarn add babel-plugin-stub --dev
```## Usage
### Configuration
```js
// babel.config.js
module.exports = function (api) {
api.cache(true);return {
// recommend using environment variable to apply plugin as your need.
plugins: [process.env.STUB && 'stub'].filter(i => i),
};
};
```### Variable
```js
// @stub 'string'
let string = 'value';
// @stub 1
let number = 'value';
// @stub undefined
let undef = 'value';
// @stub null
let nil = 'value';
// @stub true
let truly = 'value';
// @stub false
let falsy = 'value';
```turns into
```js
let string = 'string';
let number = 1;
let undef = undefined;
let nil = null;
let truly = true;
let falsy = false;
```### Object Property
```js
const obj = {
// @stub 'stub value'
property: 'value',
};
```turns into
```js
const obj = {
property: 'stub value',
};
```### Conditional Statement
```js
// @stub true
if (variable > 0) {
// @stub false
} else if (variable < 0) {
}
```turns into
```js
if (true) {
} else if (false) {
}
```### Return Statement
```js
function fn() {
// @stub 'stub value'
return 'value';
}
```turns into
```js
function fn() {
return 'stub value';
}
```## Function Arguments
```js
fn(
// @stub 'stub value'
variable,
// @stub 'stub value'
'value'
);
```turns into
```js
fn(
'stub value',
'stub value,
)
```