{"action":"created","issue":{"url":"https://api.github.com/repos/hapijs/lab/issues/560","repository_url":"https://api.github.com/repos/hapijs/lab","labels_url":"https://api.github.com/repos/hapijs/lab/issues/560/labels{/name}","comments_url":"https://api.github.com/repos/hapijs/lab/issues/560/comments","events_url":"https://api.github.com/repos/hapijs/lab/issues/560/events","html_url":"https://github.com/hapijs/lab/issues/560","id":147853332,"number":560,"title":"allow passing context between before(), test() and after()","user":{"login":"nlf","id":424045,"avatar_url":"https://avatars.githubusercontent.com/u/424045?v=3","gravatar_id":"","url":"https://api.github.com/users/nlf","html_url":"https://github.com/nlf","followers_url":"https://api.github.com/users/nlf/followers","following_url":"https://api.github.com/users/nlf/following{/other_user}","gists_url":"https://api.github.com/users/nlf/gists{/gist_id}","starred_url":"https://api.github.com/users/nlf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nlf/subscriptions","organizations_url":"https://api.github.com/users/nlf/orgs","repos_url":"https://api.github.com/users/nlf/repos","events_url":"https://api.github.com/users/nlf/events{/privacy}","received_events_url":"https://api.github.com/users/nlf/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/hapijs/lab/labels/request","name":"request","color":"c7def8"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2016-04-12T19:41:16Z","updated_at":"2016-04-12T19:58:44Z","closed_at":null,"body":"so writing a bunch of CRUD tests today it occurred to me that it would be really convenient if i could pass variables around instead of relying on vars defined as a `let` in an outer scope\r\n\r\nfor example, what i currently have:\r\n\r\n```js\r\nlet userId;\r\nbefore(() => {\r\n  return db.users.find({ id: something }).then((user) => {\r\n    userId = user.id;\r\n  });\r\n});\r\n\r\nlet createdId;\r\ntest(() => {\r\n  return server.inject({ method: 'post', url: `/users/${userId}/stuff`, payload: something }).then((res) => {\r\n\r\n   expect(blahblah);\r\n   createdId = res.result.id;\r\n  });\r\n});\r\n\r\nafter(() => {\r\n  return db.users_stuff.destroy({ id: createdId });\r\n});\r\n```\r\n\r\nvs what i would propose as more usable:\r\n\r\n```js\r\nbefore(() => {\r\n  return db.users.find({ id: something });\r\n});\r\n\r\ntest((user) => {\r\n  return server.inject({ method: 'post', url: `/users/${userId}/stuff`, payload: something }).then((res) => {\r\n    expect(blahblah);\r\n    return res.result.id;\r\n  });\r\n});\r\n\r\n// note this could also work as an afterEach if there are multiple tests and they all return an id\r\nafter((id) => {\r\n  return db.users_stuff.destroy({ id: id });\r\n});\r\n```\r\n\r\nobviously using callbacks instead of promises would mean having to change the parameters passed to test() and after(), but i think if we pass `done` as the first argument and the results of the previous steps after would be a minimally invasive change (i.e. people could ignore this new feature and not have their tests expode).\r\n\r\nthoughts?"},"comment":{"url":"https://api.github.com/repos/hapijs/lab/issues/comments/209078896","html_url":"https://github.com/hapijs/lab/issues/560#issuecomment-209078896","issue_url":"https://api.github.com/repos/hapijs/lab/issues/560","id":209078896,"user":{"login":"nlf","id":424045,"avatar_url":"https://avatars.githubusercontent.com/u/424045?v=3","gravatar_id":"","url":"https://api.github.com/users/nlf","html_url":"https://github.com/nlf","followers_url":"https://api.github.com/users/nlf/followers","following_url":"https://api.github.com/users/nlf/following{/other_user}","gists_url":"https://api.github.com/users/nlf/gists{/gist_id}","starred_url":"https://api.github.com/users/nlf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nlf/subscriptions","organizations_url":"https://api.github.com/users/nlf/orgs","repos_url":"https://api.github.com/users/nlf/repos","events_url":"https://api.github.com/users/nlf/events{/privacy}","received_events_url":"https://api.github.com/users/nlf/received_events","type":"User","site_admin":false},"created_at":"2016-04-12T19:58:44Z","updated_at":"2016-04-12T19:58:44Z","body":"how do before and after work with running tests in parallel currently? i don't see where this would impact anything in that respect, they still run in order"}}