diff --git a/.travis.yml b/.travis.yml index 6409518..575e07a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,3 +11,4 @@ install: - yarn script: - yarn build + - yarn test diff --git a/package.json b/package.json index 34953ed..be401e2 100644 --- a/package.json +++ b/package.json @@ -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" + ] } } diff --git a/test/server_process.js b/test/server_process.js new file mode 100644 index 0000000..350e901 --- /dev/null +++ b/test/server_process.js @@ -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(); + }) + + }); + +});