@putout/test 9.0.0 → 9.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +1,17 @@
1
1
  'use strict';
2
2
 
3
- const {readFile, writeFile} = require('fs/promises');
3
+ const tryToCatch = require('try-to-catch');
4
+ const {
5
+ readFile,
6
+ writeFile,
7
+ unlink,
8
+ } = require('node:fs/promises');
4
9
 
5
10
  const {
6
11
  join,
7
12
  extname,
8
13
  basename,
9
- } = require('path');
14
+ } = require('node:path');
10
15
 
11
16
  const test = require('supertape');
12
17
  const processFile = require('putout/process-file');
@@ -20,6 +25,17 @@ const update = async (a, b) => {
20
25
  await write(a, b);
21
26
  };
22
27
 
28
+ const remove = async (a) => {
29
+ const remove = global.unlink || unlink;
30
+ await tryToCatch(remove, a);
31
+ };
32
+
33
+ const read = async (a, b) => {
34
+ const read = global.readFile || readFile;
35
+
36
+ return await read(a, b);
37
+ };
38
+
23
39
  const buildOptions = ({options, plugins, processors}) => ({
24
40
  ...options,
25
41
  plugins: plugins || options.plugins,
@@ -105,9 +121,7 @@ async function process(filename, dir, {printer, processors, plugins, extension,
105
121
  const inputName = join(dir, 'fixture', `${filename}${extension}`);
106
122
  const outputName = join(dir, 'fixture', `${filename}-fix${extension}`);
107
123
 
108
- const rawSource = await readFile(inputName, 'utf8');
109
- const output = !fix || noChange ? '' : await readFile(outputName, 'utf8');
110
-
124
+ const rawSource = await read(inputName, 'utf8');
111
125
  const options = {
112
126
  dir,
113
127
  processors,
@@ -129,8 +143,13 @@ async function process(filename, dir, {printer, processors, plugins, extension,
129
143
  processorRunners,
130
144
  });
131
145
 
132
- if (isUpdate() && !noChange && fix)
133
- await update(outputName, processedSource);
146
+ if (isUpdate())
147
+ if (!noChange && fix)
148
+ await update(outputName, processedSource);
149
+ else if (noChange)
150
+ await remove(outputName);
151
+
152
+ const output = !fix || noChange ? '' : await read(outputName, 'utf8');
134
153
 
135
154
  return {
136
155
  processedSource,
package/lib/test.js CHANGED
@@ -607,7 +607,7 @@ function parseOptions(plugin) {
607
607
  }
608
608
 
609
609
  function checkReport(name, message) {
610
- if (!message) {
610
+ if (!isString(message) && !message) {
611
611
  const help = `☝️ Looks like you forget to pass the 'message' for 'report()' operator`;
612
612
  const source = `report(name: string, message: string): Operator`;
613
613
  const values = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/test",
3
- "version": "9.0.0",
3
+ "version": "9.1.0",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "Test runner for 🐊Putout plugins ",