{"name":"coffee","version":"5.5.0","description":"Test command line on Node.js.","main":"index.js","dependencies":{"cross-spawn":"^6.0.5","debug":"^4.1.0","is-type-of":"^1.2.1"},"devDependencies":{"@types/node":"^10.12.18","egg-bin":"^5.5.0","egg-ci":"^2.2.0","eslint":"^8.28.0","eslint-config-egg":"^12.1.0","lodash.ismatch":"^4.4.0","mm":"^3.2.1","mocha":"^10.1.0","mz-modules":"^2.1.0","nyc":"^11.0.2","spy":"^1.0.0","tsd":"^0.24.1","typescript":"^4.9.3"},"repository":{"type":"git","url":"git://github.com/node-modules/coffee.git"},"homepage":"https://github.com/node-modules/coffee","author":{"name":"popomore","email":"sakura9515@gmail.com"},"keywords":["cli","test","shell","spawn","fork","child_process","exec"],"license":"MIT","engines":{"node":">= 6.0.0"},"ci":{"version":"14, 16, 18","os":"linux"},"scripts":{"lint":"eslint .","test":"npm run lint -- --fix && npm run test-local","test-local":"tsd && egg-bin test","cov":"tsd && egg-bin cov","ci":"npm run lint && npm run cov"},"gitHead":"cf7f8d576769f0d75f3137e0038d21a6b9e388f6","bugs":{"url":"https://github.com/node-modules/coffee/issues"},"_id":"coffee@5.5.0","_nodeVersion":"18.12.0","_npmVersion":"6.14.17","dist":{"integrity":"sha512-dRovm6sxD+INLLoYzJAqzvQ5+K1qvZl9RAQQt62PE0IXj4VP+tTYUuVu2akI0qaXL4u3ZSqnFKXTx35IjAUvHA==","shasum":"270d2771328e9f974906c175fd50de3ea4ca8a57","tarball":"http://registry-npm.ywwl.com/coffee/download/coffee-5.5.0.tgz","fileCount":9,"unpackedSize":32922,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEMCHwKW+tJaAYxPbFS5OPXoFbCwlKGOuH72BRlfF0hiTS4CIBZ0iZ9WSID/2dKEdYlE3KZ1z1xB4iL+v8EIwwdQT6JX"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjfHcSACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmoWDw//QV3mi++T2OWYiL9OIoWDbBjb0UAlDPIY+hv3+un1MadxzjFn\r\ne5qo0WwUT12zamc2PUaFvswgI0F0miQ505FFVJGO+sFv0jaqAess0+4jTDxn\r\ndoOv3adnm5wrQ031e38t9RM5dMys0ml9BZPNkQ520U8vg1XTFBPlBX0WDUZS\r\nw7MFqZRqI1utfz5uu8zqTANO5y1zdvA5cfFr9/SwyLkhFQJgzTPM9DfEhwiK\r\nu0xVPc3zySmI2zDNSJA0EeMf1E1pgd9Lb1GU5LIAsZYGt4gP3SnHdiVTPt7O\r\nX7EXexEx43CjACmwmUjs8/gOIp0PyOjKjsTTRSYG+r3kD637ZDoFB127tpq1\r\nEdRxeKrr+FyUyKG0k0zppq1v9LHuhgY1iPo5+8LaXtVUyNCzgy1s9NwEKmfa\r\n6ZuF3KPyY5TbkWtzhoUMgZB84LJe8s9krC0qa6+I2XVOUAAXUSDovrmmUzQk\r\nytLuuVxcbWlEO0C/NxY2MQ92mbk+uMhRWL3ovGievGIvKBU3oRiVJwByPHPv\r\n4oVgfgxvZ7oHbN8edPWpdJPbKRsSVY5S4+rsL2+n9a9t4NrBKCFXh98njmJZ\r\nb6PfjXVU3I2yWgFcT+CTXMVYzc6lnIjd80Gbdp9XVjfhagHVdkHt3UX7XIjy\r\nV9d3CwufFbjU9POU9uS9qnHFxx90jjhOMpI=\r\n=JwAP\r\n-----END PGP SIGNATURE-----\r\n","size":9165,"noattachment":false,"key":"/coffee/-/coffee-5.5.0.tgz"},"_npmUser":{"name":"fengmk2","email":"fengmk2@gmail.com"},"directories":{},"maintainers":[{"name":"atian25","email":"atian25@qq.com"},{"name":"dead_horse","email":"dead_horse@qq.com"},{"name":"popomore","email":"sakura9515@gmail.com"},{"name":"fengmk2","email":"fengmk2@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/coffee_5.5.0_1669101330393_0.9227764116039447"},"_hasShrinkwrap":false,"readme":"# Coffee\n\nTest command line on Node.js.\n\n---\n\n[![NPM version](https://img.shields.io/npm/v/coffee.svg?style=flat)](https://npmjs.org/package/coffee)\n[![Build Status](https://img.shields.io/travis/node-modules/coffee.svg?style=flat)](https://travis-ci.org/node-modules/coffee)\n[![codecov.io](https://img.shields.io/codecov/c/github/node-modules/coffee.svg?style=flat)](http://codecov.io/github/node-modules/coffee?branch=master)\n[![NPM downloads](http://img.shields.io/npm/dm/coffee.svg?style=flat)](https://npmjs.org/package/coffee)\n\n## Install\n\n```bash\n$ npm i coffee --save-dev\n```\n\n## Usage\n\nCoffee is useful for test command line in test frammework (like Mocha).\n\n### Fork\n\nYou can use `fork` for spawning Node processes.\n\n```js\nconst coffee = require('coffee');\n\ndescribe('cli', () => {\n  it('should fork node cli', () => {\n    return coffee.fork('/path/to/file.js')\n    .expect('stdout', '12\\n')\n    .expect('stderr', /34/)\n    .expect('code', 0)\n    .end();\n  });\n});\n```\n\nIn file.js\n\n```js\nconsole.log(12);\nconsole.error(34);\n```\n\nYou can pass `args` and `opts` to [child_process fork](https://nodejs.org/api/child_process.html#child_process_child_process_fork_modulepath_args_options).\n\n```js\ncoffee.fork('/path/to/file.js', [ 'args' ], { execArgv: [ '--inspect' ]})\n  .expect('stdout', '12\\n')\n  .expect('stderr', '34\\n')\n  .expect('code', 0)\n  .end();\n```\n\nAnd more:\n\n```js\ncoffee.fork('/path/to/file.js')\n  // print origin stdio\n  .debug()\n\n  // inject a script\n  .beforeScript(mockScript)\n\n  // interact with prompt\n  .waitForPrompt()\n  .write('tz\\n')\n\n  // string strict equals\n  .expect('stdout', 'abcdefg')\n  // regex\n  .expect('stdout', /^abc/)\n  // multiple\n  .expect('stdout', [ 'abcdefg', /abc/ ])\n  .expect('code', 0)\n  .end();\n```\n\nsee the API chapter below for more details.\n\n### Spawn\n\nYou can also use `spawn` for spawning normal shell scripts.\n\n```js\ncoffee.spawn('cat')\n  .write('1')\n  .write('2')\n  .expect('stdout', '12')\n  .expect('code', 0)\n  .end();\n```\n\n## Rule\n\n### code\n\nCheck the exit code.\n\n```js\ncoffee.fork('/path/to/file.js', [ 'args' ])\n  .expect('code', 0)\n  // .expect('code', 1)\n  .end();\n```\n\n### stdout / stderr\n\nCheck the stdout and stderr.\n\n```js\ncoffee.fork('/path/to/file.js', [ 'args' ])\n  .expect('stdout', '12\\n')\n  .expect('stderr', '34\\n')\n  .expect('code', 0)\n  .end();\n```\n\n### custom\n\nSupport custom rules, see `test/fixtures/extendable` for more details.\n\n```js\nconst { Coffee, Rule } = require('coffee');\n\nclass FileRule extends Rule {\n  constructor(opts) {\n    super(opts);\n    // `args` is which pass to `expect(type, ...args)`, `expected` is the first args.\n    const { args, expected } = opts;\n  }\n\n  assert(actual, expected, message) {\n    // do sth\n    return super.assert(fs.existsSync(expected), true, `should exists file ${expected}`);\n  }\n}\n\nclass MyCoffee extends Coffee {\n  constructor(...args) {\n    super(...args);\n    this.setRule('file', FileRule);\n  }\n\n  static fork(modulePath, args, opt) {\n    return new MyCoffee({\n      method: 'fork',\n      cmd: modulePath,\n      args,\n      opt,\n    });\n  }\n}\n```\n\nUsage:\n\n```js\n// test/custom.test.js\nconst coffee = require('MyCoffee');\ncoffee.fork('/path/to/file.js', [ 'args' ])\n  .expect('file', `${root}/README.md`);\n  .notExpect('file', `${root}/not-exist`);\n```\n\n## Support multiple process coverage with nyc\n\nRecommend to use [nyc] for coverage, you can use [any test frammework supported by nyc](https://istanbul.js.org/docs/tutorials/).\n\n## API\n\n### coffee.spawn\n\nRun command using `child_process.spawn`, then return `Coffee` instance.\n\nArguments see [child_process.spawn](http://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options)\n\n### coffee.fork\n\nRun command using `child_process.fork`, then return `Coffee` instance.\n\nArguments see [child_process.fork](http://nodejs.org/api/child_process.html#child_process_child_process_fork_modulepath_args_options)\n\n### coffee.Coffee\n\nAssertion object\n\n#### coffee.expect(type, ...args)\n\nAssert type with expected value, expected value can be string, regular expression, and array.\n\n```js\ncoffee.spawn('echo', [ 'abcdefg' ])\n  .expect('stdout', 'abcdefg')\n  .expect('stdout', /^abc/)\n  .expect('stdout', [ 'abcdefg', /abc/ ])\n  .end();\n```\n\nAccept type: `stdout` / `stderr` / `code` / `error`, see built-in rules description above.\n\n#### coffee.notExpect(type, ...args)\n\nThe opposite assertion of `expect`.\n\n#### coffee.includes(type, ...args)\n\nAssert type with expected string value, expected value should be string only.\n\n```js\ncoffee.spawn('echo', [ 'abcdefg' ])\n  .includes('stdout', 'abc')\n  .expect('stdout', [ 'abc', 'efg' ])\n  .end();\n```\n\nAccept type: `stdout` / `stderr`, see built-in rules description above.\n\n#### coffee.notIncludes(type, ...args)\n\nThe opposite assertion of `includes`.\n\n#### coffee.write(data)\n\nWrite data to stdin.\n\n```js\ncoffee.fork(path.join(fixtures, 'stdin.js'))\n  .write('1\\n')\n  .write('2')\n  .expect('stdout', '1\\n2')\n  .end();\n```\n\n#### coffee.writeKey(...args)\n\nWrite special key sequence to stdin, support `UP` / `DOWN` / `LEFT` / `RIGHT` / `ENTER` / `SPACE`.\n\nAll args will join as one key.\n\n```js\ncoffee.fork(path.join(fixtures, 'stdin.js'))\n  .writeKey('1', 'ENTER', '2')\n  .expect('stdout', '1\\n2')\n  .end();\n```\n\n#### coffee.waitForPrompt(bool)\n\nIf you set false, coffee will write stdin immediately, otherwise will wait for `prompt` message.\n\n```js\ncoffee.fork('/path/to/cli', [ 'abcdefg' ])\n  .waitForPrompt()\n  .write('tz\\n')\n  // choose the second item\n  .writeKey('DOWN', 'DOWN', 'ENTER');\n  .end(done);\n```\n\n**cli process should emit `prompt` message:**\n\n> Or use `coffee.on('stdout', callback)` instead, see docs below.\n\n```js\nconst readline = require('readline');\n\nconst rl = readline.createInterface({\n  input: process.stdin,\n  output: process.stdout\n});\n\nfunction ask(q, callback) {\n  process.send({ type: 'prompt' });\n  rl.question(q, callback);\n}\n\nask('What\\'s your name? ', answer => {\n  console.log(`hi, ${answer}`);\n  ask('How many coffee do you want? ', answer => {\n    console.log(`here is your ${answer} coffee`);\n    rl.close();\n  });\n});\n```\n\n#### coffee.end([callback])\n\nCallback will be called after completing the assertion, the first argument is Error if throw exception.\n\n```js\ncoffee.fork('path/to/cli')\n  .expect('stdout', 'abcdefg')\n  .end(done);\n\n// recommended to left undefind and use promise style.\nconst { stdout, stderr, code } = await coffee.fork('path/to/cli').end();\nassert(stdout.includes(abcdefg));\n```\n\n#### coffee.on(event, callback)\n\nEmit `stdout/stderr` event.\n\nuse for kill long-run process:\n\n```js\ncoffee.fork('path/to/cli')\n  .on('stdout', (buf, { proc }) => {\n    if (buf.includes('egg-ready')) {\n      proc.exitCode = 0;\n      proc.kill();\n    }\n  })\n  .expect('stdout', 'egg-ready')\n  .end(done);\n```\n\nuse for prompt:\n\n```js\n// do not call `waitForPrompt` / `write` / `writeKey`\ncoffee.fork('path/to/cli')\n  .on('stdout', (buf, { proc }) => {\n    if (buf.includes('Your Name: ')) {\n      proc.stdin.write('TZ\\n');\n    }\n  })\n  .expect('stdout', 'Your Name: TZ\\n')\n  .end(done);\n```\n\n#### coffee.debug(level)\n\nWrite data to process.stdout and process.stderr for debug\n\n`level` can be\n\n- 0 (default): pipe stdout + stderr\n- 1: pipe stdout\n- 2: pipe stderr\n- false: disable\n\nAlternative you can use `COFFEE_DEBUG` env.\n\n#### coffee.coverage()\n\nIf you set false, coffee will not generate coverage.json, default: true.\n\n#### coffee.beforeScript(scriptFile)\n\nAdd a hook script before fork child process run.\n\n### coffee.Rule\n\nAssertion Rule base class.\n\n## LICENSE\n\nCopyright (c) 2017 - 2019 node-modules. Licensed under the MIT license.\n\n[nyc]: https://github.com/istanbuljs/nyc\n","publish_time":1669101330609,"_cnpm_publish_time":1669101330609,"dist-tags":{"latest":"5.5.1","latest-3":"3.3.3","latest-4":"4.2.1"}}