service-core/test/core.test.integration.mjs
Jonatan Nilsson 4f4bc8cf6a
All checks were successful
continuous-integration/appveyor/branch AppVeyor build succeeded
More core development, full integration started
2022-02-11 13:59:10 +00:00

70 lines
1.8 KiB
JavaScript

import { Eltro as t, assert} from 'eltro'
import fs from 'fs/promises'
import http from 'http'
import Util from '../core/util.mjs'
import { request } from '../core/client.mjs'
const util = new Util(import.meta.url)
const port = 61412
const defaultHandler = function(req, res) {
res.statusCode = 200
res.end('{"a":1}');
}
let server = null
let prefix = `http://localhost:${port}/`
let handler = defaultHandler
let files = []
let logs = []
t.describe('', function() {
t.before(function(cb) {
server = http.createServer(function(req, res) {
req.on('error', function(err) {
console.log('error', err)
})
res.on('error', function(err) {
console.log('error', err)
})
handler(req, res)
})
server.listen(port, cb)
})
t.after(function() {
return Promise.resolve()
return Promise.all(files.map(function(file) {
return fs.rm(file, { force: true, recursive: true })
}))
})
const stable_version_1 = `
export function start(http, port, ctx) {
const server = http.createServer(function (req, res) {
res.writeHead(200);
res.end(JSON.stringify({ version: 'stable_version_1' }))
})
return server.listenAsync(port, '0.0.0.0')
.then(() => {
ctx.log.info(\`Server is listening on \${port} serving stable_version_1\`)
})
}
`
function file(relative) {
let file = util.getPathFromRoot(relative)
files.push(file)
return file
}
function log(message) {
logs.push(message)
console.log(message)
}
t.test('should be fully operational', async function() {
let index = file('./index.mjs')
await fs.writeFile(index, stable_version_1)
await util.runCommand(util.get7zipExecutable(), ['a', file('./v1.7z'), index], util.getPathFromRoot('./testapp/'), log)
})
})