Giter Club home page Giter Club logo

Comments (4)

ijpiantanida avatar ijpiantanida commented on June 19, 2024 1

I extended the examples to show how you can do this in a few ways.

Starting talkback in a separate process than the tests (what you are already doing)

You can continue using the single line command.

node tapesServer.js & TALKBACK_PID=$! && sleep 1 && yarn test && kill $TALKBACK_PID

Note that you don't need to send a SIGKILL. Talkback handles SIGTERM (kill -15 or just kill) and shutdowns gracefully.
Also it's probably a good idea to give talkback some time (sleep 1) to initialize before running the tests.

I'm using the once liner in this example.

You could put it as the definition of yarn test in your package.json, or alternatively, you could create a test.sh script, put the commands there instead of the long one-liner and then have yarn test just call the script.

Let the test runner start/stop talkback

There are many ways in which you can do this, depending on what your test runner allows.

  • A global beforeAll. See this mocha example.
  • A beforeAll/afterAll in each test where you need talkback. See this Jest example.

Personally, I prefer the second option since it plays nicely with IDEs running the tests as they start all the context that they require by themselves.

Hopefully, this helps you.

from talkback.

ijpiantanida avatar ijpiantanida commented on June 19, 2024

Hi @denislutz, how is your CI server starting talkback and the tests?

from talkback.

denislutz avatar denislutz commented on June 19, 2024

Hi I have a file tapesServer.js

const opts = {
  host,
  port,
  path: `${__dirname}/tapes`,
  record,
  fallbackMode: (req) => {
    console.warn(`Tape NOT FOUND for request: ${req.method} ${req.url} ${req.body ? req.body.toString() : 'no body'}`)
    return talkback.Options.FallbackMode.NOT_FOUND
  },
  // urlMatcher,
  // bodyMatcher,
  ignoreHeaders,
  tapeNameGenerator,
}
const localServer = talkback(opts)
localServer.start()

module.exports = async () => {
  global.__MY_LOCAL_SERVER = localServer
}

Usually I would start the tapes in a separate terminal and the run 'yarn test' in another on. Then when I am done testing just kill it by hand.

For the CI I then do all in one command. Something like:

yarn node tapesServer.js & yarn test && kill -9 $(lsof -t -i:$TAPES_PORT) || true

This works in general but its not very clean, since I am killing it in a hard way, besides this I would like to have one command locally to offer it to new developers who dont know abouth the whole tapes setup and just want to run one command 'yarn test'.

So the final question is, how can I
a) reference the running server from some other script that would stop it?
b) Maybe start and stop it out of jest?

from talkback.

denislutz avatar denislutz commented on June 19, 2024

Thanks so much, let my try it all out.

from talkback.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.