mirror of
https://github.com/niklasvh/html2canvas.git
synced 2023-08-10 21:13:10 +03:00
Add dev server script
This commit is contained in:
parent
1a53643457
commit
0f9f8ff494
26
karma.js
26
karma.js
@ -13,9 +13,31 @@ const bodyParser = require('body-parser');
|
|||||||
const cors = require('cors');
|
const cors = require('cors');
|
||||||
const filenamifyUrl = require('filenamify-url');
|
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();
|
const app = express();
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
app.use(function(req, res, next) {
|
app.use((req, res, next) => {
|
||||||
// IE9 doesn't set headers for cross-domain ajax requests
|
// IE9 doesn't set headers for cross-domain ajax requests
|
||||||
if(typeof(req.headers['content-type']) === 'undefined'){
|
if(typeof(req.headers['content-type']) === 'undefined'){
|
||||||
req.headers['content-type'] = "application/json";
|
req.headers['content-type'] = "application/json";
|
||||||
@ -81,7 +103,7 @@ app.use((error, req, res, next) => {
|
|||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
const listener = app.listen(8081, () => {
|
const listener = app.listen(8000, () => {
|
||||||
server.start();
|
server.start();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -52,6 +52,7 @@
|
|||||||
"prettier": "1.5.3",
|
"prettier": "1.5.3",
|
||||||
"promise-polyfill": "6.0.2",
|
"promise-polyfill": "6.0.2",
|
||||||
"rimraf": "2.6.1",
|
"rimraf": "2.6.1",
|
||||||
|
"serve-index": "1.9.0",
|
||||||
"slash": "1.0.0",
|
"slash": "1.0.0",
|
||||||
"webpack": "3.4.1"
|
"webpack": "3.4.1"
|
||||||
},
|
},
|
||||||
@ -64,7 +65,8 @@
|
|||||||
"lint": "eslint src/**",
|
"lint": "eslint src/**",
|
||||||
"test": "npm run flow && npm run lint && npm run karma",
|
"test": "npm run flow && npm run lint && npm run karma",
|
||||||
"karma": "node karma",
|
"karma": "node karma",
|
||||||
"watch": "webpack --progress --colors --watch"
|
"watch": "webpack --progress --colors --watch",
|
||||||
|
"start": "node tests/server"
|
||||||
},
|
},
|
||||||
"homepage": "https://html2canvas.hertzen.com",
|
"homepage": "https://html2canvas.hertzen.com",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
41
tests/server.js
Normal file
41
tests/server.js
Normal file
@ -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
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
@ -117,7 +117,8 @@ const assertPath = (result, expected, desc) => {
|
|||||||
return testContainer.contentWindow
|
return testContainer.contentWindow
|
||||||
.html2canvas(testContainer.contentWindow.document.documentElement, {
|
.html2canvas(testContainer.contentWindow.document.documentElement, {
|
||||||
removeContainer: true,
|
removeContainer: true,
|
||||||
backgroundColor: '#ffffff'
|
backgroundColor: '#ffffff',
|
||||||
|
...(testContainer.contentWindow.h2cOptions || {})
|
||||||
})
|
})
|
||||||
.then(canvas => {
|
.then(canvas => {
|
||||||
try {
|
try {
|
||||||
@ -388,7 +389,7 @@ const assertPath = (result, expected, desc) => {
|
|||||||
version: platform.version
|
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
|
version: platform.version
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
'http://localhost:8081/screenshot'
|
'http://localhost:8000/screenshot'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user