{"action":"created","issue":{"url":"https://api.github.com/repos/winstonjs/winston/issues/1295","repository_url":"https://api.github.com/repos/winstonjs/winston","labels_url":"https://api.github.com/repos/winstonjs/winston/issues/1295/labels{/name}","comments_url":"https://api.github.com/repos/winstonjs/winston/issues/1295/comments","events_url":"https://api.github.com/repos/winstonjs/winston/issues/1295/events","html_url":"https://github.com/winstonjs/winston/issues/1295","id":318378696,"number":1295,"title":"Unit test using winston-spy","user":{"login":"paulmbw","id":9769730,"avatar_url":"https://avatars2.githubusercontent.com/u/9769730?v=4","gravatar_id":"","url":"https://api.github.com/users/paulmbw","html_url":"https://github.com/paulmbw","followers_url":"https://api.github.com/users/paulmbw/followers","following_url":"https://api.github.com/users/paulmbw/following{/other_user}","gists_url":"https://api.github.com/users/paulmbw/gists{/gist_id}","starred_url":"https://api.github.com/users/paulmbw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paulmbw/subscriptions","organizations_url":"https://api.github.com/users/paulmbw/orgs","repos_url":"https://api.github.com/users/paulmbw/repos","events_url":"https://api.github.com/users/paulmbw/events{/privacy}","received_events_url":"https://api.github.com/users/paulmbw/received_events","type":"User","site_admin":false},"labels":[{"id":189158,"url":"https://api.github.com/repos/winstonjs/winston/labels/investigate","name":"investigate","color":"74E7BA","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2018-04-27T11:44:23Z","updated_at":"2018-04-29T19:33:07Z","closed_at":null,"author_association":"NONE","body":"Hi there!\r\n\r\nI'm having a little trouble with unit testing a method that makes use of winstonjs. Here is a brief example of the implementation:\r\n\r\n`router.all('/api', (req, res) => {\r\n    res.status(404);\r\n    logger.error('404 Not Found!');\r\n    res.end();\r\n  });\r\n`\r\n\r\nAnd here is the unit test:\r\n`before(() => {`\r\n  `  winston.add(winston.transports.Console);`\r\n    `winston.add(spyLogger, { spy });`\r\n  `});`\r\n\r\n ` after(() => {`\r\n    `winston.remove(winston.transports.Console);`\r\n    `winston.remove(spyLogger, { spy });`\r\n  `});`\r\n\r\n` it('should log 404 not found message', async () => {`\r\n   ` await request(app).get(<api_url>);`\r\n    `winston.error(notFoundLogMessage);`\r\n    `expect(spy.calledWith('error', notFoundLogMessage)).to.equal(true);`\r\n  `});`\r\n\r\nHowever, my unit tests fails the first time with this message:\r\n`Error: Transport already attached: console, assign a different name`\r\n`Error: Transport spyLogger not attached to this instance`\r\n\r\nWhen I run the tests for a second time, they pass. Is there something I am missing? Why does the test fail the first time?"},"comment":{"url":"https://api.github.com/repos/winstonjs/winston/issues/comments/385275444","html_url":"https://github.com/winstonjs/winston/issues/1295#issuecomment-385275444","issue_url":"https://api.github.com/repos/winstonjs/winston/issues/1295","id":385275444,"user":{"login":"ChrisAlderson","id":17688012,"avatar_url":"https://avatars3.githubusercontent.com/u/17688012?v=4","gravatar_id":"","url":"https://api.github.com/users/ChrisAlderson","html_url":"https://github.com/ChrisAlderson","followers_url":"https://api.github.com/users/ChrisAlderson/followers","following_url":"https://api.github.com/users/ChrisAlderson/following{/other_user}","gists_url":"https://api.github.com/users/ChrisAlderson/gists{/gist_id}","starred_url":"https://api.github.com/users/ChrisAlderson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ChrisAlderson/subscriptions","organizations_url":"https://api.github.com/users/ChrisAlderson/orgs","repos_url":"https://api.github.com/users/ChrisAlderson/repos","events_url":"https://api.github.com/users/ChrisAlderson/events{/privacy}","received_events_url":"https://api.github.com/users/ChrisAlderson/received_events","type":"User","site_admin":false},"created_at":"2018-04-29T19:33:07Z","updated_at":"2018-04-29T19:33:07Z","author_association":"MEMBER","body":"@indexzero, Managed to wrap the `winston-spy` code in the `LegacyTransportStream`. Here is the [code](https://gist.github.com/ChrisAlderson/2c6c52939c43b2dee4c7fedeec0f3e01)."}}
{"actor":{"display_login":"ChrisAlderson"}}