runner.mjs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import process from 'node:process'
  2. import waitOn from 'wait-on'
  3. import { spawn } from 'node:child_process'
  4. let ot = null
  5. export default function getRunner () {
  6. const type = process.env.OLIVETIN_TEST_RUNNER
  7. console.log('OLIVETIN_TEST_RUNNER env value is: ', type)
  8. switch (type) {
  9. case 'local':
  10. return new OliveTinTestRunnerLocalProcess()
  11. case 'vm':
  12. return null
  13. case 'container':
  14. return null
  15. default:
  16. return new OliveTinTestRunnerLocalProcess()
  17. }
  18. }
  19. class OliveTinTestRunnerLocalProcess {
  20. async start (cfg) {
  21. ot = spawn('./../OliveTin', ['-configdir', 'configs/' + cfg + '/'])
  22. const logStdout = process.env.OLIVETIN_TEST_RUNNER_LOG_STDOUT === '1'
  23. if (logStdout) {
  24. ot.stdout.on('data', (data) => {
  25. console.log(`stdout: ${data}`)
  26. })
  27. ot.stderr.on('data', (data) => {
  28. console.error(`stderr: ${data}`)
  29. })
  30. }
  31. ot.on('close', (code) => {
  32. if (code != null) {
  33. console.log(`child process exited with code ${code}`)
  34. }
  35. })
  36. /*
  37. this.server = await startSomeServer({port: process.env.TEST_PORT});
  38. console.log(`server running on port ${this.server.port}`);
  39. */
  40. await waitOn({
  41. 'resources': ['http://localhost:1337/']
  42. })
  43. return ot
  44. }
  45. async stop () {
  46. await ot.kill()
  47. }
  48. }