Skip to content
This repository has been archived by the owner on Jun 11, 2021. It is now read-only.

setup/teardown #9

Closed
JoelEinbinder opened this issue Apr 18, 2020 · 2 comments
Closed

setup/teardown #9

JoelEinbinder opened this issue Apr 18, 2020 · 2 comments

Comments

@JoelEinbinder
Copy link
Contributor

We should have hooks for setting up some test servers or other long running processes when the test run starts and shutting them down when the test run ends. I believe jest already has apis for this, but its a question of integrating with them.

@mxschmitt
Copy link
Member

We had a discussion going on about forking jest-dev-server and rewriting it since its not maintained anymore actively.

It would be cool to have especially with device / browser enumeration a way of executing commands before and after for e.g. setting up a database and cleaning it up afterwards.

Additional to that it would be nice to have jest-dev-server functionality, either integrated or providing support for it so we could start e.g. a backend or the frontend with it.

@jperl jperl mentioned this issue Apr 27, 2020
@mxschmitt
Copy link
Member

mxschmitt commented May 1, 2020

Probably it does not make much sense to use jest-dev-server there. I thought about the following:

  • startup/teardown hooks in the playwright.config
  • startup/teardown hooks if you test multiple browsers
  • There you can basically implement your own customisable async function to use e.g. that: https://www.npmjs.com/package/wait-on or execute shell commands (maybe provide a small helper for that)

e.g.

const waitOn = require('wait-on');

module.exports = {
  browsers: ['chromium', 'webkit'],
  contextOptions: {
    viewport: {
      width: 1234,
      height: 789,
    },
  },
  setup: async (state, { execCommand, runInBackground }) => {
    await execCommand('createdb foobar');
    // start the backend
    runInBackground('python manage.py runserver');
    runInBackground('nginx -d');
    // Wait until its reachable
    await waitOn({
      resources: 'http://localhost:8080'
    });
  },
  teardown: async (state, { execCommand, killBackgroundProcesses }) => {
    await killBackgroundProcesses();
    await execCommand('dropdb foobar');
  }
};

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants