Skip to content

Commit

Permalink
feat(e2e): first test with @ui5/cli
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudBuchholz committed Apr 11, 2024
1 parent 6eb7450 commit a4d7973
Showing 1 changed file with 42 additions and 20 deletions.
62 changes: 42 additions & 20 deletions test/e2e.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const { fork } = require('child_process')
const { fork, spawn } = require('child_process')
const { join } = require('path')
const assert = require('assert/strict')
const { stat } = require('fs/promises')
Expand All @@ -11,7 +11,7 @@ const { getOutput, newProgress } = require('../src/output')
const { $statusProgressCount, $statusProgressTotal } = require('../src/symbols')

const root = join(__dirname, '..')
const [,, only] = process.argv
const [node,, only] = process.argv
if (only) {
process.env.E2E_ONLY = only
}
Expand All @@ -23,6 +23,31 @@ const coverage = () => async job => {
assert.strictEqual((await stat(join(coverageReportDir, 'lcov-report/index.html'))).isFile(), true, 'Coverage HTML report exists')
}

const ui5Serve = () => {
if (!ui5Serve.promise) {
ui5Serve.promise = new Promise((resolve, reject) => {
const ui5 = join(root, 'node_modules/@ui5/cli/bin/ui5.cjs')
spawn(
node,
[ui5, 'serve', '--config', join(root, 'test/sample.js/ui5.yaml')],
{
stdio: [0, 'pipe', 'pipe']
}
)
const waitForServer = async () => {
try {
await fetch('http://localhost:8080')
resolve()
} catch (e) {
setTimeout(waitForServer, 250)
}
}
waitForServer()
})
}
return ui5Serve.promise
}

let port = 8080

const tests = [{
Expand All @@ -45,42 +70,36 @@ const tests = [{
id: 'JS_LEGACY',
label: 'Legacy JS Sample',
utr: ['--cwd', join(root, './test/sample.js')],
tests: [
qunitPages(2)
]
tests: [qunitPages(2)]
}, {
id: 'JS_LEGACY_SPLIT',
label: 'Legacy JS Sample with OPA split',
utr: ['--cwd', join(root, './test/sample.js'), '--split-opa'],
tests: [
qunitPages(3)
]
tests: [qunitPages(3)]
}, {
id: 'JS_LEGACY_COVERAGE',
label: 'Legacy JS Sample with coverage',
utr: ['--cwd', join(root, './test/sample.js'), ...'--coverage --coverage-settings nyc.json --coverage-check-statements 67'.split(' ')],
tests: [
qunitPages(2),
coverage()
]
tests: [qunitPages(2), coverage()]
}, {
id: 'JS_LEGACY_REMOTE',
label: 'Legacy JS Sample accessed using --url',
utr: ['--cwd', join(root, './test/sample.js'), '--port', ++port, '--url', `http://localhost:${port}/test/testsuite.qunit.html`],
tests: [
qunitPages(2)
]
tests: [qunitPages(2)]
}, {
id: 'JS_LEGACY_REMOTE_COVERAGE',
label: 'Legacy JS Sample accessed using --url with coverage',
utr: [
'--cwd', join(root, './test/sample.js'), '--port', ++port, '--url', `http://localhost:${port}/test/testsuite.qunit.html`,
...'--coverage --coverage-settings nyc.json --coverage-check-statements 67'.split(' ')
],
tests: [
qunitPages(2),
coverage()
]
tests: [qunitPages(2), coverage()]
}, {
id: 'JS_REMOTE',
label: 'Remote JS',
before: ui5Serve,
utr: '--url http://localhost:8080/test/testsuite.qunit.html',
tests: [qunitPages(2)]
}].filter(({ id }) => {
if (process.env.E2E_ONLY) {
return id === process.env.E2E_ONLY
Expand All @@ -96,12 +115,15 @@ const job = {
}
const output = getOutput(job)

async function test ({ label, utr, tests }) {
async function test ({ before, label, utr, tests }) {
const progress = newProgress(job)
const id = filename(label)
const reportDir = join(root, 'e2e', id)
progress.label = `${label} (${id})`
progress.count = 1
if (before) {
await before()
}
const { promise, resolve, reject } = allocPromise()
const parameters = [
'--report-dir', reportDir,
Expand Down

0 comments on commit a4d7973

Please sign in to comment.