@selkirk-systems/fetch 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.jshintrc +125 -0
- package/.npmignore +10 -0
- package/LICENSE +21 -0
- package/README.md +61 -0
- package/dist/exampleTests.js +27 -0
- package/dist/index.js +74 -0
- package/gulpfile.js +11 -0
- package/index.js +1 -0
- package/package.json +72 -0
- package/scripts/mocha_runner.js +21 -0
- package/src/__tests__/index.js +61 -0
- package/src/exampleTests.js +26 -0
- package/src/index.js +76 -0
package/.jshintrc
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
{
|
|
2
|
+
// --------------------------------------------------------------------
|
|
3
|
+
// JSHint Nodeclipse Configuration v0.18
|
|
4
|
+
// Strict Edition with some relaxations and switch to Node.js, no `use strict`
|
|
5
|
+
// by Ory Band, Michael Haschke, Paul Verest
|
|
6
|
+
// https://github.com/Nodeclipse/nodeclipse-1/blob/master/org.nodeclipse.ui/templates/common-templates/.jshintrc
|
|
7
|
+
// JSHint Documentation is at http://www.jshint.com/docs/options/
|
|
8
|
+
// JSHint Integration v0.9.10 comes with JSHInt 2.5.6 , see https://github.com/eclipsesource/jshint-eclipse
|
|
9
|
+
// --------------------------------------------------------------------
|
|
10
|
+
// from https://gist.github.com/haschek/2595796
|
|
11
|
+
//
|
|
12
|
+
// This is a options template for [JSHint][1], using [JSHint example][2]
|
|
13
|
+
// and [Ory Band's example][3] as basis and setting config values to
|
|
14
|
+
// be most strict:
|
|
15
|
+
//
|
|
16
|
+
// * set all enforcing options to true
|
|
17
|
+
// * set all relaxing options to false
|
|
18
|
+
// * set all environment options to false, except the node value
|
|
19
|
+
// * set all JSLint legacy options to false
|
|
20
|
+
//
|
|
21
|
+
// [1]: http://www.jshint.com/
|
|
22
|
+
// [2]: https://github.com/jshint/node-jshint/blob/master/example/config.json //404
|
|
23
|
+
// [3]: https://github.com/oryband/dotfiles/blob/master/jshintrc
|
|
24
|
+
// [4]: http://www.jshint.com/options/
|
|
25
|
+
//
|
|
26
|
+
// @author http://michael.haschke.biz/
|
|
27
|
+
// @license http://unlicense.org/
|
|
28
|
+
|
|
29
|
+
// == Enforcing Options ===============================================
|
|
30
|
+
//
|
|
31
|
+
// These options tell JSHint to be more strict towards your code. Use
|
|
32
|
+
// them if you want to allow only a safe subset of JavaScript, very
|
|
33
|
+
// useful when your codebase is shared with a big number of developers
|
|
34
|
+
// with different skill levels. Was all true.
|
|
35
|
+
|
|
36
|
+
"bitwise" : true, // Prohibit bitwise operators (&, |, ^, etc.).
|
|
37
|
+
"curly" : true, // Require {} for every new block or scope.
|
|
38
|
+
"eqeqeq" : true, // Require triple equals i.e. `===`.
|
|
39
|
+
"forin" : true, // Tolerate `for in` loops without `hasOwnPrototype`.
|
|
40
|
+
"immed" : true, // Require immediate invocations to be wrapped in parens e.g. `( function(){}() );`
|
|
41
|
+
"latedef" : true, // Prohibit variable use before definition.
|
|
42
|
+
"newcap" : true, // Require capitalization of all constructor functions e.g. `new F()`.
|
|
43
|
+
"noarg" : true, // Prohibit use of `arguments.caller` and `arguments.callee`.
|
|
44
|
+
"noempty" : true, // Prohibit use of empty blocks.
|
|
45
|
+
"nonew" : true, // Prohibit use of constructors for side-effects.
|
|
46
|
+
"plusplus" : false, // Prohibit use of `++` & `--`. //coding style related only
|
|
47
|
+
"regexp" : true, // Prohibit `.` and `[^...]` in regular expressions.
|
|
48
|
+
"undef" : true, // Require all non-global variables be declared before they are used.
|
|
49
|
+
"strict" : false, // Require `use strict` pragma in every file.
|
|
50
|
+
"trailing" : true, // Prohibit trailing whitespaces.
|
|
51
|
+
|
|
52
|
+
// == Relaxing Options ================================================
|
|
53
|
+
//
|
|
54
|
+
// These options allow you to suppress certain types of warnings. Use
|
|
55
|
+
// them only if you are absolutely positive that you know what you are
|
|
56
|
+
// doing. Was all false.
|
|
57
|
+
"asi" : false, // Tolerate Automatic Semicolon Insertion (no semicolons).
|
|
58
|
+
"boss" : false, // Tolerate assignments inside if, for & while. Usually conditions & loops are for comparison, not assignments.
|
|
59
|
+
"debug" : false, // Allow debugger statements e.g. browser breakpoints.
|
|
60
|
+
"eqnull" : false, // Tolerate use of `== null`.
|
|
61
|
+
//"es5" : true, // Allow EcmaScript 5 syntax. // es5 is default https://github.com/jshint/jshint/issues/1411
|
|
62
|
+
"esnext" : false, // Allow ES.next (ECMAScript 6) specific features such as `const` and `let`.
|
|
63
|
+
"evil" : false, // Tolerate use of `eval`.
|
|
64
|
+
"expr" : false, // Tolerate `ExpressionStatement` as Programs.
|
|
65
|
+
"funcscope" : false, // Tolerate declarations of variables inside of control structures while accessing them later from the outside.
|
|
66
|
+
"globalstrict" : false, // Allow global "use strict" (also enables 'strict').
|
|
67
|
+
"iterator" : false, // Allow usage of __iterator__ property.
|
|
68
|
+
"lastsemic" : false, // Tolerat missing semicolons when the it is omitted for the last statement in a one-line block.
|
|
69
|
+
"laxbreak" : false, // Tolerate unsafe line breaks e.g. `return [\n] x` without semicolons.
|
|
70
|
+
"laxcomma" : true, // Suppress warnings about comma-first coding style.
|
|
71
|
+
"loopfunc" : false, // Allow functions to be defined within loops.
|
|
72
|
+
"maxerr" : 100, // This options allows you to set the maximum amount of warnings JSHint will produce before giving up. Default is 50.
|
|
73
|
+
"multistr" : false, // Tolerate multi-line strings.
|
|
74
|
+
"onecase" : false, // Tolerate switches with just one case.
|
|
75
|
+
"proto" : false, // Tolerate __proto__ property. This property is deprecated.
|
|
76
|
+
"regexdash" : false, // Tolerate unescaped last dash i.e. `[-...]`.
|
|
77
|
+
"scripturl" : false, // Tolerate script-targeted URLs.
|
|
78
|
+
"smarttabs" : false, // Tolerate mixed tabs and spaces when the latter are used for alignmnent only.
|
|
79
|
+
"shadow" : false, // Allows re-define variables later in code e.g. `var x=1; x=2;`.
|
|
80
|
+
"sub" : false, // Tolerate all forms of subscript notation besides dot notation e.g. `dict['key']` instead of `dict.key`.
|
|
81
|
+
"supernew" : false, // Tolerate `new function () { ... };` and `new Object;`.
|
|
82
|
+
"validthis" : false, // Tolerate strict violations when the code is running in strict mode and you use this in a non-constructor function.
|
|
83
|
+
|
|
84
|
+
// == Environments ====================================================
|
|
85
|
+
//
|
|
86
|
+
// These options pre-define global variables that are exposed by
|
|
87
|
+
// popular JavaScript libraries and runtime environments—such as
|
|
88
|
+
// browser or node.js. TODO JSHint Documentation has more, but it is not clear since what JSHint version they appeared
|
|
89
|
+
"browser" : false, // Standard browser globals e.g. `window`, `document`.
|
|
90
|
+
"couch" : false, // Enable globals exposed by CouchDB.
|
|
91
|
+
"devel" : false, // Allow development statements e.g. `console.log();`.
|
|
92
|
+
"dojo" : false, // Enable globals exposed by Dojo Toolkit.
|
|
93
|
+
"jquery" : false, // Enable globals exposed by jQuery JavaScript library.
|
|
94
|
+
"mootools" : false, // Enable globals exposed by MooTools JavaScript framework.
|
|
95
|
+
"node" : true, // Enable globals available when code is running inside of the NodeJS runtime environment.
|
|
96
|
+
"nonstandard" : false, // Define non-standard but widely adopted globals such as escape and unescape.
|
|
97
|
+
"phantom" : false, //?since version? This option defines globals available when your core is running inside of the PhantomJS runtime environment.
|
|
98
|
+
"prototypejs" : false, // Enable globals exposed by Prototype JavaScript framework.
|
|
99
|
+
"rhino" : false, // Enable globals available when your code is running inside of the Rhino runtime environment.
|
|
100
|
+
"worker" : false, //?since version? This option defines globals available when your code is running inside of a Web Worker.
|
|
101
|
+
"wsh" : false, // Enable globals available when your code is running as a script for the Windows Script Host.
|
|
102
|
+
"yui" : false, //?since version? This option defines globals exposed by the YUI JavaScript framework.
|
|
103
|
+
|
|
104
|
+
// == JSLint Legacy ===================================================
|
|
105
|
+
//
|
|
106
|
+
// These options are legacy from JSLint. Aside from bug fixes they will
|
|
107
|
+
// not be improved in any way and might be removed at any point.
|
|
108
|
+
"nomen" : false, // Prohibit use of initial or trailing underbars in names.
|
|
109
|
+
"onevar" : false, // Allow only one `var` statement per function.
|
|
110
|
+
"passfail" : false, // Stop on first error.
|
|
111
|
+
"white" : false, // Check against strict whitespace and indentation rules.
|
|
112
|
+
|
|
113
|
+
// == Undocumented Options ============================================
|
|
114
|
+
//
|
|
115
|
+
// While Michael have found these options in [example1][2] and [example2][3] (already gone 404)
|
|
116
|
+
// they are not described in the [JSHint Options documentation][4].
|
|
117
|
+
|
|
118
|
+
"predef" : [ // Extra globals.
|
|
119
|
+
//"exampleVar",
|
|
120
|
+
//"anotherCoolGlobal",
|
|
121
|
+
//"iLoveDouglas"
|
|
122
|
+
"Java", "JavaFX", "$ARG" //no effect
|
|
123
|
+
]
|
|
124
|
+
//, "indent" : 2 // Specify indentation spacing
|
|
125
|
+
}
|
package/.npmignore
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2015 Julian Ćwirko <julian.io>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# Selkirk Fetch
|
|
2
|
+
|
|
3
|
+
This is a wrapper for [isomorphic-fetch](https://github.com/matthew-andrews/isomorphic-fetch).
|
|
4
|
+
All options provided by isomorphic-fetch are available by default.
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
### Notes
|
|
8
|
+
This wrapper abstracts some additional config that selkirk would use 90% of the time.
|
|
9
|
+
All config options can be overridden if needed
|
|
10
|
+
|
|
11
|
+
Config
|
|
12
|
+
- All Data sent and received assumed to be JSON
|
|
13
|
+
- Anything set to the body property is automatically JSON.stringify
|
|
14
|
+
- Method "GET" is assumed if not provided
|
|
15
|
+
- Responses from the server are processed into JSON objects automatically.
|
|
16
|
+
- Errors in responses are also processed and will cause a "catch" to fire based on httpResponseCodes
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Component Example
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
const Fetch = require('selkirk-fetch');
|
|
23
|
+
|
|
24
|
+
Fetch('/api', {
|
|
25
|
+
method: 'put',
|
|
26
|
+
body : user
|
|
27
|
+
})
|
|
28
|
+
.then((response)=> {
|
|
29
|
+
//response is already processed into a valid obj and can be used as such
|
|
30
|
+
|
|
31
|
+
Dispatcher.handleViewAction({
|
|
32
|
+
actionType: Constants.USER_SUBMITTED,
|
|
33
|
+
item : response
|
|
34
|
+
})
|
|
35
|
+
})
|
|
36
|
+
.catch((err)=> {
|
|
37
|
+
//valid httpResponseCodes that are considered errors will trigger a catch (500,401) etc.
|
|
38
|
+
|
|
39
|
+
_onError(err);
|
|
40
|
+
Dispatcher.handleViewAction({
|
|
41
|
+
actionType: Constants.USER_SUBMIT_FAILED,
|
|
42
|
+
})
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
#### Boilerplate
|
|
48
|
+
|
|
49
|
+
The package is based on [react-npm-boilerplate](https://github.com/juliancwirko/react-npm-boilerplate). This one is prepared to be used as a starter point for React components which needs to be published on Npm.
|
|
50
|
+
|
|
51
|
+
It includes linting with [ESLint](http://eslint.org/) and testing with [Mocha](https://mochajs.org/), [Enzyme](http://airbnb.io/enzyme/) and [JSDOM](https://github.com/tmpvar/jsdom).
|
|
52
|
+
|
|
53
|
+
Also there is of course ES6 transpilation.
|
|
54
|
+
|
|
55
|
+
#### Basic Usage
|
|
56
|
+
|
|
57
|
+
1. Clone this repo
|
|
58
|
+
2. Inside cloned repo run `npm install`
|
|
59
|
+
3. If you want to run tests: `npm test` or `npm run testonly` or `npm run test-watch`. You need to write tests in `__tests__` folder. You need at least Node 4 on your machine to run tests.
|
|
60
|
+
4. If you want to run linting: `npm test` or `npm run lint`. Fix bugs: `npm run lint-fix`. You can adjust your `.eslintrc` config file.
|
|
61
|
+
5. If you want to run transpilation to ES5 in `dist` folder: `npm run prepublish` (standard npm hook).
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// Demo component
|
|
4
|
+
// this is only example component
|
|
5
|
+
// you can find tests in __test__ folder
|
|
6
|
+
|
|
7
|
+
var React = require("react");
|
|
8
|
+
var DOM = require('react-dom');
|
|
9
|
+
|
|
10
|
+
var MyComponent = React.createClass({
|
|
11
|
+
displayName: "MyComponent",
|
|
12
|
+
componentDidMount: function componentDidMount() {
|
|
13
|
+
// some logic here - we only test if the method is called
|
|
14
|
+
},
|
|
15
|
+
render: function render() {
|
|
16
|
+
return React.createElement(
|
|
17
|
+
"div",
|
|
18
|
+
{ className: "my-component" },
|
|
19
|
+
React.createElement("i", { className: "icon-test" }),
|
|
20
|
+
React.createElement("i", { className: "icon-test" }),
|
|
21
|
+
React.createElement("i", { className: "icon-test" }),
|
|
22
|
+
React.createElement("button", { onClick: this.props.handleClick, type: "button" })
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
module.exports = MyComponent;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var Assign = require("object-assign");
|
|
4
|
+
var Promise = require("bluebird");
|
|
5
|
+
|
|
6
|
+
require('es6-promise').polyfill();
|
|
7
|
+
require('isomorphic-fetch');
|
|
8
|
+
|
|
9
|
+
var _networkTimer = null;
|
|
10
|
+
|
|
11
|
+
function _checkFetchStatus(response) {
|
|
12
|
+
if (response.status >= 200 && response.status < 300) {
|
|
13
|
+
return response.json();
|
|
14
|
+
} else {
|
|
15
|
+
var error = new Error(response.statusText);
|
|
16
|
+
return response.json().then(function (result) {
|
|
17
|
+
error.response = result;
|
|
18
|
+
throw error;
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function _invokeFetch(url, props) {
|
|
24
|
+
if (!url) {
|
|
25
|
+
throw new Error("fetch:Missing Parameter - URL");
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
var options = Assign({
|
|
29
|
+
method: "GET",
|
|
30
|
+
credentials: 'same-origin',
|
|
31
|
+
headers: {
|
|
32
|
+
'Accept': 'application/json',
|
|
33
|
+
'Content-Type': 'application/json'
|
|
34
|
+
}
|
|
35
|
+
}, props);
|
|
36
|
+
|
|
37
|
+
if (_networkTimer) {
|
|
38
|
+
return new Promise(function (resolve, reject) {
|
|
39
|
+
setTimeout(resolve, _networkTimer);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (options.body) options.body = JSON.stringify(options.body);
|
|
44
|
+
|
|
45
|
+
return fetch(url, options).then(_checkFetchStatus);
|
|
46
|
+
}
|
|
47
|
+
module.exports = function (dispatcher, params) {
|
|
48
|
+
if (!dispatcher) return _invokeFetch;
|
|
49
|
+
|
|
50
|
+
var options = Assign({
|
|
51
|
+
lastErrorEvent: "LAST_ERROR_EVENT",
|
|
52
|
+
errorID: null
|
|
53
|
+
}, params);
|
|
54
|
+
|
|
55
|
+
return function (url, props, responseEvent) {
|
|
56
|
+
return _invokeFetch(url, props).then(function (response) {
|
|
57
|
+
|
|
58
|
+
if (!responseEvent) return null;
|
|
59
|
+
|
|
60
|
+
dispatcher.handleViewAction({
|
|
61
|
+
actionType: responseEvent,
|
|
62
|
+
item: response
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
return response;
|
|
66
|
+
}).catch(function (err) {
|
|
67
|
+
console.error(new Error("Fetch - " + options.errorID || ""), err);
|
|
68
|
+
dispatcher.handleViewAction({
|
|
69
|
+
actionType: options.lastErrorEvent,
|
|
70
|
+
item: { error: err, id: options.errorID }
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
};
|
package/gulpfile.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
var gulp = require('gulp');
|
|
2
|
+
var bambooUtil = require('@selkirk-systems/bamboo-util')();
|
|
3
|
+
var concat = require('gulp-concat');
|
|
4
|
+
|
|
5
|
+
gulp.task('projectInit', bambooUtil.projectInit);
|
|
6
|
+
gulp.task('npmPublish', bambooUtil.npmPublish);
|
|
7
|
+
gulp.task('concatCss', function () {
|
|
8
|
+
return gulp.src('./src/css/*.css')
|
|
9
|
+
.pipe(concat('form-controls.css'))
|
|
10
|
+
.pipe(gulp.dest('./dist/css/'));
|
|
11
|
+
});
|
package/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/index');
|
package/package.json
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@selkirk-systems/fetch",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A wrapper on fetch-polyfill that will work for server and client environments",
|
|
5
|
+
"selkirk": {
|
|
6
|
+
"bambooDeploy": "npm",
|
|
7
|
+
"bambooKey": "EDF",
|
|
8
|
+
"bambooUrl": [
|
|
9
|
+
"http://bamboo5.selkirksystems.com/browse/RCB-EDFDEF",
|
|
10
|
+
"http://bamboo5.selkirksystems.com/browse/RCB-EDFPUB"
|
|
11
|
+
]
|
|
12
|
+
},
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"registry": "https://registry.npmjs.org/"
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "https://bitbucket.org/selkirk/selkirk-fetch.git"
|
|
19
|
+
},
|
|
20
|
+
"author": "Marcos Bernal <mbernal@selkirksystems.com>",
|
|
21
|
+
"contributors": [
|
|
22
|
+
{
|
|
23
|
+
"name": "Marcos Bernal",
|
|
24
|
+
"email": "mbernal@selkirksystems.com"
|
|
25
|
+
}
|
|
26
|
+
],
|
|
27
|
+
"homepage": "https://bitbucket.org/selkirk/selkirk-fetch/wiki/Home",
|
|
28
|
+
"keywords": [
|
|
29
|
+
"react-component",
|
|
30
|
+
"react",
|
|
31
|
+
"utility"
|
|
32
|
+
],
|
|
33
|
+
"scripts": {
|
|
34
|
+
"prepublish": "babel src --ignore __tests__ --out-dir ./dist",
|
|
35
|
+
"lint": "eslint ./src",
|
|
36
|
+
"lintfix": "eslint ./src --fix",
|
|
37
|
+
"testonly": "mocha --require scripts/mocha_runner src/**/__tests__/**/*.js",
|
|
38
|
+
"test": "npm run lint && npm run testonly",
|
|
39
|
+
"test-watch": "npm run testonly -- --watch --watch-extensions js"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"babel-cli": "^6.6.4",
|
|
43
|
+
"babel-core": "^6.7.4",
|
|
44
|
+
"babel-eslint": "^6.0.2",
|
|
45
|
+
"babel-plugin-transform-es2015-modules-umd": "^6.6.5",
|
|
46
|
+
"babel-polyfill": "^6.7.4",
|
|
47
|
+
"babel-preset-es2015": "^6.6.0",
|
|
48
|
+
"babel-preset-react": "^6.5.0",
|
|
49
|
+
"babel-preset-stage-2": "^6.5.0",
|
|
50
|
+
"babelify": "^7.3.0",
|
|
51
|
+
"@selkirk-systems/bamboo-util": "~1.2.0",
|
|
52
|
+
"chai": "^3.5.0",
|
|
53
|
+
"enzyme": "^2.2.0",
|
|
54
|
+
"eslint": "^2.7.0",
|
|
55
|
+
"eslint-plugin-babel": "^3.1.0",
|
|
56
|
+
"eslint-plugin-react": "^4.2.3",
|
|
57
|
+
"gulp": "^3.9.1",
|
|
58
|
+
"gulp-concat": "^2.6.0",
|
|
59
|
+
"jsdom": "^8.1.0",
|
|
60
|
+
"mocha": "^2.4.5",
|
|
61
|
+
"nodemon": "^1.9.1",
|
|
62
|
+
"react-addons-test-utils": "^15.0.0",
|
|
63
|
+
"sinon": "^1.17.3"
|
|
64
|
+
},
|
|
65
|
+
"dependencies": {
|
|
66
|
+
"babel-runtime": "^6.6.1",
|
|
67
|
+
"bluebird": "^3.4.6",
|
|
68
|
+
"es6-promise": "^3.2.1",
|
|
69
|
+
"isomorphic-fetch": "^2.2.1",
|
|
70
|
+
"object-assign": "^4.1.0"
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
var jsdom = require('jsdom').jsdom;
|
|
2
|
+
|
|
3
|
+
var exposedProperties = ['window', 'navigator', 'document'];
|
|
4
|
+
|
|
5
|
+
global.document = jsdom('');
|
|
6
|
+
global.window = document.defaultView;
|
|
7
|
+
Object.keys(document.defaultView).forEach((property) => {
|
|
8
|
+
if (typeof global[property] === 'undefined') {
|
|
9
|
+
exposedProperties.push(property);
|
|
10
|
+
global[property] = document.defaultView[property];
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
global.navigator = {
|
|
15
|
+
userAgent: 'node.js'
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
documentRef = document;
|
|
19
|
+
|
|
20
|
+
require('babel-core/register');
|
|
21
|
+
require('babel-polyfill');
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/*
|
|
2
|
+
import React from 'react';
|
|
3
|
+
|
|
4
|
+
import {shallow, mount, render} from 'enzyme';
|
|
5
|
+
import {expect} from 'chai';
|
|
6
|
+
import sinon from 'sinon';
|
|
7
|
+
|
|
8
|
+
import MyComponent from '../exampleTests';
|
|
9
|
+
|
|
10
|
+
// Demo tests
|
|
11
|
+
|
|
12
|
+
// Shallow Rendering
|
|
13
|
+
// https://github.com/airbnb/enzyme/blob/master/docs/api/shallow.md
|
|
14
|
+
describe('Shallow Rendering', () => {
|
|
15
|
+
|
|
16
|
+
it('to have three `.icon-test`s', () => {
|
|
17
|
+
const wrapper = shallow(<MyComponent />);
|
|
18
|
+
expect(wrapper.find('.icon-test')).to.have.length(3);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('simulates click events', () => {
|
|
22
|
+
const buttonClick = sinon.spy();
|
|
23
|
+
const wrapper = shallow(
|
|
24
|
+
<MyComponent handleClick={buttonClick} />
|
|
25
|
+
);
|
|
26
|
+
wrapper.find('button').simulate('click');
|
|
27
|
+
expect(buttonClick.calledOnce).to.equal(true);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// Full DOM Rendering
|
|
33
|
+
// https://github.com/airbnb/enzyme/blob/master/docs/api/mount.md
|
|
34
|
+
describe('Full DOM Rendering', () => {
|
|
35
|
+
|
|
36
|
+
it('allows us to set props', () => {
|
|
37
|
+
const wrapper = mount(<MyComponent bar='baz' />);
|
|
38
|
+
expect(wrapper.props().bar).to.equal('baz');
|
|
39
|
+
wrapper.setProps({ bar: 'foo' });
|
|
40
|
+
expect(wrapper.props().bar).to.equal('foo');
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('calls componentDidMount', () => {
|
|
44
|
+
sinon.spy(MyComponent.prototype, 'componentDidMount');
|
|
45
|
+
const wrapper = mount(<MyComponent />);
|
|
46
|
+
expect(MyComponent.prototype.componentDidMount.calledOnce).to.be.true;
|
|
47
|
+
MyComponent.prototype.componentDidMount.restore();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
// Static Rendered Markup
|
|
53
|
+
// https://github.com/airbnb/enzyme/blob/master/docs/api/render.md
|
|
54
|
+
describe('Static Rendered Markup', () => {
|
|
55
|
+
|
|
56
|
+
it('renders three `.icon-test`s', () => {
|
|
57
|
+
const wrapper = render(<MyComponent />);
|
|
58
|
+
expect(wrapper.find('.icon-test').length).to.equal(3);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
});*/
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Demo component
|
|
2
|
+
// this is only example component
|
|
3
|
+
// you can find tests in __test__ folder
|
|
4
|
+
|
|
5
|
+
const React = require("react");
|
|
6
|
+
const DOM = require('react-dom');
|
|
7
|
+
|
|
8
|
+
const MyComponent = React.createClass({
|
|
9
|
+
componentDidMount() {
|
|
10
|
+
// some logic here - we only test if the method is called
|
|
11
|
+
},
|
|
12
|
+
render() {
|
|
13
|
+
return(
|
|
14
|
+
<div className="my-component">
|
|
15
|
+
<i className="icon-test"></i>
|
|
16
|
+
<i className="icon-test"></i>
|
|
17
|
+
<i className="icon-test"></i>
|
|
18
|
+
<button onClick={this.props.handleClick} type="button"></button>
|
|
19
|
+
</div>
|
|
20
|
+
)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
module.exports = MyComponent;
|
package/src/index.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
const Assign = require("object-assign");
|
|
2
|
+
const Promise = require("bluebird");
|
|
3
|
+
|
|
4
|
+
require('es6-promise').polyfill();
|
|
5
|
+
require('isomorphic-fetch');
|
|
6
|
+
|
|
7
|
+
const _networkTimer = null;
|
|
8
|
+
|
|
9
|
+
function _checkFetchStatus(response) {
|
|
10
|
+
if (response.status >= 200 && response.status < 300) {
|
|
11
|
+
return response.json()
|
|
12
|
+
} else {
|
|
13
|
+
var error = new Error(response.statusText);
|
|
14
|
+
return response.json().then((result)=>{
|
|
15
|
+
error.response = result;
|
|
16
|
+
throw error;
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function _invokeFetch(url,props) {
|
|
22
|
+
if(!url) {
|
|
23
|
+
throw new Error("fetch:Missing Parameter - URL");
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
var options = Assign({
|
|
27
|
+
method:"GET",
|
|
28
|
+
credentials:'same-origin',
|
|
29
|
+
headers: {
|
|
30
|
+
'Accept': 'application/json',
|
|
31
|
+
'Content-Type': 'application/json'
|
|
32
|
+
}
|
|
33
|
+
},props);
|
|
34
|
+
|
|
35
|
+
if(_networkTimer){
|
|
36
|
+
return new Promise((resolve,reject)=>{
|
|
37
|
+
setTimeout(resolve,_networkTimer);
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if(options.body)options.body = JSON.stringify(options.body);
|
|
42
|
+
|
|
43
|
+
return fetch(url, options)
|
|
44
|
+
.then(_checkFetchStatus)
|
|
45
|
+
}
|
|
46
|
+
module.exports = function(dispatcher,params){
|
|
47
|
+
if(!dispatcher) return _invokeFetch;
|
|
48
|
+
|
|
49
|
+
const options = Assign({
|
|
50
|
+
lastErrorEvent:"LAST_ERROR_EVENT",
|
|
51
|
+
errorID: null
|
|
52
|
+
}, params);
|
|
53
|
+
|
|
54
|
+
return function(url,props,responseEvent){
|
|
55
|
+
return _invokeFetch(url,props)
|
|
56
|
+
.then((response)=>{
|
|
57
|
+
|
|
58
|
+
if(!responseEvent) return null;
|
|
59
|
+
|
|
60
|
+
dispatcher.handleViewAction({
|
|
61
|
+
actionType: responseEvent,
|
|
62
|
+
item: response
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
return response;
|
|
66
|
+
})
|
|
67
|
+
.catch((err)=>{
|
|
68
|
+
console.error(new Error("Fetch - " + options.errorID ||""),err);
|
|
69
|
+
dispatcher.handleViewAction({
|
|
70
|
+
actionType: options.lastErrorEvent,
|
|
71
|
+
item: {error:err,id:options.errorID}
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
})
|
|
75
|
+
}
|
|
76
|
+
};
|