{"action":"created","issue":{"url":"https://api.github.com/repos/TypeStrong/ts-node/issues/365","repository_url":"https://api.github.com/repos/TypeStrong/ts-node","labels_url":"https://api.github.com/repos/TypeStrong/ts-node/issues/365/labels{/name}","comments_url":"https://api.github.com/repos/TypeStrong/ts-node/issues/365/comments","events_url":"https://api.github.com/repos/TypeStrong/ts-node/issues/365/events","html_url":"https://github.com/TypeStrong/ts-node/issues/365","id":237213753,"number":365,"title":"Using with Mocha breaks Sinon","user":{"login":"aendrew","id":185041,"avatar_url":"https://avatars0.githubusercontent.com/u/185041?v=3","gravatar_id":"","url":"https://api.github.com/users/aendrew","html_url":"https://github.com/aendrew","followers_url":"https://api.github.com/users/aendrew/followers","following_url":"https://api.github.com/users/aendrew/following{/other_user}","gists_url":"https://api.github.com/users/aendrew/gists{/gist_id}","starred_url":"https://api.github.com/users/aendrew/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aendrew/subscriptions","organizations_url":"https://api.github.com/users/aendrew/orgs","repos_url":"https://api.github.com/users/aendrew/repos","events_url":"https://api.github.com/users/aendrew/events{/privacy}","received_events_url":"https://api.github.com/users/aendrew/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-06-20T13:42:31Z","updated_at":"2017-06-23T11:58:23Z","closed_at":"2017-06-23T11:58:23Z","body":"I've run into an issue where using `ts-node` with Mocha via the `--compilers ts:ts-node/register` flag causes Sinon not work:\r\n\r\n*index.ts*\r\n```js\r\nimport {readFileSync} from 'fs';\r\n\r\nexport default function() {\r\n    return readFileSync(`${__dirname}/fixture.txt`, {encoding: 'utf-8'});\r\n}\r\n```\r\n\r\n*index.spec.ts*\r\n```js\r\ndescribe('stubbing aModule', () => {\r\n  let readFileSyncStub: sinon.SinonStub;\r\n\r\n  // This is where everything dies\r\n  beforeEach(() => {\r\n    readFileSyncStub = sinon.stub(fs, 'readFileSync').returns('boo-urns');\r\n  });\r\n\r\n  afterEach(() => {\r\n    readFileSyncStub.restore();\r\n  });\r\n\r\n  it('returns boo-urns', () => {\r\n    const result = aModule();\r\n    result.should.equal('boo-urns');\r\n  });\r\n});\r\n```\r\n*Mocha output*\r\n```\r\n> tsnode-mocha-sinon-test-case@1.0.0 test /Users/aendrew/Projects/tsnode-mocha-sinon-test-case\r\n> mocha --compilers ts:ts-node/register ./index.spec.ts\r\n\r\n\r\n\r\n  stubbing aModule\r\n    stubbed behaviour\r\n      1) \"before each\" hook for \"returns boo-urns\"\r\n      2) \"after each\" hook for \"returns boo-urns\"\r\n\r\n\r\n  0 passing (22ms)\r\n  2 failing\r\n```\r\n\r\nVery frustratingly, no error message whatsoever is reported, even when running with `DEBUG=*`.\r\n\r\n**However**, if you transpile to ES2017, everything runs flawlessly. This leads me to believe the issue is with `ts-node` itself.\r\n\r\nI have a full test-case here: https://github.com/aendrew/tsnode-mocha-sinon-test-case, including instructions on how to run it.\r\n\r\n**Update:** Should be noted I've been using Node8 for all of this. However, I tried downgrading to 6 and have the same issue, however, this time with slightly more in terms of error messaging:\r\n\r\n```\r\n  1) stubbing aModule stubbed behaviour \"before each\" hook for \"returns boo-urns\":\r\n     TypeError: Cannot read property 'sections' of undefined\r\n\r\n\r\n  2) stubbing aModule stubbed behaviour \"after each\" hook for \"returns boo-urns\":\r\n     TypeError: Cannot read property 'restore' of undefined\r\n```\r\n\r\nThe bit about sections in the first TypeError is illuminating as I think it implies the issue may have something to do with sourcemaps."},"comment":{"url":"https://api.github.com/repos/TypeStrong/ts-node/issues/comments/310647159","html_url":"https://github.com/TypeStrong/ts-node/issues/365#issuecomment-310647159","issue_url":"https://api.github.com/repos/TypeStrong/ts-node/issues/365","id":310647159,"user":{"login":"aendrew","id":185041,"avatar_url":"https://avatars0.githubusercontent.com/u/185041?v=3","gravatar_id":"","url":"https://api.github.com/users/aendrew","html_url":"https://github.com/aendrew","followers_url":"https://api.github.com/users/aendrew/followers","following_url":"https://api.github.com/users/aendrew/following{/other_user}","gists_url":"https://api.github.com/users/aendrew/gists{/gist_id}","starred_url":"https://api.github.com/users/aendrew/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aendrew/subscriptions","organizations_url":"https://api.github.com/users/aendrew/orgs","repos_url":"https://api.github.com/users/aendrew/repos","events_url":"https://api.github.com/users/aendrew/events{/privacy}","received_events_url":"https://api.github.com/users/aendrew/received_events","type":"User","site_admin":false},"created_at":"2017-06-23T11:58:23Z","updated_at":"2017-06-23T11:58:23Z","body":"This seems to be fixed in 3.1.0 by #368. THANK YOU! 🎉  🎊  🙌 "}}
{"actor":{"display_login":"aendrew"}}