{"action":"created","issue":{"url":"https://api.github.com/repos/isaacs/node-tap/issues/166","labels_url":"https://api.github.com/repos/isaacs/node-tap/issues/166/labels{/name}","comments_url":"https://api.github.com/repos/isaacs/node-tap/issues/166/comments","events_url":"https://api.github.com/repos/isaacs/node-tap/issues/166/events","html_url":"https://github.com/isaacs/node-tap/issues/166","id":103944991,"number":166,"title":"Feature/How-To: Synchronous Tests w/Fail-Only Output","user":{"login":"tooolbox","id":4984708,"avatar_url":"https://avatars.githubusercontent.com/u/4984708?v=3","gravatar_id":"","url":"https://api.github.com/users/tooolbox","html_url":"https://github.com/tooolbox","followers_url":"https://api.github.com/users/tooolbox/followers","following_url":"https://api.github.com/users/tooolbox/following{/other_user}","gists_url":"https://api.github.com/users/tooolbox/gists{/gist_id}","starred_url":"https://api.github.com/users/tooolbox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tooolbox/subscriptions","organizations_url":"https://api.github.com/users/tooolbox/orgs","repos_url":"https://api.github.com/users/tooolbox/repos","events_url":"https://api.github.com/users/tooolbox/events{/privacy}","received_events_url":"https://api.github.com/users/tooolbox/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-08-30T20:36:17Z","updated_at":"2015-08-30T23:56:53Z","closed_at":null,"body":"I'm currently writing a number of file-processing scripts, and I wanted to do some assertions on the state of the files before and after.  I'm using Chai for this, which is fine; my script simply dies if an assertion fails.\r\n\r\nHowever, I'd like to make the assertions a little more descriptive.  I like the idea of using Tap, Mocha-style, with `describe()` and `it()`!  However, there's two problems/issues:\r\n\r\n- Tap seems to only run after my script has otherwise finished, whereas I'd like to run tests before, after, and in the middle of my processing routine.  (I'm guessing it's hooked onto the process end, but it's not obvious from the code.)  So some sort of synchronous method of running would be sweet.\r\n- I'd like to have Tap only output the reporter contents if a test fails.  So my script just runs, but if something goes wrong I get a big report about what went wrong and why.\r\n\r\nMy concept would be doing something like this:\r\n\r\n```js\r\nvar fs = require('fs');\r\nvar should = require('chai').should();\r\nvar tap = require('tap');\r\n\r\ntap.mochaGlobals();\r\n\r\nvar fileContent = fs.readFileSync('./testFile.txt');\r\ndescribe('the file when we start', function(){\r\n    it('should have content', function(){\r\n        fileContent.should.exist;\r\n    });\r\n});\r\n\r\n// process the file in some way\r\n\r\ndescribe('the file when we end', function(){\r\n    it('should be changed in some way', function(){\r\n        fileContent.should.contain('new stuff string!');\r\n    });\r\n});\r\n\r\nfs.writeFileSync(fileContent, './changedFile.txt');\r\n```\r\n\r\n*(Inline diff reporting on failure is also something I'd like to have, but I'm pretty sure that's possible with the various reporters that can be hooked into Tap.)*\r\n\r\nI'm wondering if this is possible already and I just didn't realize it (maybe I'm using the API incorrectly--possibly I need to use `.end()` somewhere?), or if it could be added.  I'm open to doing the work to add it if it seems within reason--I would need to be pointed in the right direction.\r\n\r\nThanks!"},"comment":{"url":"https://api.github.com/repos/isaacs/node-tap/issues/comments/136218144","html_url":"https://github.com/isaacs/node-tap/issues/166#issuecomment-136218144","issue_url":"https://api.github.com/repos/isaacs/node-tap/issues/166","id":136218144,"user":{"login":"isaacs","id":9287,"avatar_url":"https://avatars.githubusercontent.com/u/9287?v=3","gravatar_id":"","url":"https://api.github.com/users/isaacs","html_url":"https://github.com/isaacs","followers_url":"https://api.github.com/users/isaacs/followers","following_url":"https://api.github.com/users/isaacs/following{/other_user}","gists_url":"https://api.github.com/users/isaacs/gists{/gist_id}","starred_url":"https://api.github.com/users/isaacs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/isaacs/subscriptions","organizations_url":"https://api.github.com/users/isaacs/orgs","repos_url":"https://api.github.com/users/isaacs/repos","events_url":"https://api.github.com/users/isaacs/events{/privacy}","received_events_url":"https://api.github.com/users/isaacs/received_events","type":"User","site_admin":false},"created_at":"2015-08-30T23:56:53Z","updated_at":"2015-08-30T23:56:53Z","body":"When you run the file with the tap bin, you get this by default:\r\n\r\n```\r\n$ tap m.js\r\nm.js .................................................. 2/2\r\ntotal ................................................. 2/2\r\n\r\n  2 passing (181.505ms)\r\n\r\n  ok\r\n```\r\n\r\nIf there's a failure, you get something like this:\r\n\r\n```\r\n$ tap m.js\r\nm.js .................................................. 1/2\r\n  the file when we end\r\n  not ok should be changed in some way\r\n    at:\r\n      file: m.js\r\n      line: 19\r\n      column: 28\r\n    showDiff: false\r\n    actual: |-\r\n      ok\r\n      old junk string!\r\n    expected: null\r\n    message: \"AssertionError: expected 'ok\\\\nold junk string!' to include 'new stuff string!'\"\r\n    source: |\r\n      fileContent.should.contain('new stuff string!');\r\n    stack: |\r\n      m.js:19:28\r\n      Test.<anonymous> (lib/assert.js:235:7)\r\n      Test.ASSERT [as _currentAssert] (lib/test.js:1080:15)\r\n      it (lib/mocha.js:28:7)\r\n      m.js:18:5\r\n      lib/mocha.js:45:7\r\n      Test.test (lib/test.js:404:27)\r\n      describe (lib/mocha.js:44:7)\r\n\r\ntotal ................................................. 1/2\r\n\r\n\r\n  1 passing (198.216ms)\r\n  1 failing\r\n```"}}