1 const static_server = require('static-server');
2 const puppeteer = require('puppeteer');
3 const fse = require('fs-extra');
5 // Methods to run at the start and end of the mocha testsuite run
6 // https://mochajs.org/#global-setup-fixtures
8 exports.mochaGlobalSetup = async function () {
9 const workdir = 'dist_for_testing';
11 // 1. Prepare build directory
12 fse.mkdirpSync(workdir);
13 fse.copySync('dist', workdir);
15 fse.outputFile(workdir + '/theme/config.theme.js', `
16 Nominatim_Config.Nominatim_API_Endpoint = 'https:/nominatim.openstreetmap.org/';
19 // 2. Start webserver pointing to build directory
20 // https://github.com/nbluis/static-server#readme
21 this.server = new static_server({ port: 9999, rootPath: workdir });
22 await this.server.start();
23 console.log(`server running on port ${this.server.port}`);
25 // 3. Create browser instance
26 global.browser = await puppeteer.launch({
27 defaultViewport: { width: 1024, height: 768 },
33 exports.mochaGlobalTeardown = async function () {
34 global.browser.close();
36 await this.server.stop();
37 console.log('server stopped');