Skip to content

Commit

Permalink
Merge branch 'master' of github.com:processing/p5.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Lauren McCarthy committed May 17, 2019
2 parents 9977673 + 746471b commit ea64e6c
Show file tree
Hide file tree
Showing 33 changed files with 2,214 additions and 93 deletions.
21 changes: 20 additions & 1 deletion .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -1443,6 +1443,16 @@
"doc"
]
},
{
"login": "Luke_",
"name": "Luc de wit",
"avatar_url": "https://media.discordapp.net/attachments/499488127245615135/499488260435869696/normal_luke.png",
"profile": "https://github.com/justlucdewit",
"contributions": [
"code",
"bug"
]
},
{
"login": "mcuz",
"name": "Mark Nikora",
Expand All @@ -1451,6 +1461,15 @@
"contributions": [
"code"
]
}
},
{
"login": "Nekzuris",
"name": "Louis Demange",
"avatar_url": "https://avatars3.githubusercontent.com/u/48560751?s=400&u=652ea1a1720b1986c3ea5b96028bdcb5f4f18f96&v=4",
"profile": "https://github.com/Nekzuris",
"contributions": [
"bug"
]
}
]
}
10 changes: 8 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,8 @@ module.exports = grunt => {
test: {
src: ['test/node/**/*.js'],
options: {
reporter: reporter
reporter: reporter,
ui: 'tdd'
}
}
},
Expand Down Expand Up @@ -471,7 +472,12 @@ module.exports = grunt => {
'mochaChrome',
'mochaTest'
]);
grunt.registerTask('test:nobuild', ['eslint:test', 'connect', 'mochaChrome']);
grunt.registerTask('test:nobuild', [
'eslint:test',
'connect:server',
'mochaChrome',
'mochaTest'
]);
grunt.registerTask('yui', ['yuidoc:prod', 'clean:reference', 'minjson']);
grunt.registerTask('yui:test', [
'yuidoc:prod',
Expand Down
67 changes: 67 additions & 0 deletions developer_docs/unit_testing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Unit Testing

We use unit testing to ensure that individual components of the codebase work as we expect them to.

## References

Here's a [good, quick intro to unit testing](https://codeburst.io/javascript-unit-testing-using-mocha-and-chai-1d97d9f18e71) with a similar tech stack, and here's a [more in depth walkthrough](https://blog.logrocket.com/a-quick-and-complete-guide-to-mocha-testing-d0e0ea09f09d)

## Running All the Unit Tests

In the repo root, use the following command in your terminal

```shellsession
npm test
```

### Running One Suite

To run a single test or group of tests, append `.only` on a `suite` or `test` in your `.js` file and run the tests using the above command.

**Be careful you don't commit `.only` though!** (We always want Travis CI to run _all_ the unit tests.)

#### An Example

To only run the "p5.ColorConversion" suite of tests, you would change the first line of `test/unit/color/color_conversion.js` to read:

```js
suite.only('color/p5.ColorConversion', function() {
```
Now when you use `npm test`, only tests within that `function()` body will be run.

## Infrastucture

### Frameworks

We use [mocha](https://mochajs.org) for structuring and running our unit tests

We use [chai's `assert` (and `expect`)](https://www.chaijs.com/api/assert/) to write individual statements about how code should behave.

### Environments

We have a collection of tests under the `test/unit` folder that run in the browser and a collection of tests under `test/node` that run in Node.js.

The browser tests run in ["headless" Chrome](https://developers.google.com/web/updates/2017/06/headless-karma-mocha-chai). This is why you don't see a browser window pop up when you run the tests.

### Setup and Helpers

These are currently only available to the browser tests (where most of our tests run):

- `test/js/mocha_setup.js` configures a few options for mocha
- `test/js/chai_helpers.js` sets up chai and adds a couple helpful functions to `chai.assert`
- `test/js/p5_helpers.js` adds a couple helpers for testing p5 sketches

The setup for Node.js tests is all done in `test/mocha.opts`

### Continuous Integration Testing

When you open a pull request in the p5.js repo, it will automatically run the tests [on Travis CI](https://travis-ci.org/processing/p5.js/pull_requests) too. Travis CI helps us double check that the tests pass for each pull request, with no extra work from individual contributors.

## Adding Unit Tests

If you want to add more unit tests, look and see if there's already a test file for the component you want to add tests for. Generally, tests for a given file in `src/` are at the same path under `test/unit`. (For example the tests for `src/color/p5.Color.js` are in `test/unit/color/p5.Color.js`.)

If you can't find one, that's probably because there aren't any tests for that file (yet 😉), so create a new file according to the conventions above. If the module you're testing requires a browser to work, you'll want to put it in `test/unit`, but if it doesn't, you might want to add it under `test/node`. **When in doubt, default to adding a browser test in `test/unit`! (It's pretty easy to move a later if we need to.)**

If you have to add a test file for a module to `test/unit`, then you'll also need to the module under test to the `spec` array in `test/unit/spec.js`. This will make sure the necessary modules are loaded for your test to run.
22 changes: 22 additions & 0 deletions docs/yuidoc-p5-theme/assets/shader-gradient.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Code adopted from "Creating a Gradient Color in Fragment Shader"
// by Bahadır on stackoverflow.com
// https://stackoverflow.com/questions/47376499/creating-a-gradient-color-in-fragment-shader


precision highp float; varying vec2 vPos;
uniform vec2 offset;
uniform vec3 colorCenter;
uniform vec3 colorBackground;

void main() {

vec2 st = vPos.xy + offset.xy;

// color1 = vec3(1.0,0.55,0);
// color2 = vec3(0.226,0.000,0.615);

float mixValue = distance(st,vec2(0,1));
vec3 color = mix(colorCenter,colorBackground,mixValue);

gl_FragColor = vec4(color,mixValue);
}
Loading

0 comments on commit ea64e6c

Please sign in to comment.