Skip to content

Commit

Permalink
fix(@putout/engine-runner) debug.enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
coderaiser committed Jun 20, 2020
1 parent 7218b05 commit 9ff3a70
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/engine-runner/lib/run-fix.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

const tryCatch = require('try-catch');
const debug = require('debug')('putout:runner:fix');
const enabled = {debug};
const {enabled} = debug;

debug('xxxxx');

const tryToFix = (fix, {path, position}) => {
const [e] = tryCatch(fix, path);
Expand Down
1 change: 1 addition & 0 deletions packages/engine-runner/test/fixture/debug.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const hello = 'world';
32 changes: 32 additions & 0 deletions packages/engine-runner/test/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
const test = require('supertape');
const putout = require('putout');
const stub = require('@cloudcmd/stub');
const mockRequire = require('mock-require');
const {reRequire, stopAll} = mockRequire;

const {readFixtures} = require('./fixture');
const {runPlugins} = require('..');
Expand All @@ -14,6 +16,7 @@ const fixture = readFixtures([
'shebang-fix',
'babel',
'babel-fix',
'debug',
]);

test('putout: runner: run plugins', (t) => {
Expand Down Expand Up @@ -674,6 +677,35 @@ test('putout: runner: shebang', (t) => {
t.end();
});

test('putout: runner: debug', (t) => {
const {DEBUG} = process.env;
process.env.DEBUG = 'putout:runner:fix';

const debugFn = stub();
debugFn.enabled = true;
const debug = stub().returns(debugFn);

mockRequire('debug', debug);
reRequire('../lib/run-fix');
const {runPlugins} = reRequire('..');
const putout = reRequire('putout');

const {code} = putout(fixture.debug, {
fix: true,
runPlugins,
plugins: [
'remove-unused-variables',
],
});
const expected = '\n';
process.env.DEBUG = DEBUG;

stopAll();

t.deepEqual(code, expected, 'should equal');
t.end();
});

test('putout: runner: babel', (t) => {
const {code} = putout(fixture.babel, {
runPlugins,
Expand Down

0 comments on commit 9ff3a70

Please sign in to comment.