mirror of
https://github.com/bellingcat/ukraine-timemap.git
synced 2026-06-08 03:18:36 +03:00
Add basic http smoke test
- Add mocha dev dependency - Add test to launch server and GET basic urls - Add `yarn test` to travis
This commit is contained in:
@@ -11,3 +11,4 @@ install:
|
||||
- yarn
|
||||
script:
|
||||
- yarn build
|
||||
- yarn test
|
||||
|
||||
@@ -6,7 +6,8 @@
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "webpack-dev-server --content-base static --mode development",
|
||||
"build": "NODE_ENV=production webpack --mode production"
|
||||
"build": "NODE_ENV=production webpack --mode production",
|
||||
"test": "./node_modules/mocha/bin/mocha"
|
||||
},
|
||||
"dependencies": {
|
||||
"babel-polyfill": "^6.26.0",
|
||||
@@ -37,6 +38,7 @@
|
||||
"file-loader": "^2.0.0",
|
||||
"html-webpack-plugin": "^3.2.0",
|
||||
"mini-css-extract-plugin": "^0.4.4",
|
||||
"mocha": "^5.2.0",
|
||||
"node-sass": "^4.9.4",
|
||||
"redux-devtools": "^3.4.0",
|
||||
"sass-loader": "^7.1.0",
|
||||
|
||||
73
test/server_process.js
Normal file
73
test/server_process.js
Normal file
@@ -0,0 +1,73 @@
|
||||
var assert = require('assert');
|
||||
var child_process = require('child_process')
|
||||
var http = require('http');
|
||||
|
||||
var SERVER_LAUNCH_WAIT_TIME = 5 * 1000;
|
||||
|
||||
describe('server process', function() {
|
||||
var server_proc = null;
|
||||
var server_exited = false;
|
||||
|
||||
before(function() {
|
||||
this.timeout(SERVER_LAUNCH_WAIT_TIME + 1000);
|
||||
|
||||
console.log("launching server...")
|
||||
server_proc = child_process.spawn('yarn', ['dev'], {
|
||||
cwd: '.'
|
||||
});
|
||||
|
||||
server_proc.on('exit', function(code, signal) {
|
||||
server_exited = true;
|
||||
});
|
||||
|
||||
return (new Promise(function(done) {
|
||||
// @TODO Better way to detect server alive-ness than waiting?
|
||||
setTimeout(done, SERVER_LAUNCH_WAIT_TIME)
|
||||
}));
|
||||
});
|
||||
|
||||
after(function() {
|
||||
console.log("killing server...")
|
||||
server_proc.kill();
|
||||
});
|
||||
|
||||
it('should launch', function() {
|
||||
assert.equal(server_exited, false);
|
||||
});
|
||||
|
||||
var urls = [
|
||||
'/',
|
||||
'js/index.bundle.js'
|
||||
];
|
||||
|
||||
urls.forEach(function(url) {
|
||||
|
||||
it('should respond to request for "' + url + '"', function(done) {
|
||||
|
||||
http.get({
|
||||
hostname: 'localhost',
|
||||
port: 8080,
|
||||
path: '/'
|
||||
}, function(res) {
|
||||
var result_data = '';
|
||||
|
||||
if(res.statusCode != 200) {
|
||||
throw new Error('Server response was not 200.');
|
||||
}
|
||||
|
||||
res.on('data', function(data) { result_data += data });
|
||||
|
||||
res.on('end', function() {
|
||||
if (result_data.length > 0) {
|
||||
done();
|
||||
} else {
|
||||
done(new Error("Server returned no data."));
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user