Skip to content

Commit

Permalink
updated README and test/README
Browse files Browse the repository at this point in the history
  • Loading branch information
TristanWright committed Jun 20, 2016
1 parent 58458b1 commit a8197f0
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 31 deletions.
29 changes: 7 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
## HPCCloud ##
# HPC Cloud #

[![codecov.io](https://codecov.io/github/Kitware/HPCCloud/coverage.svg?branch=master)](https://codecov.io/github/Kitware/HPCCloud?branch=master)
[![Build Status](https://travis-ci.org/Kitware/HPCCloud.svg?branch=master)](https://travis-ci.org/Kitware/HPCCloud)

### Goal ###

Expand All @@ -7,26 +10,7 @@ environment and resources on which you can run those simulations.

## Installation

```
$ npm install
```

After installing the package you will get one executable **HPCCloud** with
the following set of options.

```
$ HPCCloud
Usage: HPCCloud [options]
Options:
-h, --help output usage information
-V, --version output the version number
>>> FIXME <<<
```
Observe the instructions for [HPCCloud deploy](https://github.com/Kitware/HPCCloud-deploy);

## Development

Expand All @@ -37,8 +21,9 @@ $ npm install
$ npm start
```

## Trouble shooting
## Troubleshooting

(With the vm running from HPCCloud-Deploy)
```sh
$ vagrant ssh
$ sudo -iu hpccloud
Expand Down
93 changes: 84 additions & 9 deletions test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,98 @@ We test two things:

## Running

- Redux - `nam run test:redux`
- Redux - `npm run test:redux`
- Components - `npm run test:components`
- Everything - `nam run test`
- Everything - `npm run test`

## Writing new tests

We're using:

- [Karma](https://karma-runner.github.io/0.13/index.html): with [webpack](https://webpack.github.io/) and [istanbul-instrumenter](https://github.com/deepsweet/istanbul-instrumenter-loader)
- [Jasmine](http://jasmine.github.io/2.4/introduction.html)
- [PhantomJS](http://phantomjs.org/)
- [expect](https://github.com/mjackson/expect)
- [redux-actions-assertions](https://github.com/dmitry-zaets/redux-actions-assertions) (Redux tests only, but can be used for tests which have redux elements.)
- [React Test Utils](https://facebook.github.io/react/docs/test-utils.html) (For tests involving React components)
- [Karma](https://karma-runner.github.io/0.13/index.html): with [karma-webpack](https://github.com/webpack/karma-webpack) and [istanbul-instrumenter](https://github.com/deepsweet/istanbul-instrumenter-loader) - test runner, transpiles tests with a webpack extension.
- [Jasmine](http://jasmine.github.io/2.4/introduction.html) - test framework
- [expect](https://github.com/mjackson/expect) - assertion library
- [PhantomJS](http://phantomjs.org/) - headless webkit environment for testing in
- [babel-polyfill](https://github.com/babel/babel/tree/master/packages/babel-polyfill) - PhantomJS has no Promise object, so we supplement it with this.
- [redux-actions-assertions](https://github.com/dmitry-zaets/redux-actions-assertions) - Redux tests only, but can be used for component tests which use redux.
- [React Test Utils](https://facebook.github.io/react/docs/test-utils.html) - For tests involving React components

### Redux
Check if there is already a file for the actions or reducers you're testing in `/test/redux`, add a new file if there isn't one already. Action testing can be split up by "simple actions" and "async actions". Simple actions just return an object with `type` and optionally some data payload. Async actions call some backend component.

#### Template

```js
// import necessary libraries and tools.
import { registerMiddlewares } from 'redux-actions-assertions';
import { registerAssertions } from 'redux-actions-assertions/expect';
import thunk from 'redux-thunk'; // useful for testing async actions
import expect from 'expect';
import complete from '../helpers/complete'; // a done/fail helper for redux-action-assertions

// what we're testing
import myActions from '../../src/redux/actions/myActions';
import myReducer from '../../src/redux/reducers/myReducer';
import client from '../../src/network'; // for setting spies on

/* global describe it afterEach */

registerMiddlewares([thunk]);
registerAssertions();

function setSpy(target, method, data) {
expect.spyOn(target, method)
.andReturn(Promise.resolve({ data }));
}

describe('some action test', () => {
describe('simple actions', () => {
it('should increment a value', (done) => {
const expectedAction = { type: myActions.INCREMENT };
expect(myActions.increment)
.toDispatchActions(expectedAction, complete(done));

const initialState = { value: 0 }; // this can also be exported from the reducers, be sure to clone it if you use it.
const expectedState = { value: 1 };
expect(myReducer(initialState, expectedAction))
.toEqual(expectedState); // does a deep equal, if you're dealing with big payloads it can be hard to read error output.
});
});

describe('asyn actions', () => {
afterEach(() => {
expect.restoreSpies();
});

it('should increment a value on the server', (done) => {
const expectedAction = { type: myActions.UPDATE_VALUE, value: 2 };
setSpy(client, 'serverIncrement', { value: 2 })
expect(myActions.serverIncrement()) // this action would call `client.serverIncrement` which we're spying on
.toDispatchActions(expectedAction, complete(done));
});
});
});
```

### Components
Writing tests for React components can be a bit finicky. For components with some state or props reliance they may not fully render. Luckily you can manipulate the React components just like you would with plain javascript objects.
Writing tests for React components can be a bit finicky. For components with reliance on state or props they may not fully render. Luckily you can manipulate the React components just like you would with plain javascript objects.

#### Template

```js
// import necessary libraries and tools.
import expect from 'expect';
import React from 'react';
import TestUtils from 'react/lib/ReactTestUtils';
import MyComponent from '../../src/panels/sampleComponent';

/* global describe it afterEach */

describe('some component test', () => {
it('should render increment buttons', (done) => {
const el = TestUtils.renderIntoDocument(<MyComponent buttons={[{ action: 'increment', name: 'Increment Value' }]} />);
const buttons = TestUtils.findAllInRenderedTree(el, (component) => component.tagName === 'BUTTON');
expect(buttons.length).toEqual(1);
});
});
```

0 comments on commit a8197f0

Please sign in to comment.