diff --git a/.zuul.yaml b/.zuul.yaml index 85368a8..f0c0bad 100644 --- a/.zuul.yaml +++ b/.zuul.yaml @@ -1,5 +1,18 @@ + - job: - name: ara-build-dashboard + name: ara-web-unit-tests + parent: nodejs-npm + description: Run unit tests + files: + - src/.* + - .zuul.yaml + - zuul-playbooks/.* + vars: + node_version: 8 + run: zuul-playbooks/test.yaml + +- job: + name: ara-web-build-dashboard # https://zuul.openstack.org/job/build-javascript-content parent: build-javascript-content description: | @@ -20,10 +33,12 @@ pre-run: zuul-playbooks/pre.yaml run: zuul-playbooks/build-dashboard.yaml + - project: check: jobs: - - ara-build-dashboard + - ara-web-unit-tests + - ara-web-build-dashboard gate: jobs: - - ara-build-dashboard + - ara-web-unit-tests diff --git a/package.json b/package.json index 1605caa..ffc341c 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,8 @@ "scripts": { "start": "react-scripts start", "build": "react-scripts build", - "test": "react-scripts test --env=jsdom", + "test": "CI=true react-scripts test --env=jsdom", + "test:watch": "react-scripts test --env=jsdom", "eject": "react-scripts eject" }, "devDependencies": { diff --git a/src/App.test.js b/src/App.test.js index a754b20..9519bf2 100644 --- a/src/App.test.js +++ b/src/App.test.js @@ -1,9 +1,17 @@ -import React from 'react'; -import ReactDOM from 'react-dom'; -import App from './App'; +import React from "react"; +import ReactDOM from "react-dom"; +import axios from "axios"; +import axiosMockAdapter from "axios-mock-adapter"; -it('renders without crashing', () => { - const div = document.createElement('div'); +import App from "./App"; + +const axiosMock = new axiosMockAdapter(axios); + +it("renders without crashing", () => { + axiosMock.onGet("config.json").reply(200, { + apiURL: "http://localhost:8000" + }); + const div = document.createElement("div"); ReactDOM.render(, div); ReactDOM.unmountComponentAtNode(div); }); diff --git a/src/config/configActions.test.js b/src/config/configActions.test.js index 51c11d2..1e4937b 100644 --- a/src/config/configActions.test.js +++ b/src/config/configActions.test.js @@ -1,13 +1,11 @@ import * as actions from "./configActions"; -import * as types from "./playbooksActionsTypes"; +import * as types from "./configActionsTypes"; it("setConfig", () => { const config = { apiURL: "http://example.org" }; - const expectedActions = [ - { - type: types.SET_CONFIG, - config - } - ]; + const expectedActions = { + type: types.SET_CONFIG, + config + }; expect(actions.setConfig(config)).toEqual(expectedActions); }); diff --git a/zuul-playbooks/test.yaml b/zuul-playbooks/test.yaml new file mode 100644 index 0000000..eca4cb1 --- /dev/null +++ b/zuul-playbooks/test.yaml @@ -0,0 +1,7 @@ +- name: Test ARA web + hosts: all + roles: + - role: npm + npm_command: build + - role: npm + npm_command: test