Last active
December 16, 2016 03:03
-
-
Save ctaggart/001de11269981c1d4eb3d3e5d38fa4b7 to your computer and use it in GitHub Desktop.
Fetch from Browsers using Mocha & System.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -e | |
npm install --save-dev typescript | |
npm install --save-dev http-server | |
# browser | |
npm install --save whatwg-fetch | |
npm install --save-dev @types/whatwg-fetch | |
npm install --save es6-promise | |
npm install --save systemjs | |
npm install --save-dev @types/systemjs | |
# node | |
npm install --save node-fetch | |
npm install --save-dev @types/node | |
# testing | |
npm install --save-dev mocha | |
npm install --save-dev @types/mocha | |
npm install --save-dev chai | |
npm install --save-dev @types/chai |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Mocha = require("mocha"); | |
import fetch = require("node-fetch"); | |
(<any>global).fetch = fetch; | |
var runner = new Mocha({ui: "bdd"}); | |
runner.addFile("node/build/fetch-tests.js"); | |
runner.run(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"compilerOptions": { | |
"module": "commonjs", | |
"moduleResolution": "node", | |
"sourceMap": true, | |
"target": "es6", | |
"outDir": "build" | |
}, | |
"files": [ | |
"tests.ts", | |
"../fetch-tests.ts", | |
"../FreeGeoIP.d.ts" | |
], | |
"typeRoots": [ | |
"../../node_modules/@types" | |
] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>tests</title> | |
<link href="node_modules/mocha/mocha.css" rel="stylesheet" /> | |
</head> | |
<body> | |
<div id="mocha"></div> | |
<script src="node_modules/es6-promise/dist/es6-promise.js"></script> | |
<script src="node_modules/whatwg-fetch/fetch.js"></script> | |
<script src="node_modules/systemjs/dist/system.js"></script> | |
<script src="build/tests.js"></script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SystemJS.config({ | |
meta: { | |
'node_modules/mocha/mocha.js': { format: 'global' } | |
}, | |
map: { | |
chai: "node_modules/chai/chai.js", | |
mocha: "node_modules/mocha/mocha.js" | |
} | |
}); | |
SystemJS.import("mocha").then(m => { | |
mocha.setup("bdd"); // https://mochajs.org/#bdd | |
SystemJS.import("build/fetch-tests.js").then(m => { | |
mocha.run(); | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
{ | |
"compilerOptions": { | |
"module": "system", | |
"sourceMap": true, | |
"target": "es5", | |
"lib": [ "dom", "es6" ], | |
"outDir": "build" | |
}, | |
"files": [ | |
"tests.ts", | |
"fetch-tests.ts", | |
"FreeGeoIP.d.ts" | |
], | |
"typeRoots": [ | |
"../node_modules/@types" | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment