]> git.openstreetmap.org Git - nominatim-ui.git/blob - test/_bootstrap.js
bd3fd01b3abf56b1175630d28b85b6d4e6c911b4
[nominatim-ui.git] / test / _bootstrap.js
1 const static_server = require('static-server');
2 const puppeteer = require('puppeteer');
3 const fse = require('fs-extra');
4
5 // Methods to run at the start and end of the mocha testsuite run
6 // https://mochajs.org/#global-setup-fixtures
7
8 exports.mochaGlobalSetup = async function () {
9   const workdir = 'dist_for_testing';
10
11   // 1. Prepare build directory
12   fse.mkdirpSync(workdir);
13   fse.copySync('dist', workdir);
14
15   fse.outputFile(workdir + '/theme/config.theme.js', `
16 Nominatim_Config.Nominatim_API_Endpoint = 'https:/nominatim.openstreetmap.org/';
17   `);
18
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}`);
24
25   // 3. Create browser instance
26   global.browser = await puppeteer.launch({
27     defaultViewport: { width: 1024, height: 768 },
28     timeout: 5000
29   });
30 };
31
32
33 exports.mochaGlobalTeardown = async function () {
34   global.browser.close();
35
36   await this.server.stop();
37   console.log('server stopped');
38 };