Skip to content

Commit c99e4ec

Browse files
committed
Added check for self and window objects + tests
1 parent ebee841 commit c99e4ec

5 files changed

Lines changed: 26 additions & 8 deletions

File tree

.istanbul.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ instrumentation:
44
extensions:
55
- .js
66
default-excludes: true
7-
excludes: ['lib/browser.js']
87
reporting:
98
print: summary
109
reports:

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ script:
2020
- node --version
2121
- npm --version
2222
- npm run ci-lint
23-
- npm run test
23+
- npm run ci-test
2424
- npm run check
2525

2626
after_success:

lib/browser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
/* eslint-env browser */
2-
module.exports = self.FormData;
2+
module.exports = typeof self == 'object' ? self.FormData : window.FormData;

package.json

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@
1414
"test": "istanbul cover test/run.js",
1515
"posttest": "istanbul report lcov text",
1616
"lint": "eslint lib/*.js test/*.js test/integration/*.js",
17-
"ci-lint": "is-node-modern && npm run lint || is-node-not-modern",
17+
"report": "istanbul report lcov text",
18+
"ci-lint": "is-node-modern 6 && npm run lint || is-node-not-modern 6",
19+
"ci-test": "npm run test && npm run browser && npm run report",
1820
"predebug": "rimraf coverage test/tmp",
1921
"debug": "verbose=1 ./test/run.js",
22+
"browser": "browserify -t browserify-istanbul test/run-browser.js | obake --coverage",
2023
"check": "istanbul check-coverage coverage/coverage*.json",
2124
"files": "pkgfiles --sort=name",
2225
"get-version": "node -e \"console.log(require('./package.json').version)\"",
@@ -27,7 +30,7 @@
2730
},
2831
"pre-commit": [
2932
"lint",
30-
"test",
33+
"ci-test",
3134
"check"
3235
],
3336
"engines": {
@@ -39,19 +42,24 @@
3942
"mime-types": "^2.1.12"
4043
},
4144
"devDependencies": {
45+
"browserify": "^13.1.1",
46+
"browserify-istanbul": "^2.0.0",
4247
"coveralls": "^2.11.14",
4348
"cross-spawn": "^4.0.2",
44-
"eslint": "^3.7.1",
49+
"eslint": "^3.9.1",
4550
"fake": "^0.2.2",
4651
"far": "^0.0.7",
4752
"formidable": "^1.0.17",
4853
"in-publish": "^2.0.0",
4954
"is-node-modern": "^1.0.0",
5055
"istanbul": "^0.4.5",
56+
"obake": "^0.1.2",
57+
"phantomjs-prebuilt": "^2.1.13",
5158
"pkgfiles": "^2.3.0",
5259
"pre-commit": "^1.1.3",
53-
"request": "^2.75.0",
54-
"rimraf": "^2.5.4"
60+
"request": "2.76.0",
61+
"rimraf": "^2.5.4",
62+
"tape": "^4.6.2"
5563
},
5664
"license": "MIT"
5765
}

test/run-browser.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
var test = require('tape');
2+
var FormData = require('../lib/browser.js');
3+
var form = new FormData();
4+
5+
test('being nice to browser-like environments', function(t)
6+
{
7+
t.plan(3);
8+
t.notEqual(typeof FormData, 'undefined', 'FormData should be defined');
9+
t.equal(typeof form, 'object', 'FormData instance should be object');
10+
t.equal(typeof form.append, 'function', 'FormData instance should have `append` method');
11+
});

0 commit comments

Comments
 (0)