Skip to content

Commit

Permalink
Merge pull request #282 from alexindigo/master
Browse files Browse the repository at this point in the history
#271 Added check for self and window objects + tests
  • Loading branch information
alexindigo committed Nov 8, 2016
2 parents ebee841 + c99e4ec commit 3e4ccf4
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 8 deletions.
1 change: 0 additions & 1 deletion .istanbul.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ instrumentation:
extensions:
- .js
default-excludes: true
excludes: ['lib/browser.js']
reporting:
print: summary
reports:
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ script:
- node --version
- npm --version
- npm run ci-lint
- npm run test
- npm run ci-test
- npm run check

after_success:
Expand Down
2 changes: 1 addition & 1 deletion lib/browser.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/* eslint-env browser */
module.exports = self.FormData;
module.exports = typeof self == 'object' ? self.FormData : window.FormData;
18 changes: 13 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@
"test": "istanbul cover test/run.js",
"posttest": "istanbul report lcov text",
"lint": "eslint lib/*.js test/*.js test/integration/*.js",
"ci-lint": "is-node-modern && npm run lint || is-node-not-modern",
"report": "istanbul report lcov text",
"ci-lint": "is-node-modern 6 && npm run lint || is-node-not-modern 6",
"ci-test": "npm run test && npm run browser && npm run report",
"predebug": "rimraf coverage test/tmp",
"debug": "verbose=1 ./test/run.js",
"browser": "browserify -t browserify-istanbul test/run-browser.js | obake --coverage",
"check": "istanbul check-coverage coverage/coverage*.json",
"files": "pkgfiles --sort=name",
"get-version": "node -e \"console.log(require('./package.json').version)\"",
Expand All @@ -27,7 +30,7 @@
},
"pre-commit": [
"lint",
"test",
"ci-test",
"check"
],
"engines": {
Expand All @@ -39,19 +42,24 @@
"mime-types": "^2.1.12"
},
"devDependencies": {
"browserify": "^13.1.1",
"browserify-istanbul": "^2.0.0",
"coveralls": "^2.11.14",
"cross-spawn": "^4.0.2",
"eslint": "^3.7.1",
"eslint": "^3.9.1",
"fake": "^0.2.2",
"far": "^0.0.7",
"formidable": "^1.0.17",
"in-publish": "^2.0.0",
"is-node-modern": "^1.0.0",
"istanbul": "^0.4.5",
"obake": "^0.1.2",
"phantomjs-prebuilt": "^2.1.13",
"pkgfiles": "^2.3.0",
"pre-commit": "^1.1.3",
"request": "^2.75.0",
"rimraf": "^2.5.4"
"request": "2.76.0",
"rimraf": "^2.5.4",
"tape": "^4.6.2"
},
"license": "MIT"
}
11 changes: 11 additions & 0 deletions test/run-browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
var test = require('tape');
var FormData = require('../lib/browser.js');
var form = new FormData();

test('being nice to browser-like environments', function(t)
{
t.plan(3);
t.notEqual(typeof FormData, 'undefined', 'FormData should be defined');
t.equal(typeof form, 'object', 'FormData instance should be object');
t.equal(typeof form.append, 'function', 'FormData instance should have `append` method');
});

0 comments on commit 3e4ccf4

Please sign in to comment.