Choices/server.js
Konstantin Vyatkin dddba5b35b [TEST] Automatic screenshots comparing and error checking in IE11, Firefox and Chrome (#715)
* taking screenshots

* let's try

* save artifacts

* better exceptiosn

* try to install geskodriver

* fix edge name

* add check for safari

* check os

* try this

* again

* fix syntax

* try this

* try firefox on windows

* and again

* handle error

* and again

* try older macos

* add firefox screenshot

* switch back env

* switch back env

* add IE screenshot

* try sudo for safari

* try not install nuget

* try more

* more

* try this

* install firefox

* add chrome

* increase threshold

* add firefox-darwin

* push

* fixing

* let's go

* increase threeshold

* again

* try safari tp

* tap cask versions

* fix conditions

* try like this

* last run

* increase threshold

* reenable macos firefox

* last try for safari

* rename screenshots to snapshots

* check console

* console workarounds

* fix safari misspleings

* logging is not supported by everyone

* maximize and set rect

* errors only for Chrome

* remove safari for now

* try to decrease threshold

* cleanup

* increase threeshold

* sleep more and increase threeshold

* add pupeeter

* handle errors

* build

* add prettier end of line

* add gitattributes

* add png to binary

* more attributest

* limit run

* run on chages to snapshots

* hey!

* make artifacts named as snapshots

* just for fun: we don't need express here

* update pupeeter snapshot

* no audit

* don't wait for quit?

* try more IE capabilities

* add wait timeout

* use server.js
2019-11-02 11:18:19 +00:00

75 lines
1.8 KiB
JavaScript

/* eslint-disable no-console,global-require,import/no-extraneous-dependencies */
const express = require('express');
const path = require('path');
const PORT = process.env.PORT || 3001;
const DIST_DIR = path.resolve(__dirname, 'public');
const app = express();
if (process.env.NODE_ENV !== 'production') {
const webpack = require('webpack');
const webpackDevMiddleware = require('webpack-dev-middleware');
const webpackHotMiddleware = require('webpack-hot-middleware');
const config = require('./webpack.config.dev');
console.log('Compiling bundle... 👷🏽');
const compiler = webpack(config);
app.use(
webpackDevMiddleware(compiler, {
publicPath: '/assets/scripts/',
stats: {
colors: true,
},
}),
);
app.use(webpackHotMiddleware(compiler));
app.get('/data', (req, res) => {
// prevent endpoint from being cached
res.header('Cache-Control', 'private, no-cache, no-store, must-revalidate');
res.header('Expires', '-1');
res.header('Pragma', 'no-cache');
const fakeData = [...new Array(50)].map((_, index) => ({
label: `Label ${index + 1}`,
value: `Value ${index + 1}`,
}));
setTimeout(() => {
res.status(200).send(fakeData);
}, 1000);
});
}
app.use(express.static(DIST_DIR));
const server = app.listen(PORT, err => {
if (err) {
console.log(err);
}
console.log(`Listening at http://localhost:${server.address().port} 👂`);
});
process.on('SIGTERM', () => {
console.log('Shutting down server');
if (server) {
server.close(err => {
if (err) {
console.log('Failed to shut down server');
process.exit(1);
}
console.log('Shut down server');
process.exit(0);
});
} else {
process.exit(0);
}
});
module.exports = server;