X-Git-Url: https://git.openstreetmap.org./nominatim-ui.git/blobdiff_plain/61e0c9318d8f48915877e6985a46f57ec6d43b83..2ba00544d30017ad30570011b1a2bcc6a8da73a7:/test/_bootstrap.js diff --git a/test/_bootstrap.js b/test/_bootstrap.js index c74de5b..e608d2b 100644 --- a/test/_bootstrap.js +++ b/test/_bootstrap.js @@ -1,23 +1,23 @@ -const static_server = require('static-server'); -const http = require('http'); -const httpProxy = require('http-proxy'); -const puppeteer = require('puppeteer'); -const fse = require('fs-extra'); +import static_server from 'static-server'; +import http from 'node:http'; +import httpProxy from 'http-proxy'; +import puppeteer from 'puppeteer'; +import fse from 'fs-extra'; const testing_port = 9999; // this is the port all tests expect nominatim-ui to listen to // The installation on https://nominatim.openstreetmap.org/ui/ is a bit more complex as -// for backward compatiblity they run the API and the UI on the same port. Nominatim-UI +// for backward compatibility they run the API and the UI on the same port. Nominatim-UI // is installed in the /ui subdirectory plus their webserver has custom redirect rules. // // We can simulate that with a proxy. const use_proxy = !!process.env.API_ON_SAME_PORT; const static_port = use_proxy ? 9998 : 9999; - +const reverse_only = !!process.env.REVERSE_ONLY; // Methods to run at the start and end of the mocha testsuite run // https://mochajs.org/#global-setup-fixtures -exports.mochaGlobalSetup = async function () { +export async function mochaGlobalSetup() { const workdir = 'dist_for_testing'; // 1. Prepare build directory @@ -28,6 +28,7 @@ exports.mochaGlobalSetup = async function () { fse.outputFile(workdir + '/theme/config.theme.js', ` Nominatim_Config.Nominatim_API_Endpoint = '${api_endpoint}'; +Nominatim_Config.Reverse_Only = ${reverse_only}; `); @@ -48,7 +49,7 @@ Nominatim_Config.Nominatim_API_Endpoint = '${api_endpoint}'; let api_url_match = req.url.match(/\/(\w+\.php)/); let target = api_url_match - ? 'http://nominatim.openstreetmap.org/' + api_url_match[1] + ? 'https://nominatim.openstreetmap.org' : 'http://localhost:' + static_port; // console.log(`http proxy ${req.url} => ${target + req.url}`) @@ -61,16 +62,17 @@ Nominatim_Config.Nominatim_API_Endpoint = '${api_endpoint}'; // 3. Create browser instance global.browser = await puppeteer.launch({ defaultViewport: { width: 1024, height: 768 }, - timeout: 10000, + timeout: 20000, // latency: 1000, + headless: 'new', args: [ '--user-agent=Nominatim UI test suite Mozilla/5.0 Gecko/20100101 HeadlessChrome/90.0' ] }); -}; +} -exports.mochaGlobalTeardown = async function () { +export async function mochaGlobalTeardown() { global.browser.close(); await this.static_http_server.stop(); @@ -82,4 +84,4 @@ exports.mochaGlobalTeardown = async function () { this.proxy_server.close(() => console.log('proxy server stopped')); } -}; +}