Merge pull request #17 from scztt/topic/basic-smoke-test

Topic/basic smoke test
This commit is contained in:
Lachlan Kermode
2018-11-12 09:33:19 +00:00
committed by GitHub
3 changed files with 79 additions and 1 deletions

View File

@@ -11,3 +11,4 @@ install:
- yarn
script:
- yarn build
- yarn test

View File

@@ -6,7 +6,9 @@
"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": "ava --verbose",
"test-watch": "ava --watch"
},
"dependencies": {
"babel-polyfill": "^6.26.0",
@@ -32,11 +34,13 @@
"@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",
"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",
@@ -44,5 +48,10 @@
"webpack": "^4.20.2",
"webpack-cli": "^3.1.2",
"webpack-dev-server": "^3.1.9"
},
"ava": {
"files": [
"test/**/*.js"
]
}
}

68
test/server_process.js Normal file
View File

@@ -0,0 +1,68 @@
var assert = require('assert');
var child_process = require('child_process')
var http = require('http');
import test from 'ava'
const SERVER_LAUNCH_WAIT_TIME = 5 * 1000;
var server_proc = null;
var server_exited = false;
test.before.cb(t => {
console.log("launching server...")
server_proc = child_process.spawn('yarn', ['dev'], {
cwd: '.',
stdio: 'ignore'
});
server_proc.on('exit', function(code, signal) {
server_exited = true;
});
setTimeout(t.end, SERVER_LAUNCH_WAIT_TIME)
});
test.after(function() {
console.log("killing server...")
server_proc.kill('SIGKILL');
});
test('should launch', t => {
t.false(server_exited);
});
var urls = [
'/',
'js/index.bundle.js'
];
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) {
t.pass();
} else {
t.fail("Server returned no data.");
}
});
}
t.end();
})
});
});