Use a separate docker nginx image to serve test files
This obviates the need to start/stop a web-server for each package test and paves the way to something we'll need later.
This commit is contained in:
parent
ee79695d04
commit
79b9cd734b
@ -1,4 +1,11 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
nodejs node_modules/lerna/bin/lerna.js run pre-commit\
|
docker-compose up --detach test-web
|
||||||
&& npm run check_code_format
|
|
||||||
|
nodejs node_modules/lerna/bin/lerna.js run pre-commit \
|
||||||
|
&& npm run check_code_format
|
||||||
|
EXIT=$?
|
||||||
|
|
||||||
|
docker-compose stop test-web
|
||||||
|
|
||||||
|
exit $EXIT
|
||||||
|
|||||||
@ -3,8 +3,6 @@
|
|||||||
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const url = require('url');
|
|
||||||
const http = require('http');
|
|
||||||
|
|
||||||
const chromeLauncher = require('chrome-launcher');
|
const chromeLauncher = require('chrome-launcher');
|
||||||
const CDP = require('chrome-remote-interface');
|
const CDP = require('chrome-remote-interface');
|
||||||
@ -12,12 +10,11 @@ const CDP = require('chrome-remote-interface');
|
|||||||
const SPEC_DIR = 'spec';
|
const SPEC_DIR = 'spec';
|
||||||
const TEST_FILENAME = '.spec_runner.html';
|
const TEST_FILENAME = '.spec_runner.html';
|
||||||
const HOST = '127.0.0.1';
|
const HOST = '127.0.0.1';
|
||||||
// Randomize the port so we can just run again if there's a stuck process.
|
const PORT = 8090;
|
||||||
const PORT = Math.floor(Math.random() * 40000) + 1025;
|
|
||||||
|
|
||||||
const DEBUG =
|
const DEBUG =
|
||||||
typeof process.env['DEBUG'] === 'string'
|
typeof process.env['DEBUG'] === 'string'
|
||||||
? process.env['DEBUG'].toLower() == 'true'
|
? process.env['DEBUG'].toLowerCase() == 'true'
|
||||||
: !!process.env['DEBUG'];
|
: !!process.env['DEBUG'];
|
||||||
const PORTFOLIO_DIR = path.normalize(path.join(__dirname, '..'));
|
const PORTFOLIO_DIR = path.normalize(path.join(__dirname, '..'));
|
||||||
const JASMINE_DIR = path.relative(
|
const JASMINE_DIR = path.relative(
|
||||||
@ -38,7 +35,6 @@ const items = fs.readdirSync(packageRoot);
|
|||||||
let chrome, protocol;
|
let chrome, protocol;
|
||||||
|
|
||||||
writeSpecRunner();
|
writeSpecRunner();
|
||||||
startStaticServer();
|
|
||||||
runTestsInChrome();
|
runTestsInChrome();
|
||||||
|
|
||||||
// ----------------------
|
// ----------------------
|
||||||
@ -85,49 +81,6 @@ function writeSpecRunner() {
|
|||||||
fs.writeFileSync(testPath, runnerText);
|
fs.writeFileSync(testPath, runnerText);
|
||||||
}
|
}
|
||||||
|
|
||||||
function startStaticServer() {
|
|
||||||
// An adaptation of https://gist.github.com/ryanflorence/701407
|
|
||||||
const server = http.createServer(function(request, response) {
|
|
||||||
var uri = url.parse(request.url).pathname,
|
|
||||||
filename = path.join(PORTFOLIO_DIR, uri);
|
|
||||||
|
|
||||||
fs.access(filename, fs.constants.R_OK, function(err) {
|
|
||||||
if (err) {
|
|
||||||
response.writeHead(404, { 'Content-Type': 'text/plain' });
|
|
||||||
response.write('404 Not Found\n');
|
|
||||||
response.end();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fs.statSync(filename).isDirectory()) filename += '/index.html';
|
|
||||||
|
|
||||||
fs.readFile(filename, 'binary', function(err, file) {
|
|
||||||
if (err) {
|
|
||||||
response.writeHead(500, { 'Content-Type': 'text/plain' });
|
|
||||||
response.write(err + '\n');
|
|
||||||
response.end();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
response.writeHead(200, {
|
|
||||||
'Content-Type': mime(filename)
|
|
||||||
});
|
|
||||||
response.write(file, 'binary');
|
|
||||||
response.end();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
server.on('error', e => {
|
|
||||||
if (e.code === 'EADDRINUSE') {
|
|
||||||
setTimeout(() => {
|
|
||||||
server.close();
|
|
||||||
server.listen(PORT, HOST);
|
|
||||||
}, 500);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
server.listen(parseInt(PORT, 10));
|
|
||||||
}
|
|
||||||
|
|
||||||
async function runTestsInChrome() {
|
async function runTestsInChrome() {
|
||||||
chrome = await launchChrome();
|
chrome = await launchChrome();
|
||||||
protocol = await CDP({
|
protocol = await CDP({
|
||||||
|
|||||||
@ -1,6 +1,12 @@
|
|||||||
version: '2'
|
version: '2'
|
||||||
|
|
||||||
services:
|
services:
|
||||||
|
test-web:
|
||||||
|
image: nginx:stable-alpine
|
||||||
|
ports:
|
||||||
|
- 8090:80
|
||||||
|
volumes:
|
||||||
|
- ./:/usr/share/nginx/html:ro
|
||||||
cloud9:
|
cloud9:
|
||||||
image: sapk/cloud9:latest
|
image: sapk/cloud9:latest
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
|||||||
@ -7,11 +7,12 @@
|
|||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"check_code_format": "nodejs node_modules/prettier/bin-prettier.js --config ./prettier.config.js --list-different \"{.,{packages,bin}/**/!(dist)}/*.{js,json,md}\"",
|
"check_code_format": "nodejs node_modules/prettier/bin-prettier.js --config ./prettier.config.js --list-different \"{.,{packages,bin}/**/!(dist)}/*.{js,json,md}\"",
|
||||||
"format_code": "nodejs node_modules/prettier/bin-prettier.js --config ./prettier.config.js --write \"{.,{packages,bin}/**/!(dist)}/*.{js,json,md}\""
|
"format_code": "nodejs node_modules/prettier/bin-prettier.js --config ./prettier.config.js --write \"{.,{packages,bin}/**/!(dist)}/*.{js,json,md}\"",
|
||||||
|
"pre-commit": "sh ./bin/pre-commit.sh"
|
||||||
},
|
},
|
||||||
"husky": {
|
"husky": {
|
||||||
"hooks": {
|
"hooks": {
|
||||||
"pre-commit": "sh ./bin/pre-commit.sh"
|
"pre-commit": "npm run pre-commit"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user