Skip to content

Commit

Permalink
feature: @putout/test: drop formatSave, formatManySave
Browse files Browse the repository at this point in the history
  • Loading branch information
coderaiser committed Jul 6, 2023
1 parent ab8b968 commit d2a5452
Show file tree
Hide file tree
Showing 9 changed files with 145 additions and 136 deletions.
47 changes: 21 additions & 26 deletions packages/test/lib/eslint/eslint.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@ import {
import {fileURLToPath} from 'url';
import {stub} from 'supertape';
import {createTest} from './eslint.mjs';
import {createUpdate} from '../../test/update.js';

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const test = createTest(import.meta.url);

const NOT_CHECK_ASSERTIONS_COUNT = {
checkAssertionsCount: false,
};

const update = createUpdate();

test('test: eslint: export', async ({equal}) => {
const eslint = await import('./eslint.mjs');
const testEslint = await import('@putout/test/eslint');
Expand All @@ -22,57 +29,49 @@ test('test: eslint: process', async ({process}) => {
});

test('test: eslint: process: UPDATE', async ({process}) => {
global.process.env.UPDATE = '1';
update(1);
await process('operator-linebreak');
delete global.process.env.UPDATE;
}, {
checkAssertionsCount: false,
});
update();
}, NOT_CHECK_ASSERTIONS_COUNT);

test('test: eslint: process: UPDATE: stub', async ({process, calledWith}) => {
global.process.env.UPDATE = '1';
update(1);
const writeFileSync = stub();

global.writeFileSync = writeFileSync;

await process('operator-linebreak');

delete global.process.env.UPDATE;
update();
delete global.writeFileSync;

const name = join(__dirname, 'fixture', 'operator-linebreak-fix.js');
const data = 'const a = 5;\n\n';

calledWith(writeFileSync, [name, data]);
}, {
checkAssertionsCount: false,
});
}, NOT_CHECK_ASSERTIONS_COUNT);

test('test: eslint: noProcess: UPDATE', async ({noProcess}) => {
global.process.env.UPDATE = '1';
update(1);
await noProcess('operator-linebreak-fix');
delete global.process.env.UPDATE;
}, {
checkAssertionsCount: false,
});
update();
}, NOT_CHECK_ASSERTIONS_COUNT);

test('test: eslint: noProcess: UPDATE: stub', async ({noProcess, calledWith}) => {
global.process.env.UPDATE = '1';
update(1);
const unlinkSync = stub();

global.unlinkSync = unlinkSync;

await noProcess('operator-linebreak-fix');

delete global.process.env.UPDATE;
update();
delete global.unlinkSync;

const name = join(__dirname, 'fixture', 'operator-linebreak-fix-fix.js');

calledWith(unlinkSync, [name]);
}, {
checkAssertionsCount: false,
});
}, NOT_CHECK_ASSERTIONS_COUNT);

test('test: eslint: noProcess', async ({noProcess}) => {
await noProcess('operator-linebreak-fix');
Expand Down Expand Up @@ -126,9 +125,7 @@ test('test: eslint: report: no plugins', (t) => {

t.calledWith(failStub, expected);
t.end();
}, {
checkAssertionsCount: false,
});
}, NOT_CHECK_ASSERTIONS_COUNT);

test('test: eslint: transform: no plugins', (t) => {
const failStub = stub().returns({
Expand All @@ -143,6 +140,4 @@ test('test: eslint: transform: no plugins', (t) => {

t.calledWith(failStub, expected);
t.end();
}, {
checkAssertionsCount: false,
});
}, NOT_CHECK_ASSERTIONS_COUNT);
5 changes: 0 additions & 5 deletions packages/test/lib/fixture/var-format.js
Original file line number Diff line number Diff line change
@@ -1,5 +0,0 @@
var
1:8 error Avoid 'console' call remove-console

✖ 1 errors in 1 files
 fixable with the `--fix` option
25 changes: 14 additions & 11 deletions packages/test/lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ const parsePlugin = (plugins) => {
};

function createTest(dir, maybeOptions) {
const update = isUpdate();

dir = join(dir, 'fixture');

const options = parseOptions(maybeOptions);
Expand All @@ -113,12 +111,9 @@ function createTest(dir, maybeOptions) {
noReportAfterTransform: noReportAfterTransform(dir, options),
reportWithOptions: reportWithOptions(dir, options),
noReportWithOptions: noReportWithOptions(dir, options),
reportCode: reportCode(options),

formatSave: formatSave(dir, options),
format: update ? formatSave : format(dir, options),
formatManySave: formatManySave(dir, options),
formatMany: update ? formatManySave : formatMany(dir, options),
reportCode: reportCode(options), //formatSave: formatSave(dir, options),
format: formatSave(dir, options), //formatManySave: formatManySave(dir, options),
formatMany: formatManySave(dir, options),
noFormat: noFormat(dir, options),
});
}
Expand Down Expand Up @@ -221,18 +216,22 @@ const formatMany = currify((dir, options, t) => async (formatter, names, formatt
});

const formatManySave = currify((dir, options, t) => async (formatter, names, options = {}) => {
const runFormat = await formatMany(dir, options, t);

if (!isUpdate())
return await runFormat(formatter, names, options);

const {existsSync, writeFileSync} = global.__putout_test_fs;

if (!isArray(names))
throw Error(`☝️ Looks like 'formatManySave()' received 'names' with type: '${typeof names}', expected: 'array'`);
throw Error(`☝️ Looks like 'formatMany()' received 'names' with type: '${typeof names}', expected: 'array'`);

const name = `${names.join('-')}-format.js`;
const outputName = join(dir, name);

if (!existsSync(outputName))
writeFileSync(outputName, '');

const runFormat = await formatMany(dir, options, t);
const {result} = await runFormat(formatter, names, options);

writeFileSync(outputName, result);
Expand All @@ -241,6 +240,11 @@ const formatManySave = currify((dir, options, t) => async (formatter, names, opt
});

const formatSave = currify((dir, options, t) => async (formatter, name, options = {}) => {
const runFormat = format(dir, options, t);

if (!isUpdate())
return await runFormat(formatter, name, options);

const {existsSync, writeFileSync} = global.__putout_test_fs;

const full = join(dir, name);
Expand All @@ -249,7 +253,6 @@ const formatSave = currify((dir, options, t) => async (formatter, name, options
if (!existsSync(outputName))
writeFileSync(outputName, '');

const runFormat = format(dir, options, t);
const {result} = await runFormat(formatter, name, options);

writeFileSync(outputName, result);
Expand Down
5 changes: 5 additions & 0 deletions packages/test/lib/test.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import removeConsoleFixture from '../test/fixture/remove-console.js';
import _createTest, {createTest} from './test.mjs';
import cjsTest from './test.js';
import formatter from '@putout/formatter-dump';
import {createUpdate} from '../test/update.js';

const update = createUpdate();

const test = createTest(import.meta.url, {
'remove-console': removeConsoleFixture,
Expand All @@ -12,5 +15,7 @@ test('test: esm: default export same as commonjs', ({equal}) => {
});

test('test: esm: format', async ({format}) => {
update(1);
await format(formatter, 'var');
update();
});
Empty file.
1 change: 1 addition & 0 deletions packages/test/test/fixture/empty.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var s = fn();
Loading

0 comments on commit d2a5452

Please sign in to comment.