{"action":"created","issue":{"url":"https://api.github.com/repos/substack/tape/issues/224","labels_url":"https://api.github.com/repos/substack/tape/issues/224/labels{/name}","comments_url":"https://api.github.com/repos/substack/tape/issues/224/comments","events_url":"https://api.github.com/repos/substack/tape/issues/224/events","html_url":"https://github.com/substack/tape/pull/224","id":123109731,"number":224,"title":"Add flag to require modules before running tests","user":{"login":"mstade","id":605731,"avatar_url":"https://avatars.githubusercontent.com/u/605731?v=3","gravatar_id":"","url":"https://api.github.com/users/mstade","html_url":"https://github.com/mstade","followers_url":"https://api.github.com/users/mstade/followers","following_url":"https://api.github.com/users/mstade/following{/other_user}","gists_url":"https://api.github.com/users/mstade/gists{/gist_id}","starred_url":"https://api.github.com/users/mstade/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mstade/subscriptions","organizations_url":"https://api.github.com/users/mstade/orgs","repos_url":"https://api.github.com/users/mstade/repos","events_url":"https://api.github.com/users/mstade/events{/privacy}","received_events_url":"https://api.github.com/users/mstade/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":9,"created_at":"2015-12-19T20:45:17Z","updated_at":"2015-12-21T21:48:33Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/substack/tape/pulls/224","html_url":"https://github.com/substack/tape/pull/224","diff_url":"https://github.com/substack/tape/pull/224.diff","patch_url":"https://github.com/substack/tape/pull/224.patch"},"body":"By adding the `--require` flag (and `-r` alias) we allow users to require modules before running their tests. An example of this might be adding source-map-support, like so:\r\n\r\n```bash\r\n$ tape -r source-map-support/register test/*.js\r\n```\r\n\r\nAnother example might be to install the [babel require hook](http://babeljs.io/docs/usage/require/):\r\n\r\n```bash\r\n$ tape -r babel-register test/*.js\r\n```\r\n\r\nAnother potential benefit is the ability to more easily run external test suites: \r\n\r\n```bash\r\n$ npm install test-suite-rfc1337\r\n$ tape -r test-suite-rfc1337\r\n```\r\n\r\nModules are found using the node module resolution algorithm, so if one wants to load a local module it is necessary to prepend `./` or `../`, like so:\r\n\r\n```bash\r\n$ tape -r ./my/local/module\r\n```"},"comment":{"url":"https://api.github.com/repos/substack/tape/issues/comments/166433436","html_url":"https://github.com/substack/tape/pull/224#issuecomment-166433436","issue_url":"https://api.github.com/repos/substack/tape/issues/224","id":166433436,"user":{"login":"mstade","id":605731,"avatar_url":"https://avatars.githubusercontent.com/u/605731?v=3","gravatar_id":"","url":"https://api.github.com/users/mstade","html_url":"https://github.com/mstade","followers_url":"https://api.github.com/users/mstade/followers","following_url":"https://api.github.com/users/mstade/following{/other_user}","gists_url":"https://api.github.com/users/mstade/gists{/gist_id}","starred_url":"https://api.github.com/users/mstade/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mstade/subscriptions","organizations_url":"https://api.github.com/users/mstade/orgs","repos_url":"https://api.github.com/users/mstade/repos","events_url":"https://api.github.com/users/mstade/events{/privacy}","received_events_url":"https://api.github.com/users/mstade/received_events","type":"User","site_admin":false},"created_at":"2015-12-21T21:48:32Z","updated_at":"2015-12-21T21:48:32Z","body":"Some thoughts:\r\n\r\n### Order is not preserved\r\n\r\nConsider the following:\r\n\r\n```bash\r\n$ tape -r first second -r third\r\n```\r\n\r\nOrder is preserved for flags and globs separately, so the order of execution in the above example is `first, third, second`. Would it be more intuitive and meaningful to preserve the order entirely? Could this help with things like #126 where the node process never ends because of lingering handles? I.e. if order was preserved, then setup and teardown could be extracted into modules of their own, and common logic shared:\r\n\r\n```bash\r\n$ tape -r setup-db test/*.test.js -r teardown-db\r\n```\r\n\r\nSure enough, this can be done *without* `-r` as well, by having setup and teardown files:\r\n\r\n```bash\r\n$ tape test/setup-db.js test/*.test.js test/teardown-db.js\r\n```\r\n\r\nBut this makes it more difficult to share such modules, for instance on a team that does a lot of similar work. I'm not sure which way to lean on this.\r\n\r\n### Parameterizing modules\r\n\r\nParameterizing modules can be done using environment variables:\r\n\r\n```bash\r\n$ BABEL_ENV=production tape -r babel-register test/*.js\r\n```\r\n\r\nIs there a need for parameterization of modules, that can't be solved with environment variables? If so, should the recommended approach be to implement a local module and load that? E.g.:\r\n\r\n```bash\r\n$ cat ./my-esoteric-needs\r\nvar mod = require('some-module')\r\nmod.installGlobablly({ some: 'parameters' })\r\n\r\n$ tape -r ./my-esoteric-needs test/*.js\r\n```"}}