Skip to content

Commit 10edf61

Browse files
authored
Merge pull request #117 from cignium/improve-stability
Improve stability
2 parents d093c0a + f2d6d22 commit 10edf61

12 files changed

Lines changed: 164 additions & 25 deletions

.jestrc

Lines changed: 0 additions & 9 deletions
This file was deleted.

.travis.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,21 @@ cache:
66
notifications:
77
email: false
88
node_js:
9-
- 5.0.0
9+
- 6.10.3
10+
install:
11+
- wget https://www.browserstack.com/browserstack-local/BrowserStackLocal-linux-x64.zip
12+
- unzip BrowserStackLocal-linux-x64.zip
13+
- ./BrowserStackLocal -v -onlyAutomate -forcelocal $BROWSERSTACK_ACCESS_KEY &
14+
- sleep 3
15+
- npm install
1016
before_script:
11-
- npm prune
17+
- npm prune
18+
- npm run start-ui-test-server &
1219
script:
1320
- npm run lint
1421
- npm run test
1522
- npm run build
23+
- npm run test-ui
1624
after_success:
1725
- npm run semantic-release
1826
branches:

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Hypermedia renderer for Cignium's hypermedia api.
44

5-
[![Build Status](https://travis-ci.org/cignium/hypermedia-client.svg)](https://travis-ci.org/cignium/hypermedia-client)
5+
[![Build Status](https://travis-ci.org/cignium/hypermedia-client.svg)](https://travis-ci.org/cignium/hypermedia-client) [![npm](https://img.shields.io/npm/v/cignium-hypermedia-client.svg)](https://www.npmjs.com/package/cignium-hypermedia-client)
66

77
## Install
88

@@ -21,14 +21,15 @@ npm install cignium-hypermedia-client --save
2121
Add the following script tag:
2222

2323
```html
24-
<script src="//unpkg.com/cignium-hypermedia-client/dist/client.min.js"></script>
24+
<script src="//unpkg.com/cignium-hypermedia-client/dist@1/client.min.js"></script>
2525
```
2626

2727
For default styling, include this tag:
2828

2929
```html
30-
<link rel="stylesheet" type="text/css" href="//unpkg.com/cignium-hypermedia-client/dist/default.css">
30+
<link rel="stylesheet" type="text/css" href="//unpkg.com/cignium-hypermedia-client@1/dist/default.css">
3131
```
32+
*NOTE: the @1 in these import statements make sure that you are importing the latest version of the client that is still on major version 1. Meaning every version below 2.0.0. Importing the client like this ensures that your application will not automatically upgrade to version 2.0.0 which will contain breaking changes. The safest way to import the client will always be to specify the entire version e.g. @1.31.3 but that also means that you will not even get small patches automatically.*
3233

3334
## Get Started
3435

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const assert = require('assert')
2+
3+
describe('All type of controls form', () => {
4+
it('can load the form and find the header', () => {
5+
browser.url('index.html')
6+
const selector = '.ct-document-header-text'
7+
browser.waitForExist(selector, 30000)
8+
9+
assert.equal(browser.getText(selector), 'All type of controls form')
10+
})
11+
})

jest.config.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = {
2+
transform: { '.*': '<rootDir>/test-preprocessor' },
3+
'unmockedModulePathPatterns': [
4+
'<rootDir>/node_modules/react',
5+
'<rootDir>/node_modules/react-dom',
6+
'<rootDir>/node_modules/react-addons-test-utils',
7+
],
8+
'automock':true,
9+
'testPathIgnorePatterns': [
10+
'<rootDir>/__tests__/ui',
11+
],
12+
}

package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"moment": "^2.18.0",
1414
"react": "^15.4.2",
1515
"react-dom": "^15.4.2",
16+
"react-input-autosize": "1.1.0",
1617
"react-select": "^1.0.0-rc.3",
1718
"react-text-mask": "^3.0.0",
1819
"react-tooltip": "3.2.10",
@@ -34,6 +35,7 @@
3435
"babel-preset-react": "^6.3.13",
3536
"babel-preset-stage-0": "^6.3.13",
3637
"babel-runtime": "^6.9.0",
38+
"browserstack-local": "^1.3.0",
3739
"css-loader": "^0.23.0",
3840
"eslint": "^1.10.3",
3941
"eslint-loader": "^1.1.1",
@@ -43,7 +45,7 @@
4345
"extract-text-webpack-plugin": "^1.0.1",
4446
"file-loader": "^0.10.1",
4547
"imports-loader": "^0.6.5",
46-
"jest-cli": "*",
48+
"jest-cli": "^20.0.0",
4749
"less": "^2.7.2",
4850
"less-loader": "^4.0.0",
4951
"npm-run-all": "^1.5.3",
@@ -54,16 +56,20 @@
5456
"semantic-release": "^4.3.5",
5557
"style-loader": "^0.13.2",
5658
"url-loader": "^0.5.8",
59+
"wdio-mocha-framework": "^0.5.10",
60+
"webdriverio": "^4.8.0",
5761
"webpack": "^1.12.9",
5862
"webpack-dev-middleware": "^1.4.0",
5963
"webpack-hot-middleware": "^2.6.0"
6064
},
6165
"scripts": {
6266
"build": "NODE_ENV=production babel-node node_modules/webpack/bin/webpack --config webpack.production.config.js",
63-
"test": "jest --config .jestrc",
67+
"test": "jest",
68+
"test-ui": "wdio wdio.conf.js",
6469
"lint": "eslint .",
6570
"start": "npm-run-all --parallel start-server start-test",
6671
"start-server": "babel-node server.js",
72+
"start-ui-test-server": "node ui-test-server.js",
6773
"start-test": "jest --config .jestrc --watch",
6874
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
6975
}

src/client.js

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ export default class Client {
1818
}
1919

2020
init(element) {
21-
if (typeof element === 'string') {
22-
element = document.getElementById(element)
23-
}
21+
element = findAndValidateElement(element)
2422

2523
render(<App api={this.api} config={this.config} state={this.state} />, element)
2624

@@ -36,24 +34,24 @@ export default class Client {
3634
get(propertyName) {
3735
let data = this.state.get().resources
3836
data = data[data.current]
39-
37+
4038
if (propertyName) {
4139
return this.api.allProperties.find(i => i.name === propertyName).value
4240
}
43-
41+
4442
const output = {}
4543
this.api.allProperties.forEach(i => {
4644
output[i.name] = i.value
4745
})
4846
return output
4947
}
50-
48+
5149
set(propertyName, value) {
5250
let data = this.state.get().resources
5351
data = data[data.current]
54-
52+
5553
const property = this.api.allProperties.find(i => i.name === propertyName)
56-
54+
5755
if (property.value !== value) {
5856
if (!property.links.update) {
5957
property.set('value', value)
@@ -62,3 +60,23 @@ export default class Client {
6260
}
6361
}
6462
}
63+
64+
function findAndValidateElement(element) {
65+
if (!element) {
66+
throw new Error(`Mandatory parameter 'element' was ${element}`)
67+
}
68+
69+
if (typeof element === 'string') {
70+
const elementId = element
71+
element = document.getElementById(element)
72+
if (!element) {
73+
throw new Error(`Element with id '${elementId}' was not found.`)
74+
}
75+
}
76+
77+
if (element.nodeType !== 1) {
78+
throw new Error(`Parameter 'element' is not a valid DOM element.`)
79+
}
80+
81+
return element
82+
}

ui-test-server.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const express = require('express')
2+
3+
const app = express()
4+
app.use(express.static('ui-tests'))
5+
app.use(express.static('dist'))
6+
7+
app.listen(3004, '0.0.0.0', err => {
8+
if (err) {
9+
console.log(err)
10+
return
11+
}
12+
13+
console.log('Listening at http://localhost:3004')
14+
})

ui-tests/index.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Hypermedia Client Testing</title>
6+
<link rel="stylesheet" type="text/css" href="default.css" />
7+
<script src="client.min.js"></script>
8+
</head>
9+
<body>
10+
<div id="demo-app" data-endpoint="https://cignium-lm-staging.azurewebsites.net/run/staging/regression/prod/forms-test"></div>
11+
</body>
12+
</html>

wdio.conf.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
const browserstack = require('browserstack-local')
2+
3+
exports.config = {
4+
user: process.env.BROWSERSTACK_USERNAME || 'BROWSERSTACK_USERNAME',
5+
key: process.env.BROWSERSTACK_ACCESS_KEY || 'BROWSERSTACK_ACCESS_KEY',
6+
7+
updateJob: false,
8+
specs: [
9+
'./__tests__/ui/*-tests.js',
10+
],
11+
exclude: [],
12+
13+
capabilities: [{
14+
browser: 'chrome',
15+
name: 'single_test',
16+
build: process.env.CI ?
17+
'hypermedia-client #' + process.env.TRAVIS_BUILD_NUMBER + '.' + process.env.TRAVIS_JOB_NUMBER :
18+
'hypermedia-client-local',
19+
'browserstack.local': true,
20+
}],
21+
22+
logLevel: 'verbose',
23+
coloredLogs: true,
24+
screenshotPath: './errorShots/',
25+
baseUrl: 'http://localhost:3004',
26+
waitforTimeout: 30000,
27+
connectionRetryTimeout: 90000,
28+
connectionRetryCount: 3,
29+
30+
framework: 'mocha',
31+
mochaOpts: {
32+
ui: 'bdd',
33+
timeout: 30000,
34+
},
35+
36+
// Code to start browserstack local before start of test
37+
onPrepare: (config, capabilities) => {
38+
if (process.env.CI) {
39+
console.log('On CI. Skipping local connection.')
40+
return
41+
}
42+
console.log('Connecting local')
43+
return new Promise((resolve, reject) => {
44+
exports.bs_local = new browserstack.Local()
45+
exports.bs_local.start({'key': exports.config.key, 'force': true }, error => {
46+
if (error) {
47+
console.log(error)
48+
return reject(error)
49+
}
50+
console.log('Connected. Now testing...')
51+
52+
resolve()
53+
})
54+
})
55+
},
56+
57+
// Code to stop browserstack local after end of test
58+
onComplete: (capabilties, specs) => {
59+
if (process.env.CI) {
60+
console.log('On CI. No local connection to close.')
61+
return
62+
}
63+
console.log('Closing local connection')
64+
exports.bs_local.stop(() => {})
65+
},
66+
}

0 commit comments

Comments
 (0)