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 },
30 '--user-agent=Nominatim UI test suite Mozilla/5.0 Gecko/20100101 HeadlessChrome/90.0'
36 exports.mochaGlobalTeardown = async function () {
37 global.browser.close();
39 await this.server.stop();
40 console.log('server stopped');