{"action":"created","issue":{"url":"https://api.github.com/repos/mochajs/mocha/issues/1810","repository_url":"https://api.github.com/repos/mochajs/mocha","labels_url":"https://api.github.com/repos/mochajs/mocha/issues/1810/labels{/name}","comments_url":"https://api.github.com/repos/mochajs/mocha/issues/1810/comments","events_url":"https://api.github.com/repos/mochajs/mocha/issues/1810/events","html_url":"https://github.com/mochajs/mocha/issues/1810","id":96172709,"node_id":"MDU6SXNzdWU5NjE3MjcwOQ==","number":1810,"title":"Adding -p,--prepare option to allow async initialization before loading test files","user":{"login":"enobufs","id":930777,"node_id":"MDQ6VXNlcjkzMDc3Nw==","avatar_url":"https://avatars2.githubusercontent.com/u/930777?v=4","gravatar_id":"","url":"https://api.github.com/users/enobufs","html_url":"https://github.com/enobufs","followers_url":"https://api.github.com/users/enobufs/followers","following_url":"https://api.github.com/users/enobufs/following{/other_user}","gists_url":"https://api.github.com/users/enobufs/gists{/gist_id}","starred_url":"https://api.github.com/users/enobufs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/enobufs/subscriptions","organizations_url":"https://api.github.com/users/enobufs/orgs","repos_url":"https://api.github.com/users/enobufs/repos","events_url":"https://api.github.com/users/enobufs/events{/privacy}","received_events_url":"https://api.github.com/users/enobufs/received_events","type":"User","site_admin":false},"labels":[{"id":185748,"node_id":"MDU6TGFiZWwxODU3NDg=","url":"https://api.github.com/repos/mochajs/mocha/labels/feature","name":"feature","color":"CC9264","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":11,"created_at":"2015-07-20T22:04:47Z","updated_at":"2018-08-17T13:40:03Z","closed_at":null,"author_association":"NONE","body":"I came across a situation where async initialization before loading all test files has become necessary. The --require option allows us to some initialization tasks but this is synchronous. It would be really great if mocha offers a new option which allows us to give a path to an initialization files like this:\n\n```\n// mocha.ops\n-r test/require\n--prepare test/init_a\n--prepare test/init_b\n```\n\nThe init_x files would have something like this:\n\n``` javascript\nmodule.exports = function (cb) {\n    // do some async stuff\n    cb();\n}\n```\n\nor;\n\n``` javascript\nmodule.exports = function () {\n    // do some async stuff\n    return Promise.resolve().then(function () { /* do something */ });\n}\n```\n\nMy project started without needing such async initialization for testing. Now it is needed, but we already have a number of test cases that references some variables before `before handlers` are executed. Modifying all these test cases to do all the initialization in the before handlers are not realistic/doable at this point.\n\nWe have experimented the proposed option, in [this branch](https://github.com/DeNA/mocha/commit/05190610898540f3fe25c94b72f05b5466735e61), which works very well. This change is done off of `2.2.5` tag.\n\nPlease let me know if this has already been addressed or discussed elsewhere. If this feature is found useful to other users (I am sure it is), I will be more than happy to send a PR for an appropriate branch/revision.\n"},"comment":{"url":"https://api.github.com/repos/mochajs/mocha/issues/comments/413869329","html_url":"https://github.com/mochajs/mocha/issues/1810#issuecomment-413869329","issue_url":"https://api.github.com/repos/mochajs/mocha/issues/1810","id":413869329,"node_id":"MDEyOklzc3VlQ29tbWVudDQxMzg2OTMyOQ==","user":{"login":"krzkaczor","id":1814312,"node_id":"MDQ6VXNlcjE4MTQzMTI=","avatar_url":"https://avatars2.githubusercontent.com/u/1814312?v=4","gravatar_id":"","url":"https://api.github.com/users/krzkaczor","html_url":"https://github.com/krzkaczor","followers_url":"https://api.github.com/users/krzkaczor/followers","following_url":"https://api.github.com/users/krzkaczor/following{/other_user}","gists_url":"https://api.github.com/users/krzkaczor/gists{/gist_id}","starred_url":"https://api.github.com/users/krzkaczor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/krzkaczor/subscriptions","organizations_url":"https://api.github.com/users/krzkaczor/orgs","repos_url":"https://api.github.com/users/krzkaczor/repos","events_url":"https://api.github.com/users/krzkaczor/events{/privacy}","received_events_url":"https://api.github.com/users/krzkaczor/received_events","type":"User","site_admin":false},"created_at":"2018-08-17T13:40:03Z","updated_at":"2018-08-17T13:40:03Z","author_association":"NONE","body":"@enobufs nice work man! I am working on code generation tool for typescript and I wanted to programmatically run it at the very beginning of the test suite because later tests cases use generated code. I couldn't use before/after hooks because then generation would happen too late and `ts-node` would scream about compilation errors."}}
{"actor":{"display_login":"krzkaczor"}}