This repository has been archived by the owner on Nov 1, 2020. It is now read-only.
forked from adobe/brackets
-
Notifications
You must be signed in to change notification settings - Fork 0
Extension Unit Tests
Peter Flynn edited this page Sep 6, 2013
·
1 revision
Brackets includes a simple test-runner for internal use. You can leverage this same tool for any Brackets extensions you write (though not for other projects you're editing in Brackets... yet).
- Learn about the Jasmine unit-test framework.
- Add a
unittests.js
module in the root of your extension folder. - Write Jasmine test cases inside the module, using
describe() {}
blocks. [Here's an example](Simple "Hello World" extension#unittestjs). - Choose Debug > Run Tests
- Click the Extensions tab
- Click the name of your Jasmine block to run it
This is not the easiest to use setup yet. Watch out for these gotchas:
- You can open dev tools for the unit test window via its own "Show Developer Tools" button.
- You must disable caching once you open dev tools -- even if you've already done so in the dev tools for the main Brackets window.
- Your unit tests run in the test-runner window by default, so the Brackets UI DOM and certain Brackets modules won't be accessible. This may cause your code to fail.
- You can run tests in a clean Brackets window using
SpecRunnerUtils.createTestWindowAndRun()
, which avoids the above problem. But this setup is not well documented and has its own pitfalls -- your test code needs to be careful about whether it's accessing something in the test-runner window vs. the popup Brackets window (for example,$
vs.testWindow.$
). See ProjectManager-test for example code. Debugging tests inside these windows is also a bit tricky.