diff --git a/karma.js b/karma.js index 4da50d3..7cfb47d 100644 --- a/karma.js +++ b/karma.js @@ -13,9 +13,31 @@ const bodyParser = require('body-parser'); const cors = require('cors'); const filenamifyUrl = require('filenamify-url'); +const CORS_PORT = 8081; +const corsApp = express(); +corsApp.use(cors()); +corsApp.use('/', express.static(path.resolve(__dirname))); +corsApp.use((error, req, res, next) => { + console.error(error); + next(); +}); + +process.on('uncaughtException', (err) => { + if(err.errno === 'EADDRINUSE') { + console.warn(err); + } else { + console.log(err); + process.exit(1); + } +}); + +corsApp.listen(CORS_PORT, () => { + console.log(`CORS server running on port ${CORS_PORT}`); +}); + const app = express(); app.use(cors()); -app.use(function(req, res, next) { +app.use((req, res, next) => { // IE9 doesn't set headers for cross-domain ajax requests if(typeof(req.headers['content-type']) === 'undefined'){ req.headers['content-type'] = "application/json"; @@ -81,7 +103,7 @@ app.use((error, req, res, next) => { next(); }); -const listener = app.listen(8081, () => { +const listener = app.listen(8000, () => { server.start(); }); diff --git a/package.json b/package.json index 41d62e9..9e08dc2 100644 --- a/package.json +++ b/package.json @@ -52,6 +52,7 @@ "prettier": "1.5.3", "promise-polyfill": "6.0.2", "rimraf": "2.6.1", + "serve-index": "1.9.0", "slash": "1.0.0", "webpack": "3.4.1" }, @@ -64,7 +65,8 @@ "lint": "eslint src/**", "test": "npm run flow && npm run lint && npm run karma", "karma": "node karma", - "watch": "webpack --progress --colors --watch" + "watch": "webpack --progress --colors --watch", + "start": "node tests/server" }, "homepage": "https://html2canvas.hertzen.com", "license": "MIT", diff --git a/tests/server.js b/tests/server.js new file mode 100644 index 0000000..52d0fcb --- /dev/null +++ b/tests/server.js @@ -0,0 +1,41 @@ +const express = require('express'); +const cors = require('cors'); +const path = require('path'); +const fs = require('fs'); +const webpack = require('webpack'); +const config = require('../webpack.config'); +const serveIndex = require('serve-index'); + +const PORT = 8080; +const CORS_PORT = 8081; + +const app = express(); +app.use('/', serveIndex(path.resolve(__dirname, '../'), {icons: true})); +app.use('/', express.static(path.resolve(__dirname, '../'))); +app.listen(PORT, () => { + console.log(`Server running on port ${PORT}`); +}); + +const corsApp = express(); +corsApp.use(cors()); +corsApp.use('/', express.static(path.resolve(__dirname, '../'))); +corsApp.listen(CORS_PORT, () => { + console.log(`CORS server running on port ${CORS_PORT}`); +}); + +const compiler = webpack(config); +compiler.watch( + { + aggregateTimeout: 300 // wait so long for more changes + }, + (err, stats) => { + console.error(err); + + console.log( + stats.toString({ + chunks: false, // Makes the build much quieter + colors: true + }) + ); + } +); diff --git a/tests/testrunner.js b/tests/testrunner.js index 67ff291..4037289 100644 --- a/tests/testrunner.js +++ b/tests/testrunner.js @@ -117,7 +117,8 @@ const assertPath = (result, expected, desc) => { return testContainer.contentWindow .html2canvas(testContainer.contentWindow.document.documentElement, { removeContainer: true, - backgroundColor: '#ffffff' + backgroundColor: '#ffffff', + ...(testContainer.contentWindow.h2cOptions || {}) }) .then(canvas => { try { @@ -388,7 +389,7 @@ const assertPath = (result, expected, desc) => { version: platform.version } }), - 'http://localhost:8081/screenshot/chunk' + 'http://localhost:8000/screenshot/chunk' ) ) ); @@ -407,7 +408,7 @@ const assertPath = (result, expected, desc) => { version: platform.version } }), - 'http://localhost:8081/screenshot' + 'http://localhost:8000/screenshot' ); } });