You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Contributing.md
+22-16Lines changed: 22 additions & 16 deletions
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,12 @@
2
2
3
3
jsdom is, as said in our tagline, “A JavaScript implementation of the DOM and HTML standards.” Anything that helps us be better at that is welcome.
4
4
5
+
## Yarn
6
+
7
+
We use the [Yarn](https://yarnpkg.com/) package manager to manage dependencies and run the scripts defined in `package.json`. It is similar to npm, but contains fewer bugs for our purposes. If you make changes which add or remove dependencies, make sure you commit the `yarn.lock` file which it generates.
8
+
9
+
You can probably get away with using npm for most contributions, as long as you are not adding or removing dependencies. You'll have to mentally translate the Yarn commands we give into npm ones, however.
10
+
5
11
## Architecture
6
12
7
13
jsdom is a blend of old and new code. Some of its older and less-touched corners may look different from newer work. Here we'll describe the modern setup, but you might encounter parts of the codebase that don't fit this model, or that seem unnecessarily baroque (like the directory structure in `lib/`).
@@ -13,7 +19,7 @@ As such, most web platform classes present in jsdom are implemented in two parts
13
19
- An IDL file, such as [`Attr.idl`](https://github.com/tmpvar/jsdom/blob/master/lib/jsdom/living/attributes/Attr.idl), drawn more or less straight from the spec
14
20
- An implementation file, such as [`Attr-impl.js`](https://github.com/tmpvar/jsdom/blob/master/lib/jsdom/living/attributes/Attr-impl.js), containing the relevant implementation logic
15
21
16
-
Our build step (`npm run prepublish`) then generates a public API file (e.g. `Attr.js`) which takes care of all the Web IDL-derived boilerplate, delegating to the implementation file for the important stuff. We then wire it together with a line in `lib/jsdom/living/index.js` that exposes the generated class on all jsdom windows.
22
+
Our build step (`yarn prepare`) then generates a public API file (e.g. `Attr.js`) which takes care of all the Web IDL-derived boilerplate, delegating to the implementation file for the important stuff. We then wire it together with a line in `lib/jsdom/living/index.js` that exposes the generated class on all jsdom windows.
17
23
18
24
## Contribution overview
19
25
@@ -33,61 +39,61 @@ Other specs might pop up from time to time, especially in regard to CSS stuff. I
33
39
34
40
### Running the tests
35
41
36
-
First you'll want to `npm install`. Then, configure your system to run the web platform tests as described in [their README](https://github.com/w3c/web-platform-tests/blob/master/README.md). If you can't get that set up correctly, the test runner will make a best-faith effort to run the tests hosted on http://w3c-test.org/, but this is pretty slow and fragile.
42
+
First you'll want to run `yarn` to install all dependencies. Then, configure your system to run the web platform tests as described in [their README](https://github.com/w3c/web-platform-tests/blob/master/README.md). If you can't get that set up correctly, the test runner will make a best-faith effort to run the tests hosted on http://w3c-test.org/, but this is pretty slow and fragile.
37
43
38
-
**To run all the tests:**`npm test`
44
+
**To run all the tests:**`yarn test`
39
45
40
46
### Web platform feature tests
41
47
42
48
All tests for web platform features (as opposed to features of jsdom itself, such as the `JSDOM()` constructor) should be in [web-platform-tests](https://github.com/w3c/web-platform-tests) format. We have some infrastructure for running these directly against jsdom documents. So ideally, when contributing a bugfix or new feature, you can browse the web-platform-tests repository and find the test covering your work, and then just enable it in [the `to-run.yaml` file](https://github.com/tmpvar/jsdom/blob/master/test/web-platform-tests/to-run.yaml). These tests are HTML files which use a special library called [testharness.js](http://testthewebforward.org/docs/testharness-library.html) to report their results.
43
49
44
50
However, the web-platform-tests project is not fully comprehensive. If you need to write your own test for a web platform feature, place it in our [to-upstream](https://github.com/tmpvar/jsdom/tree/master/test/web-platform-tests/to-upstream) directory. (It's so named because, over time, we hope to upstream these tests back to the web-platform-tests repository, so all browsers can benefit from them.) Note that you may need to create new directory structure, paralleling that of the main [web-platform-tests](https://github.com/w3c/web-platform-tests) repository.
45
51
46
-
**To run all web-platform-tests:**`npm run test-wpt`
52
+
**To run all web-platform-tests:**`yarn test-wpt`
47
53
48
-
**To run the to-upstream web-platform-tests:**`npm run test-tuwpt`
54
+
**To run the to-upstream web-platform-tests:**`yarn test-tuwpt`
49
55
50
-
**To run specific web-platform-tests already enabled via `to-run.yaml`**: `npm run test-wpt -- --fgrep dom/events`
56
+
**To run specific web-platform-tests already enabled via `to-run.yaml`**: `yarn test-wpt -- --fgrep dom/events`
51
57
52
-
**To run specific to-upstream web-platform-tests**: `npm run test-tuwpt -- --fgrep domparsing`
58
+
**To run specific to-upstream web-platform-tests**: `yarn test-tuwpt -- --fgrep domparsing`
53
59
54
-
Also, to update web platform tests to their latest revision from the source repository: `npm run update-wpt`. (This can take a long time.)
60
+
Also, to update web platform tests to their latest revision from the source repository: `yarn update-wpt`. (This can take a long time, like 10 minutes.)
55
61
56
62
### jsdom API tests
57
63
58
64
If you are testing something that can only be accomplished through the jsdom API, and not inside a normal web browser, you'll want to write a different kind of test. Such tests are written using [Mocha](https://mochajs.org/) and [Chai](http://chaijs.com/).
59
65
60
66
To write such a test that, simply add a file in `test/api/`, following the surrounding conventions. Then, add it to the manifest at `test/index.js`.
61
67
62
-
**To run all API tests:**`npm run test-api`
68
+
**To run all API tests:**`yarn test-api`
63
69
64
-
**To run a specific API test:**`npm run test-mocha -- test/api/from-file.js`
70
+
**To run a specific API test:**`yarn test-mocha -- test/api/from-file.js`
65
71
66
72
### Older tests
67
73
68
-
Although ideally you should not need to worry about this, there are some tests that are for legacy reasons not in the right format; they use Mocha, but really should be web platform tests. We're keeping them around for coverage until we can convert them. If you run `npm test`, you will get the full test suite, including such old tests.
74
+
Although ideally you should not need to worry about this, there are some tests that are for legacy reasons not in the right format; they use Mocha, but really should be web platform tests. We're keeping them around for coverage until we can convert them. If you run `yarn test`, you will get the full test suite, including such old tests.
69
75
70
76
### Testing against the browser
71
77
72
78
jsdom has experimental support to run in directly in a browser, in both the main document and in a web worker! So we try run as many tests as possible in browsers too. Currently we only test in Chrome, since it has the same JavaScript features as the Node.js environment we usually develop in. So you'll need Chrome installed on your machine.
73
79
74
80
The mocha test cases are executed in Chrome using [karma](https://karma-runner.github.io/). Currently, web platform tests are not executed in the browser yet.
75
81
76
-
**To run all browser tests:**`npm run test-browser`
82
+
**To run all browser tests:**`yarn test-browser`
77
83
78
-
**To run the karma tests in an iframe:**`npm run test-browser-iframe`
84
+
**To run the karma tests in an iframe:**`yarn test-browser-iframe`
79
85
80
-
**To run the karma tests in a web worker:**`npm run test-browser-worker`
86
+
**To run the karma tests in a web worker:**`yarn test-browser-worker`
81
87
82
88
## Benchmarks
83
89
84
90
This project cares about performance. There are a number of benchmarks that you can run. If you suspect your contribution has an impact on the performance of existing functionality, make sure you run the benchmarks before and after your change so that you can compare.
85
91
86
92
You can also run the benchmarks using the native DOM implementation of Chrome. A comparison with jsdom will automatically be made for you. If your new feature is much slower than the alternative DOM implementation, there might be an unexpected bottleneck somewhere in your change.
87
93
88
-
**To run benchmarks in Node.js:**`npm run benchmark`
94
+
**To run benchmarks in Node.js:**`yarn benchmark`
89
95
90
-
**To run benchmarks in the browser:**`npm run benchmark-browser`, then open `benchmark/browser-runner.html` in Chrome (or Chromium) and use the developer console to execute the `run()` function.
96
+
**To run benchmarks in the browser:**`yarn benchmark-browser`, then open `benchmark/browser-runner.html` in Chrome (or Chromium) and use the developer console to execute the `run()` function.
0 commit comments