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_GUIDE.md
+14-33
Original file line number
Diff line number
Diff line change
@@ -19,23 +19,21 @@ npm run test:clean
19
19
20
20
The following repo has 4 main directories:
21
21
22
-
-`scikitjs-browser`: Contains build/test commands for the browser version of scikitjs
23
-
-`scikitjs-node`: Contains build/test commands for the node version of scikitjs
22
+
-`src`: Contains the majority of the code for implementing scikit-learn Estimators, and helper functions
24
23
-`docs`: Contains a docusaurus site which builds the `scikitjs.org` site. Has blogs/tutorials/apis documentation
25
-
-`shared`: Contains all the code that is shared between browser and node versions of this library.
26
24
27
-
For anyone creating Estimators or writing scikit-learn functions, you'll likely be spending your time in the `shared/lib` directory. It contains a directory-like structure that matches the scikit-learn directory structure. So there is a `cluster` directory, and a `model_selection` directory, etc.
25
+
For anyone creating Estimators or writing scikit-learn functions, you'll likely be spending your time in the `src` directory. It contains a directory-like structure that matches the scikit-learn directory structure. So there is a `cluster` directory, and a `model_selection` directory, etc.
28
26
29
-
The following files are available in the `shared/lib` directory:
27
+
The following files are available in the `src` directory:
30
28
31
29
-`index`: Entry file which exports all features.
32
30
-`utils`: A collection of reusable utility functions.
33
31
-`types`: A file for declaring Typescript types.
34
32
35
33
Some important scripts in the package.json file are:
36
34
37
-
-`test:clean` : Build both browser and node versions, and runs all tests against them
38
-
-`build` : Builds both the browser and node versions of this library
35
+
-`test:clean` : Runs tests against node.js version of src code
36
+
-`build` : Builds all bundles (esm, cjs, script src)
39
37
-`build:docs`: Builds a local version of the site `scikitjs.org`
40
38
41
39
## Code Style
@@ -96,9 +94,9 @@ Type names are typically nouns or noun phrases. For example, Request, ImmutableL
96
94
97
95
#### Method names
98
96
99
-
Method names are written in lowerCamelCase e.g `addNum`. Names for private methods must start with a dollar sign e.g `$startAddition`, and should be declared as private.
97
+
Method names are written in lowerCamelCase e.g `addNum`.
100
98
101
-
Method names are typically verbs or verb phrases. For example, `sendMessage` or `$stopProcess`. Getter and setter methods for properties are never required, but if they are used they should be named `getFoo` (or optionally `isFoo` or `hasFoo` for booleans), or `setFoo(value)` for setters.
99
+
Method names are typically verbs or verb phrases. For example, `sendMessage` or `stopProcess`. Getter and setter methods for properties are never required, but if they are used they should be named `getFoo` (or optionally `isFoo` or `hasFoo` for booleans), or `setFoo(value)` for setters.
102
100
103
101
#### Constant names
104
102
@@ -134,9 +132,9 @@ JSDOCs attached to the class or functions are automatically converted into the A
134
132
135
133
## **Writing tests**
136
134
137
-
We strongly encourage contributors to write tests for their code. Like many packages, [danfojs](https://danfo.jsdata.org/) uses [mocha](https://mochajs.org/).
135
+
We strongly encourage contributors to write tests for their code. Like many packages, [scikitjs](https://scikitjs.org) uses [jest](https://jestjs.io/).
138
136
139
-
All tests should go into the file suffixed by `.test.ts` and place in the corresponding module. The test files contain some current examples of tests (e.g. `kmeans.test.ts`), and we suggest looking to these for inspiration.
137
+
All tests should go into the file suffixed by `.test.ts` and be placed next to the corresponding src code. The test files contain some current examples of tests (e.g. `kmeans.test.ts`), and we suggest looking to these for inspiration.
140
138
141
139
Below is the general framework to write a test for each module.
describe('Name of the class|module', function () {
148
146
it('name of the methods| expected result', function () {
149
147
//write your test code here
150
-
//use assert.{property} to test your code
148
+
//use expect(thing).toEqual to test your code
151
149
})
152
150
})
153
151
```
@@ -163,9 +161,8 @@ describe("Name of the class|module", function(){
163
161
describe("method name 1", function(){
164
162
165
163
it("expected result",function(){
166
-
167
164
//write your test code here
168
-
//use assert.{proprty} to test your code
165
+
//use expect(thing).toEqual to test your code
169
166
})
170
167
})
171
168
@@ -174,7 +171,7 @@ describe("Name of the class|module", function(){
174
171
it("expected result",function(){
175
172
176
173
//write your test code here
177
-
//use assert.{proprty} to test your code
174
+
//use expect(thing).toEqual to test your code
178
175
})
179
176
})
180
177
.......
@@ -183,22 +180,6 @@ describe("Name of the class|module", function(){
183
180
184
181
### **Running the test case**
185
182
186
-
To run the test for the module/file you created/edited,
187
-
188
-
**1\)** Change `describe` to `describe.only` at the top of the test file
189
-
190
-
**2\)** If you are in the shared directory, you can run the test case against the node library by typing
191
-
192
-
```bash
193
-
npm run test:node
194
-
```
195
-
196
-
You can also test your code against the browser version by running
197
-
198
-
```bash
199
-
npm run test:browser
200
-
```
201
-
202
-
Note that running tests against the browser is usually a bit slower because we build the browser bundle. I usually test against node for quick iterations, and then at the end test against the browser.
183
+
To run the test for the module/file you created/edited, just run jest over that single file
203
184
204
-
Learn more about mocha [here](https://mochajs.org/)
185
+
**1\)** Simply run `npx jest ./path/to/file.test.ts`
0 commit comments