2018-02-21 05:31:27 +01:00
|
|
|
/* eslint-disable no-undef, no-process-exit */
|
|
|
|
const fs = require('fs');
|
|
|
|
const path = require('path');
|
|
|
|
const mkdirp = require('mkdirp');
|
|
|
|
const puppeteer = require('puppeteer');
|
|
|
|
const webpack = require('webpack');
|
|
|
|
const config = require('../../webpack.config');
|
|
|
|
const middleware = require('webpack-dev-middleware');
|
|
|
|
const express = require('express');
|
2018-06-22 22:32:24 +02:00
|
|
|
const devRoutes = require('../../server/bin/test');
|
2018-02-21 05:31:27 +01:00
|
|
|
const app = express();
|
|
|
|
|
2018-07-23 18:49:16 +02:00
|
|
|
const wpm = middleware(webpack(config(null, { mode: 'development' })), {
|
|
|
|
logLevel: 'silent'
|
|
|
|
});
|
2018-02-21 05:31:27 +01:00
|
|
|
app.use(wpm);
|
|
|
|
devRoutes(app, { middleware: wpm });
|
|
|
|
|
2018-10-05 18:52:00 +02:00
|
|
|
// eslint-disable-next-line no-unused-vars
|
2018-02-21 05:31:27 +01:00
|
|
|
function onConsole(msg) {
|
2018-10-05 18:52:00 +02:00
|
|
|
// uncomment to debug
|
|
|
|
// console.error(msg.text());
|
2018-02-21 05:31:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const server = app.listen(async function() {
|
|
|
|
let exitCode = -1;
|
2018-12-19 21:25:05 +01:00
|
|
|
const browser = await puppeteer.launch({
|
|
|
|
args: [
|
|
|
|
// puppeteer >= 1.10.0 crashes on Circle CI without this flag set
|
|
|
|
'--no-sandbox'
|
|
|
|
]
|
|
|
|
});
|
2018-02-21 05:31:27 +01:00
|
|
|
try {
|
|
|
|
const page = await browser.newPage();
|
|
|
|
page.on('console', onConsole);
|
|
|
|
page.on('pageerror', console.log.bind(console));
|
2020-10-16 16:05:51 +02:00
|
|
|
await page.setDefaultNavigationTimeout(60000);
|
2018-02-21 05:31:27 +01:00
|
|
|
await page.goto(`http://127.0.0.1:${server.address().port}/test`);
|
|
|
|
await page.waitFor(() => typeof runner.testResults !== 'undefined', {
|
2018-07-23 18:49:16 +02:00
|
|
|
polling: 1000,
|
|
|
|
timeout: 15000
|
2018-02-21 05:31:27 +01:00
|
|
|
});
|
|
|
|
const results = await page.evaluate(() => runner.testResults);
|
|
|
|
const coverage = await page.evaluate(() => __coverage__);
|
|
|
|
if (coverage) {
|
|
|
|
const dir = path.resolve(__dirname, '../../.nyc_output');
|
|
|
|
mkdirp.sync(dir);
|
|
|
|
fs.writeFileSync(
|
|
|
|
path.resolve(dir, 'frontend.json'),
|
|
|
|
JSON.stringify(coverage)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
const stats = results.stats;
|
|
|
|
exitCode = stats.failures;
|
|
|
|
console.log(`${stats.passes} passing (${stats.duration}ms)\n`);
|
|
|
|
if (stats.failures) {
|
|
|
|
console.log('Failures:\n');
|
|
|
|
for (const f of results.failures) {
|
|
|
|
console.log(`${f.fullTitle}`);
|
|
|
|
console.log(` ${f.err.stack}\n`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
console.log(e);
|
|
|
|
} finally {
|
|
|
|
browser.close();
|
|
|
|
server.close(() => {
|
|
|
|
process.exit(exitCode);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|