]> git.openstreetmap.org Git - nominatim-ui.git/blob - test/_bootstrap.js
Feat: Added user-agent to puppeteer (#135)
[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     args: [
30       '--user-agent=Nominatim UI test suite Mozilla/5.0 Gecko/20100101 HeadlessChrome/90.0'
31     ]
32   });
33 };
34
35
36 exports.mochaGlobalTeardown = async function () {
37   global.browser.close();
38
39   await this.server.stop();
40   console.log('server stopped');
41 };