REserve — Testing UI5 — Building a platform

Defining and configuring a job

const job = {
cwd: process.cwd(),
port: 0,
ui5: 'https://ui5.sap.com/1.87.0',
webapp: 'webapp',
logServer: false
}
  • cwd : the current working directory, it is initialized with the process current one
  • port : the port used to serve the application (0 means REserve will allocate one)
  • ui5 : the base URL of the content delivery network to grab UI5 from
  • webapp : the webapp directory of the application to serve
  • logServer : enables REserve logs
process.argv.forEach(arg => {
const valueParsers = {
boolean: value => value === 'true',
number: value => parseInt(value, 10),
default: value => value
}
const parsed = /-(\w+):(.*)/.exec(arg)
if (parsed) {
const [, name, value] = parsed
if (Object.prototype.hasOwnProperty.call(job, name)) {
const valueParser = valueParsers[typeof job[name]] || valueParsers.default
job[name] = valueParser(value)
}
}
})
const { isAbsolute, join } = require('path')function toAbsolute (member, from = job.cwd) {
if (!isAbsolute(job[member])) {
job[member] = join(from, job[member])
}
}
toAbsolute('cwd', process.cwd())
toAbsolute('webapp')

Serving the application

  • UI5 resources
  • The project sources
const { join } = require('path')
const ui5 = require('./src/ui5')
const { check, log, serve } = require('reserve')
const job = require('./src/job')async function main () {
const configuration = await check({
port: job.port,
mappings: [
...ui5, {
// Project mapping
match: /^\/(.*)/,
file: join(job.webapp, '$1')
}]
})
const server = serve(configuration)
if (job.logServer) {
log(server)
}
server
.on('ready', async ({ url, port }) => {
job.port = port
if (!job.logServer) {
console.log(`Server running at ${url}`)
}
})
}
main()
'use strict'const job = require('./job')const mappings = [{
// UI5 from url
method: ['GET', 'HEAD'],
match: /\/((?:test-)?resources\/.*)/,
url: `${job.ui5}/$1`
}]
module.exports = mappings

Spawning a browser

  • browser : the path of a Node.js script that is responsible of starting the browser. By default, a script leveraging puppeteer is provided.
  • args : parameters for the script. Two tokens can be used to inject specific values :
  • __URL__ : contains the URL of the test page to execute
  • __REPORT__ : contains the path to a folder where the script can save additional information related to the test execution (such as console logs or screenshots)
  • start (relativeUrl)
  • stop (relativeURl)

Defining an endpoint

const { body } = require('reserve')function endpoint (implementation) {
return async function (request, response) {
response.writeHead(200)
response.end()
const [, url] = request.headers.referer.match(/http:\/\/[^/]+(?::\d+)?(\/.*)/)
const data = JSON.parse(await body(request))
try {
await implementation.call(this, url, data)
} catch (e) {
console.error(`Exception when processing ${url}`)
console.error(data)
console.error(e)
}
}
}

Next step

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store