microsoft / playwright-test

Build a cross-browser end-to-end test suite with Playwright.
https://playwright.dev
Apache License 2.0
777 stars 34 forks source link

setup/teardown #9

Closed JoelEinbinder closed 4 years ago

JoelEinbinder commented 4 years ago

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 commented 4 years ago

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.

mxschmitt commented 4 years ago

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

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');
  }
};