UNPKG

7.71 kBMarkdownView Raw
1# Developing for Jasmine Core
2
3We welcome your contributions! Thanks for helping make Jasmine a better project for everyone. Please review the backlog and discussion lists before starting work. What you're looking for may already have been done. If it hasn't, the community can help make your contribution better. If you want to contribute but don't know what to work on, [issues tagged ready for work](https://github.com/jasmine/jasmine/labels/ready%20for%20work) should have enough detail to get started.
4
5## Links
6
7- [Jasmine Google Group](http://groups.google.com/group/jasmine-js)
8- [Jasmine-dev Google Group](http://groups.google.com/group/jasmine-js-dev)
9- [Jasmine on PivotalTracker](https://www.pivotaltracker.com/n/projects/10606)
10
11## General Workflow
12
13Please submit pull requests via feature branches using the semi-standard workflow of:
14
15```bash
16git clone git@github.com:yourUserName/jasmine.git # Clone your fork
17cd jasmine # Change directory
18git remote add upstream https://github.com/jasmine/jasmine.git # Assign original repository to a remote named 'upstream'
19git fetch upstream # Fetch changes not present in your local repository
20git merge upstream/master # Sync local master with upstream repository
21git checkout -b my-new-feature # Create your feature branch
22git commit -am 'Add some feature' # Commit your changes
23git push origin my-new-feature # Push to the branch
24```
25
26Once you've pushed a feature branch to your forked repo, you're ready to open a pull request. We favor pull requests with very small, single commits with a single purpose.
27
28## Background
29
30### Directory Structure
31
32* `/src` contains all of the source files
33 * `/src/console` - Node.js-specific files
34 * `/src/core` - generic source files
35 * `/src/html` - browser-specific files
36* `/spec` contains all of the tests
37 * mirrors the source directory
38 * there are some additional files
39* `/dist` contains the standalone distributions as zip files
40* `/lib` contains the generated files for distribution as the Jasmine Rubygem and the Python package
41
42### Self-testing
43
44Note that Jasmine tests itself. The files in `lib` are loaded first, defining the reference `jasmine`. Then the files in `src` are loaded, defining the reference `jasmineUnderTest`. So there are two copies of the code loaded under test.
45
46The tests should always use `jasmineUnderTest` to refer to the objects and functions that are being tested. But the tests can use functions on `jasmine` as needed. _Be careful how you structure any new test code_. Copy the patterns you see in the existing code - this ensures that the code you're testing is not leaking into the `jasmine` reference and vice-versa.
47
48### `boot.js`
49
50__This is new for Jasmine 2.0.__
51
52This file does all of the setup necessary for Jasmine to work. It loads all of the code, creates an `Env`, attaches the global functions, and builds the reporter. It also sets up the execution of the `Env` - for browsers this is in `window.onload`. While the default in `lib` is appropriate for browsers, projects may wish to customize this file.
53
54For example, for Jasmine development there is a different `dev_boot.js` for Jasmine development that does more work.
55
56### Compatibility
57
58* Browser Minimum
59 * IE8
60 * Firefox 3.x
61 * Chrome ??
62 * Safari 5
63
64## Development
65
66All source code belongs in `src/`. The `core/` directory contains the bulk of Jasmine's functionality. This code should remain browser- and environment-agnostic. If your feature or fix cannot be, as mentioned above, please degrade gracefully. Any code that should only be in a non-browser environment should live in `src/console/`. Any code that depends on a browser (specifically, it expects `window` to be the global or `document` is present) should live in `src/html/`.
67
68### Install Dependencies
69
70Jasmine Core relies on Ruby and Node.js.
71
72To install the Ruby dependencies, you will need Ruby, Rubygems, and Bundler available. Then:
73
74 $ bundle
75
76...will install all of the Ruby dependencies. If the ffi gem fails to build its native extensions, you may need to manually install some system dependencies. On Ubuntu:
77
78 $ apt-get install gcc ruby ruby-dev libxml2 libxml2-dev libxslt1-dev
79
80...should get you to the point that `bundle` can install everything.
81
82To install the Node dependencies, you will need Node.js, Npm, and [Grunt](http://gruntjs.com/), the [grunt-cli](https://github.com/gruntjs/grunt-cli) and ensure that `grunt` is on your path.
83
84 $ npm install --local
85
86...will install all of the node modules locally. Now run
87
88 $ grunt
89
90...if you see that JSHint runs, your system is ready.
91
92### How to write new Jasmine code
93
94Or, How to make a successful pull request
95
96* _Do not change the public interface_. Lots of projects depend on Jasmine and if you aren't careful you'll break them
97* _Be environment agnostic_ - server-side developers are just as important as browser developers
98* _Be browser agnostic_ - if you must rely on browser-specific functionality, please write it in a way that degrades gracefully
99* _Write specs_ - Jasmine's a testing framework; don't add functionality without test-driving it
100* _Write code in the style of the rest of the repo_ - Jasmine should look like a cohesive whole
101* _Ensure the *entire* test suite is green_ in all the big browsers, Node, and JSHint - your contribution shouldn't break Jasmine for other users
102
103Follow these tips and your pull request, patch, or suggestion is much more likely to be integrated.
104
105### Running Specs
106
107Jasmine uses the [Jasmine Ruby gem](http://github.com/jasmine/jasmine-gem) to test itself in browser.
108
109 $ bundle exec rake jasmine
110
111...and then visit `http://localhost:8888` to run specs.
112
113Jasmine uses the [Jasmine NPM package](http://github.com/jasmine/jasmine-npm) to test itself in a Node.js/npm environment.
114
115 $ grunt execSpecsInNode
116
117...and then the results will print to the console. All specs run except those that expect a browser (the specs in `spec/html` are ignored).
118
119The easiest way to run the tests in **Internet Explorer** is to run a VM that has IE installed. It's easy to do this with VirtualBox.
120
1211. Download and install [VirtualBox](https://www.virtualbox.org/wiki/Downloads).
1221. Download a VM image [from Microsoft](https://developer.microsoft.com/en-us/microsoft-edge/tools/vms/). Select "VirtualBox" as the platform.
1231. Unzip the downloaded archive. There should be an OVA file inside.
1241. In VirtualBox, choose `File > Import Appliance` and select the OVA file. Accept the default settings in the dialog that appears. Now you have a Windows VM!
1251. Run the VM and start IE.
1261. With `bundle exec rake jasmine` running on your host machine, navigate to `http://10.0.2.2:8888` in IE.
127
128## Before Committing or Submitting a Pull Request
129
1301. Ensure all specs are green in browser *and* node
1311. Ensure JSHint is green with `grunt jshint`
1321. Build `jasmine.js` with `grunt buildDistribution` and run all specs again - this ensures that your changes self-test well
1331. Revert your changes to `jasmine.js` and `jasmine-html.js`
134 * We do this because `jasmine.js` and `jasmine-html.js` are auto-generated (as you've seen in the previous steps) and accepting multiple pull requests when this auto-generated file changes causes lots of headaches
135 * When we accept your pull request, we will generate these files as a separate commit and merge the entire branch into master
136
137Note that we use Travis for Continuous Integration. We only accept green pull requests.
138