{"name":"@putout/test","version":"15.6.1","keywords":["putout","putout-plugin","plugin","test","runner"],"author":{"url":"https://github.com/coderaiser","name":"coderaiser","email":"mnemonic.enemy@gmail.com"},"license":"MIT","_id":"@putout/test@15.6.1","maintainers":[{"name":"coderaiser","email":"mnemonic.enemy@gmail.com"}],"homepage":"https://github.com/coderaiser/putout/tree/master/packages/test#readme","bugs":{"url":"https://github.com/coderaiser/putout/issues"},"bin":{"tape":"bin/test.js"},"tag":false,"dist":{"shasum":"8e5b554b212d24b093e77969a148de275657791d","tarball":"http://registry-npm.ywwl.com/@putout/test/download/@putout/test-15.6.1.tgz","fileCount":15,"integrity":"sha512-GXIXtvjmBQOHd3fUrFyXmSRh5wLwr1HsntYycugmg8lHeOEEn6qEfNHZDzqA1O3wOIoNCpSi3CGTYP2BBHJw1A==","signatures":[{"sig":"MEYCIQD/e5X/LJKYJDZNx/UwTo6Vb+bs/vCiNDqpmSVWK3Jb7AIhAIVC0xFue0zW9yI7R9sNL+TZAaLuL/8tyBvEfoHZ+xDu","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":52541,"size":11568,"noattachment":false,"key":"/@putout/test/-/@putout/test-15.6.1.tgz"},"main":"lib/test.js","type":"module","engines":{"node":">=22"},"exports":{".":"./lib/test.js","./eslint":"./lib/eslint/eslint.js","./processor":"./lib/processor/index.js","./filesystem":"./lib/filesystem/index.js"},"gitHead":"8011d4930dede43ba3bfed1edca6854df1bd9bb9","release":false,"scripts":{"lint":"madrun lint","test":"madrun test","report":"madrun report","coverage":"madrun coverage","fix:lint":"madrun fix:lint","fresh:lint":"madrun fresh:lint","lint:fresh":"madrun lint:fresh","watch:test":"madrun watch:test"},"_npmUser":{"name":"coderaiser","email":"mnemonic.enemy@gmail.com"},"changelog":false,"repository":{"url":"git+https://github.com/coderaiser/putout.git","type":"git"},"_npmVersion":"11.4.2","description":"Test runner for 🐊Putout plugins ","directories":{},"_nodeVersion":"26.3.0","dependencies":{"montag":"^2.0.0","currify":"^4.0.0","supertape":"^13.0.0","try-catch":"^4.0.0","try-to-catch":"^4.0.0","@putout/eslint":"^6.0.0","@putout/engine-parser":"^15.0.7","@putout/engine-runner":"*","@putout/operator-json":"^3.1.0","@putout/engine-reporter":"^8.0.1","@putout/cli-process-file":"^7.0.0","@putout/engine-processor":"*","@putout/plugin-filesystem":"*","@putout/operator-filesystem":"^11.0.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"eslint":"^10.0.0","madrun":"^13.0.0","nodemon":"^3.0.1","superc8":"^12.0.0","@putout/plugin-esm":"*","eslint-plugin-putout":"^31.0.0","@putout/plugin-putout":"*","@putout/formatter-dump":"^7.0.0","@putout/processor-wasm":"*","@putout/plugin-variables":"*","@putout/formatter-progress":"*","@putout/plugin-destructuring":"*","@putout/plugin-remove-console":"*"},"peerDependencies":{"putout":"*","@putout/printer":"*"},"_npmOperationalInternal":{"tmp":"tmp/test_15.6.1_1781383913529_0.3525853900430942","host":"s3://npm-registry-packages-npm-production"},"readme":"# @putout/test [![NPM version][NPMIMGURL]][NPMURL]\n\n[NPMIMGURL]: https://img.shields.io/npm/v/@putout/test.svg?style=flat&longCache=true\n[NPMURL]: https://npmjs.org/package/@putout/test \"npm\"\n\nTest runner for 🐊[**Putout**](https://github.com/coderaiser/putout#plugins-api). Basically it is [supercharged **tape**](https://github.com/coderaiser/supertape) with additional asseritions:\n\n## Install\n\n```\nnpm i @putout/test -D\n```\n\n## Autofix\n\nSet environment variable `UPDATE=1` to update `transform` and `format` fixtures (both `source` and `fixed`).\n\n☝️ *Remember that `-fix.js` fixtures will be removed when used in `noReport`, `noTransform` and `noTransformWithOptions`*\n\n```sh\nUPDATE=1 tape test/*.js\n```\n\nWhen you need to override extension use `UPDATE_EXTENSION`, for example `UPDATE_EXTENSION=abc` will create files with extension 'abc'.\n\n## Plugins API\n\n🐊**Putout** can be used in all IDE's supported by`ESLint` as [`eslint-plugin-putout`](https://github.com/coderaiser/putout/tree/packages/eslint-plugin-putout).\nWhen [async rules will be supported](https://github.com/eslint/eslint/issues/15394) we can switch to `ESM`.\n\nTo write test for your plugins you need initialize `test` using `createTest`:\n\n```js\nimport {createTest} from '@putout/test';\nimport * as rmVars from '@putout/plugin-remove-unused-variables';\n\nconst test = createTest(import.meta.url, {\n    'remove-unused-variables': rmVars,\n});\n```\n\nYou can also pass all 🐊**Putout** options:\n\n```js\nconst test = createTest(import.meta.url, {\n    plugins: [\n        ['remove-unused-variables', rmVars],\n    ],\n});\n```\n\nOr use another linter with the same signature as 🐊**Putout** using `lint` field:\n\n```js\nconst test = createTest(import.meta.url, {\n    lint: putout,\n    plugins: [\n        ['remove-unused-variables', rmVars],\n    ],\n});\n```\n\nYou can also pass extensions to read from `fixture` directory:\n\n```js\nconst test = createTest(import.meta.url, {\n    extension: 'wast',\n    extensionFix: 'wast',\n    lint: putout,\n    plugins: [\n        ['remove-unused-variables', rmVars],\n    ],\n});\n```\n\nAnd apply new [operators](https://github.com/coderaiser/supertape?tab=readme-ov-file#operators):\n\n```js\nconst test = createTest(import.meta.url, {\n    extension: 'wast',\n    lint: putout,\n    plugins: [\n        ['remove-unused-variables', rmVars],\n    ],\n}, {\n    render: (operator) => (name) => operator.transform,\n});\n```\n\n### `report(filename, message: string | string[], plugins?: PutoutPlugin[])`\n\nCheck error message (or messages) of a plugin:\n\n```js\ntest('remove useless variables: dot', (t) => {\n    t.report('dot', 'Dot files should be added to .gitignore');\n    t.end();\n});\n```\n\nWhen you want to check that report called exact count of times pass an array of messages:\n\n```js\ntest('remove useless variables: dot', (t) => {\n    t.report('dot', [\n        'Dot files should be added to .gitignore',\n    ]);\n    t.end();\n});\n```\n\n### `reportCode(input: string, message: string | string[], plugins?: PutoutPlugins)`\n\nCheck error message of a plugin from `input` code:\n\n```js\ntest('remove debugger: report', (t) => {\n    t.reportCode('debugger', 'Unexpected \"debugger\" statement');\n    t.end();\n});\n```\n\n### `transform(filename [, output, plugins])`\n\nCheck transform of `filename.js` -> `filename-fix.js` in `test/fixtures` directory:\n\n```js\ntest('remove useless variables: array-from', (t) => {\n    t.transform('array-from', {\n        'remove-useless-array-from': removeUselessArrayFrom,\n    });\n    t.end();\n});\n```\n\n*☝️When input and output the same test fails. Use [`noTransform()`](#notransformfilename) for such cases.*\n\n### `transformCode(input, output)`\n\nCheck transform of `input` -> `output` code:\n\n```js\ntest('remove-console: property identifier: code', (t) => {\n    t.transformCode('console.log()', '');\n    t.end();\n});\n```\n\n### `reportWithOptions(filename, message: string | string[], options)`\n\nCheck report of `filename.js` with `options`:\n\n```js\ntest('putout: test: reportWithOptions', (t) => {\n    const cache = new Map();\n    cache.set('x', 'y');\n    \n    t.reportWithOptions('remove-import', 'avoid imports', {\n        cache,\n    });\n    t.end();\n});\n```\n\n### `noReportWithOptions(filename, options)`\n\nCheck no report of `filename.js` with `options`:\n\n```js\ntest('putout: test: no report with options: remove-import', (t) => {\n    const cache = new Map();\n    \n    t.noReportWithOptions('remove-import', {\n        cache,\n    });\n    t.end();\n});\n```\n\n### `transformWithOptions(filename, options)`\n\nCheck transform of `filename.js` with `options`:\n\n```js\ntest('putout: plugin: declare-undefined-variables: transform with options: parse', (t) => {\n    t.transformWithOptions('parse', {\n        dismiss: [\n            'assign',\n            'stringify',\n        ],\n    });\n    t.end();\n});\n```\n\n### `noTransformWithOptions(filename, options)`\n\nWhen file should not be transformed:\n\n```js\ntest('test: declared', (t) => {\n    t.noTransform('declared');\n    t.end();\n});\n```\n\n### `noTransformWithOptions(filename, options)`\n\nCheck transform of `filename.js` with `options`:\n\n```js\ntest('putout: plugin: declare-undefined-variables: transform: assign: dismiss', (t) => {\n    t.noTransformWithOptions('assign', {\n        dismiss: [\n            'assign',\n            'stringify',\n        ],\n    });\n    t.end();\n});\n```\n\n### `noReport(filename [, plugins])`\n\nCheck error message of a plugin not produces\n\n```js\ntest('plugin-putout: check-replace-code: no report: typescript', (t) => {\n    t.noReport('typescript');\n    t.end();\n});\n```\n\nwith plugins:\n\n```js\ntest('plugin-putout: check-replace-code: no report: hello', (t) => {\n    t.noReport('typescript', [\n        ['plugin', plugin],\n    ]);\n    t.end();\n});\n```\n\n### `noReportCode(filename)`\n\nCheck error message of a plugin not produces\n\n```js\ntest('plugin-putout: check-replace-code: no report: import', (t) => {\n    t.noReportCode(`import a from 'a'`);\n    t.end();\n});\n```\n\n### `noReportAfterTransform(filename)`\n\nCheck error message of a plugin not produced\n\n```js\ntest('test: no report after transform: file', (t) => {\n    t.noReportAfterTransform('file');\n    t.end();\n});\n```\n\n### `noReportAfterTransformWithOptions(filename)`\n\nCheck error message of a plugin not produced with provided options:\n\n```js\ntest('test: no report', (t) => {\n    t.noReportAfterTransformWithOptions('file');\n    t.end();\n});\n```\n\n### `noTransform(filename)`\n\nCheck transform of `filename.js` produce nothing\n\n```js\ntest('plugin-apply-numeric-separators: no transform: hex', (t) => {\n    t.noTransform('hex');\n    t.end();\n});\n```\n\n### `progress(filename, expected)`\n\nCheck progress of `filename.js`;\n\n```js\ntest('remove useless variables: for-of', async ({progress}) => {\n    await progress('progress', {\n        i: 0,\n        n: 2,\n        rule: 'read-all-files',\n    });\n});\n```\n\n### `progressWithOptions(filename, options, expected)`\n\nCheck progress of `filename.js`;\n\n```js\ntest('remove useless variables: for-of', async ({progressWithOptions}) => {\n    const options = {\n        from: '/home/coderaiser',\n        to: '/',\n    };\n    \n    await progressWithOptions('progress', options, {\n        i: 0,\n        n: 2,\n        rule: 'read-all-files',\n    });\n});\n```\n\n## Formatters API\n\nFirst you need to create test with:\n\n```js\nimport {createTest} from '@putout/test';\nimport * as rmVars from '@putout/plugin-remove-unused-variables';\n\nconst test = createTest(import.meta.url, {\n    'remove-unused-variables': rmVars,\n});\n```\n\n### `format(formatter, filename)`\n\nCheck file name formatting (pass `process.env.UPDATE=1` to save `fixture`):\n\n```js\ntest('formatter: codeframe', async ({format}) => {\n    await format(codeframe);\n});\n```\n\n### `noFormat`\n\nCheck that there is no formatting for for such file:\n\n```js\ntest('formatter: codeframe: no', async ({noFormat}) => {\n    await noFormat(codeframe, 'no');\n});\n```\n\n### `formatMany(formatter, [filename1, filename2])`\n\nCheck file name formatting (pass `process.env.UPDATE=1` to save `fixture`):\n\n```js\ntest('formatter: dump: many', async ({formatMany}) => {\n    await formatMany(dump, ['var', 'var']);\n});\n```\n\n#### Usage Example\n\nHere is example of tests for [remove-console](https://github.com/coderaiser/putout/tree/master/packages/plugin-remove-console):\n\n```js\nconst {createTest} = require('@putout/test');\nconst removeConsole = require('@putout/plugin-remove-console');\n\nconst test = createTest(__dirname, {\n    'remove-console': removeConsole,\n});\n\ntest('remove-console: report: property-identifier', (t) => {\n    t.report('property-identifier', 'Unexpected \"console\" call');\n    t.end();\n});\n\ntest('remove-console: property-identifier', (t) => {\n    t.transform('property-identifier');\n    t.end();\n});\n\n// when code should not be transformed\ntest('test: declared', (t) => {\n    t.noTransformCode('alert()');\n    t.end();\n});\n```\n\n## ESLint API\n\nFirst you need to create test with:\n\n```js\nimport {createTest} from '@putout/test/eslint';\n\nconst test = createTest(import.meta.url, config);\n```\n\n### `process(filename [, config])`\n\nWorks in similar to [transform](#transformfilename--output-plugins) way:\n\n- ✅ reads `operator-linebreak.js`;\n- ✅ transforms it;\n- ✅ check that transformed is equal to `operator-linebreak-fix.js`;\n\nExample:\n\n```js\ntest('test: eslint: transform', async ({process}) => {\n    await process('operator-linebreak');\n});\n\ntest('test: eslint: transform', async ({process}) => {\n    await process('operator-linebreak', {\n        rules: {\n            'putout/putout': {\n                rules: {\n                    'convert-esm-to-commonjs': 'on',\n                },\n            },\n        },\n    });\n});\n```\n\n*☝️When input and output the same test fails. Use [`noProcess()`](#noprocessfilename--overrides) for such cases.*\n\n### `noProcess(filename [, overrides])`\n\nCheck that filename would not be processed.\n\nExample:\n\n```js\ntest('test: eslint: noProcess', async ({noProcess}) => {\n    await noProcess('operator-linebreak-fix');\n});\n\ntest('test: eslint: noProcess', async ({noProcess}) => {\n    await noProcess('operator-linebreak-fix', {\n        rules: {\n            'putout/putout': ['error', {}],\n        },\n    });\n});\n```\n\n### `comparePlaces(filename, places[, overrides])`\n\n```js\ntest('eslint-config: operator-line-break', async ({comparePlaces}) => {\n    await comparePlaces('operator-linebreak', [{\n        message: 'There should be no line break before or after \\'=\\'.',\n        position: {\n            column: 1,\n            line: 2,\n        },\n        rule: 'operator-linebreak (eslint)',\n    }]);\n});\n```\n\nwith `overrides`:\n\n```js\ntest('eslint-config: operator-line-break', async ({comparePlaces}) => {\n    const overrides = {\n        extends: ['plugin:putout/safe'],\n    };\n    \n    await comparePlaces('operator-linebreak', [{\n        message: 'There should be no line break before or after \\'=\\'.',\n        position: {\n            column: 1,\n            line: 2,\n        },\n        rule: 'operator-linebreak (eslint)',\n    }], overrides);\n});\n```\n\n### `transform(name)`\n\n```js\ntest('test: eslint: transform: remove-debugger', (t) => {\n    t.transform('remove-debugger');\n    t.end();\n});\n```\n\n### `report(filename, message | []messages)`\n\n```js\ntest('test: eslint: report: remove-debugger', (t) => {\n    t.report('remove-debugger', `Avoid 'debugger' statement`);\n    t.end();\n});\n```\n\n## Processors API\n\nWith `processors api` you can test `processors` in a simplest possible way.\n\nFirst things first, init `test` with:\n\n```js\nimport {createTest} from '@putout/test/processor';\n\nconst test = createTest(import.meta.url, {\n    extension: 'json',\n    processors: ['json'],\n    plugins: ['eslint'],\n});\n```\n\n### `process(filename [, plugins, ])`\n\nExample:\n\n```js\ntest('putout: processor: json', async ({process}) => {\n    await process('eslintrc');\n});\n\ntest('putout: processor: json', async ({process}) => {\n    await process('package', ['package-json']);\n});\n```\n\n### `noProcess(filename [, plugins, processors])`\n\nCheck that filename would not be processed.\n\nExample:\n\n```js\ntest('putout: process: json: no process', async ({noProcess}) => {\n    await noProcess('eslintrc', [], ['json']);\n});\n```\n\n### `comparePlaces(filename, places)`\n\n```js\ntest('putout: processor: css: places', async ({comparePlaces}) => {\n    await comparePlaces('style', [{\n        message: 'Expected indentation of 4 spaces (indentation)',\n        position: {\n            column: 1,\n            line: 2,\n        },\n        rule: 'indentation (stylelint)',\n    }]);\n});\n```\n\n## Filesystem API\n\n```js\nimport {test} from '@putout/test/filesystem';\n```\n\n### `equalFilesystem(ast, expected)`\n\n```js\ntest('putout: operator: filesystem: findFile: exclude', (t) => {\n    const ast = parseFilesystem([\n        '/',\n        '/hello/',\n        '/hello/world.txt',\n        '/hello/hello.txt',\n    ]);\n    \n    findFile(ast, '*.txt', ['hello.txt']).map(removeFile);\n    \n    const expected = {\n        type: 'directory',\n        filename: '/',\n        files: [{\n            type: 'directory',\n            filename: '/hello',\n            files: [{\n                type: 'file',\n                filename: '/hello/hello.txt',\n            }],\n        }],\n    };\n    \n    t.equalFilesystems(ast, expected);\n    t.end();\n});\n```\n\n### `parseFilesystem(array)`\n\n```js\ntest('putout: operator: filesystem: writeFileContent: emoji', (t) => {\n    const ast = parseFilesystem([\n        '/hello/world/',\n        '/hello/world/README.md',\n    ]);\n    \n    const [filePath] = findFile(ast, 'README.md');\n    \n    writeFileContent(filePath, 'hello 🐊');\n    const content = readFileContent(filePath);\n    \n    t.equal(content, 'hello 🐊');\n    t.end();\n});\n```\n\n## License\n\nMIT\n","publish_time":1781383913641,"_cnpm_publish_time":1781383913641,"dist-tags":{"latest":"15.9.0"}}