{"action":"reopened","issue":{"url":"https://api.github.com/repos/danvk/mocha-react/issues/1","labels_url":"https://api.github.com/repos/danvk/mocha-react/issues/1/labels{/name}","comments_url":"https://api.github.com/repos/danvk/mocha-react/issues/1/comments","events_url":"https://api.github.com/repos/danvk/mocha-react/issues/1/events","html_url":"https://github.com/danvk/mocha-react/issues/1","id":59893380,"number":1,"title":"Question: Any ideas on how to transpile only one file at a time?","user":{"login":"adjavaherian","id":3650448,"avatar_url":"https://avatars.githubusercontent.com/u/3650448?v=3","gravatar_id":"","url":"https://api.github.com/users/adjavaherian","html_url":"https://github.com/adjavaherian","followers_url":"https://api.github.com/users/adjavaherian/followers","following_url":"https://api.github.com/users/adjavaherian/following{/other_user}","gists_url":"https://api.github.com/users/adjavaherian/gists{/gist_id}","starred_url":"https://api.github.com/users/adjavaherian/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adjavaherian/subscriptions","organizations_url":"https://api.github.com/users/adjavaherian/orgs","repos_url":"https://api.github.com/users/adjavaherian/repos","events_url":"https://api.github.com/users/adjavaherian/events{/privacy}","received_events_url":"https://api.github.com/users/adjavaherian/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-03-05T01:59:46Z","updated_at":"2015-03-05T15:37:32Z","closed_at":null,"body":"I'm using the compiler solution you've posted pretty much as is, it works great and stubs as expected.  But, if you run two tests, one of which is stubbed and one of which is the actual test for what you may have stubbed out in previous test, then the actual component for the test has already been stubbed out globally, so the second test will fail.  \r\n\r\nFor example, here's spec1 and spec2.  spec1 tests the HeaderNav component, which includes the LoginStatus component.  Its stubbed out properly, in the first test, but then when spec2 starts, LoginStatus is already stubbed, compiled and cached.\r\n\r\n```yaml\r\n//mocha.opts\r\ntest/specs/*.js\r\n--recursive\r\n--compilers jsx:test/jsx-compiler.js\r\n--reporter spec\r\n```\r\n```javascript\r\n//spec1.js\r\ndescribe('Spec 1', function() {\r\n\r\n    it('renders the HeaderNav class', function() {\r\n\r\n        (function(){\r\n            global.reactModulesToStub = ['LoginStatus.jsx'];\r\n        })();\r\n\r\n        var MyComponent = require('../../app/modules/HeaderNav.jsx'),\r\n            TestContext = require('./../lib/TestContext').getRouterComponent(MyComponent),\r\n            component = TestContext.component;\r\n\r\n        console.log(global.document.body.innerHTML);\r\n\r\n        TestUtils.findRenderedDOMComponentWithClass(\r\n            component, 'HeaderNav');\r\n    });\r\n\r\n    it('1 x 1', function() {\r\n        assert.equal(1, (1 * 1), '1 x 1 = 1');\r\n    });\r\n\r\n});\r\n\r\n//spec2.js\r\ndescribe('Spec 2', function() {\r\n\r\n    it('renders LoginStatus', function() {\r\n\r\n        var MyComponent = require('../../app/modules/LoginStatus.jsx'),\r\n            TestContext = require('./../lib/TestContext').getRouterComponent(MyComponent),\r\n            component = TestContext.component;\r\n\r\n        console.log(global.document.body.innerHTML);\r\n\r\n        TestUtils.findRenderedDOMComponentWithClass(\r\n            component, 'LoginStatus');\r\n    });\r\n\r\n    it('1 x 1', function() {\r\n        assert.equal(1, (1 * 1), '1 x 1 = 1');\r\n    });\r\n\r\n});\r\n\r\n//HeaderNav.jsx\r\nvar React = require('react');\r\nvar Link = require('../modules/Link');\r\nvar paths = require('../helpers/paths');\r\nvar LoginStatus = require('./LoginStatus');\r\nvar SitemapNav = require('./SitemapNav');\r\n\r\nvar HeaderNav = React.createClass({\r\n    displayName: 'HeaderNav',\r\n    render: function() {\r\n        return (\r\n            <div className=\"HeaderNav\">\r\n                <header className=\"header-wrapper\">\r\n                    <Link className=\"header-logo\" to={paths.FrontPage} />\r\n                    <nav className=\"header-nav hidden-sm\">\r\n                        <Link className=\"header-nav-link\" to={paths.SearchPage}> This </Link>\r\n                        <Link className=\"header-nav-link\" to={paths.SearchPage}> That </Link>\r\n                        <Link className=\"header-nav-link\" to={paths.UserItemsPage}> Other </Link>\r\n                    </nav>\r\n                    <LoginStatus />\r\n                </header>\r\n            </div>\r\n        );\r\n    }\r\n});\r\n\r\n\r\nmodule.exports = HeaderNav;\r\n```\r\n\r\nLoginStatus needs to be tested on its own, but stubbed out when included in HeaderNav.  This is the most real world solution I have come across.  So figuring it out would be huge for React testing with React-Router, Flux, etc.  I didn't post LoginStatus, but its a JSX and outputs a simple component, but requires React-Router and Flux, hence the TestContext, which adds that stuff.  \r\n\r\nBut the real problem is that I don't want to stub LoginStatus for my second test.  I've added an afterEach to the mocha helper, but that does nothing, because using require.extensions loads all .jsx modules up front.\r\n \r\n```javascript\r\nafterEach(function(){\r\n    global.reactModulesToStub = [];\r\n});\r\n```"}}