const config = require('./support/config');
const { setWorldConstructor } = require('@cucumber/cucumber');
const puppeteer = require('puppeteer');
const scope = require('./support/scope');

const express = require('express');
const httpShutdown = require('http-shutdown');
const path = require('path');
const app = express();

app.use(express.static(path.join(__dirname, '..', 'build')));

app.get('/', (req, res)=> {
    res.sendFile(path.join(__dirname, '..', 'build', 'index.html'));
})

const web = httpShutdown(app.listen(config.port, () => {
    console.log(`Web is listening on port ${config.port}`);
}));

web.host = `http://localhost:${config.port}`;

const World = function () {
    scope.host = web.host;
    scope.driver = puppeteer;
    scope.context = {};
    scope.web = web;
};

setWorldConstructor(World);