mirror of
https://github.com/bellingcat/ukraine-timemap.git
synced 2026-06-08 03:18:36 +03:00
Switch test framework to ava
Should match datasheet-server.
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
"scripts": {
|
||||
"dev": "webpack-dev-server --content-base static --mode development",
|
||||
"build": "NODE_ENV=production webpack --mode production",
|
||||
"test": "./node_modules/mocha/bin/mocha"
|
||||
"test": "npx ava --verbose"
|
||||
},
|
||||
"dependencies": {
|
||||
"babel-polyfill": "^6.26.0",
|
||||
@@ -33,6 +33,7 @@
|
||||
"@babel/core": "^7.1.2",
|
||||
"@babel/preset-env": "^7.1.0",
|
||||
"@babel/preset-react": "^7.0.0",
|
||||
"ava": "1.0.0-beta.8",
|
||||
"babel-loader": "^8.0.4",
|
||||
"css-loader": "^1.0.0",
|
||||
"file-loader": "^2.0.0",
|
||||
@@ -46,5 +47,10 @@
|
||||
"webpack": "^4.20.2",
|
||||
"webpack-cli": "^3.1.2",
|
||||
"webpack-dev-server": "^3.1.9"
|
||||
},
|
||||
"ava": {
|
||||
"files": [
|
||||
"test/**/*.js"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,75 +1,67 @@
|
||||
var assert = require('assert');
|
||||
var child_process = require('child_process')
|
||||
var http = require('http');
|
||||
import test from 'ava'
|
||||
|
||||
var SERVER_LAUNCH_WAIT_TIME = 5 * 1000;
|
||||
const SERVER_LAUNCH_WAIT_TIME = 5 * 1000;
|
||||
|
||||
describe('server process', function() {
|
||||
var server_proc = null;
|
||||
var server_exited = false;
|
||||
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: '.',
|
||||
stdio: 'ignore'
|
||||
});
|
||||
|
||||
server_proc.on('exit', function(code, signal) {
|
||||
server_exited = true;
|
||||
});
|
||||
|
||||
return (new Promise(function(resolve) {
|
||||
// @TODO Better way to detect server alive-ness than waiting?
|
||||
setTimeout(resolve, SERVER_LAUNCH_WAIT_TIME)
|
||||
}));
|
||||
test.before.cb(t => {
|
||||
console.log("launching server...")
|
||||
server_proc = child_process.spawn('yarn', ['dev'], {
|
||||
cwd: '.',
|
||||
stdio: 'ignore'
|
||||
});
|
||||
|
||||
after(function() {
|
||||
console.log("killing server...")
|
||||
server_proc.kill('SIGKILL');
|
||||
server_proc.on('exit', function(code, signal) {
|
||||
server_exited = true;
|
||||
});
|
||||
|
||||
it('should launch', function() {
|
||||
assert.equal(server_exited, false);
|
||||
});
|
||||
setTimeout(t.end, SERVER_LAUNCH_WAIT_TIME)
|
||||
});
|
||||
|
||||
var urls = [
|
||||
'/',
|
||||
'js/index.bundle.js'
|
||||
];
|
||||
test.after(function() {
|
||||
console.log("killing server...")
|
||||
server_proc.kill('SIGKILL');
|
||||
});
|
||||
|
||||
urls.forEach(function(url) {
|
||||
test('should launch', t => {
|
||||
t.false(server_exited);
|
||||
});
|
||||
|
||||
it('should respond to request for "' + url + '"', function(done) {
|
||||
this.timeout(5000);
|
||||
var urls = [
|
||||
'/',
|
||||
'js/index.bundle.js'
|
||||
];
|
||||
|
||||
http.get({
|
||||
hostname: 'localhost',
|
||||
port: 8080,
|
||||
path: '/',
|
||||
agent: false
|
||||
}, function(res) {
|
||||
var result_data = '';
|
||||
|
||||
if(res.statusCode != 200) {
|
||||
throw new Error('Server response was not 200.');
|
||||
}
|
||||
urls.forEach(function(url) {
|
||||
test.cb('should respond to request for "' + url + '"', t => {
|
||||
http.get({
|
||||
hostname: 'localhost',
|
||||
port: 8080,
|
||||
path: '/',
|
||||
agent: false
|
||||
}, function(res) {
|
||||
var result_data = '';
|
||||
|
||||
if(res.statusCode != 200) {
|
||||
t.fail('Server response was not 200.');
|
||||
} else {
|
||||
res.on('data', function(data) { result_data += data });
|
||||
|
||||
res.on('end', function() {
|
||||
if (result_data.length > 0) {
|
||||
done();
|
||||
t.pass();
|
||||
} else {
|
||||
done(new Error("Server returned no data."));
|
||||
t.fail("Server returned no data.");
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
});
|
||||
t.end();
|
||||
})
|
||||
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user