4.1.1 β€’ Published 6 months ago

@putout/plugin-convert-mock-require-to-mock-import v4.1.1

Weekly downloads
3
License
MIT
Repository
github
Last release
6 months ago

@putout/plugin-convert-mock-require-to-mock-import NPM version

🐊Putout plugin adds ability to convert mockRequire to mockImport. Moved to @putout/plugin-tape.

Install

npm i @putout/plugin-convert-mock-require-to-mock-import -D

Rule

Rule convert-mock-require-to-mock-import is enabled by default for *.mjs, to disable add to .putout.json: Good complement of @putout/plugin-tape

{
    "rules": {
        "convert-mock-require-to-mock-import": "off"
    }
}

❌ Example of incorrect code

const mockRequire = require('mock-require');

const {reRequire, stopAll} = mockRequire;

test('', (t) => {
    mockRequire('fs/promises', {
        unlink: stub(),
    });
    
    const fn = reRequire('..');
    fn();
    
    stopAll();
    t.end();
});

βœ… Example of correct code

import {createMockImport} from 'mock-import';

const {
    mockImport,
    reImport,
    stopAll,
} = createMockImport(import.meta.url);

test('', async (t) => {
    mockImport('fs/promises', {
        unlink: stub(),
    });
    
    const fn = await reImport('..');
    fn();
    
    stopAll();
    t.end();
});

License

MIT

4.1.1

6 months ago

4.1.0

2 years ago

4.0.0

2 years ago

3.0.0

2 years ago

2.0.0

2 years ago

1.0.3

2 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago