diff --git a/README.md b/README.md index a0e6abd3..6422249d 100644 --- a/README.md +++ b/README.md @@ -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 ### @@ -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 @@ -37,8 +21,9 @@ $ npm install $ npm start ``` -## Trouble shooting +## Troubleshooting +(With the vm running from HPCCloud-Deploy) ```sh $ vagrant ssh $ sudo -iu hpccloud diff --git a/test/README.md b/test/README.md index 7ec03736..4b1cfce8 100644 --- a/test/README.md +++ b/test/README.md @@ -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. \ No newline at end of file +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(); + const buttons = TestUtils.findAllInRenderedTree(el, (component) => component.tagName === 'BUTTON'); + expect(buttons.length).toEqual(1); + }); +}); +``` \ No newline at end of file