AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Jest webstorm debug8/25/2023 The set of Jest projects within Nx workspaces tends to change. This configuration allows editor/IDE integrations to pick up individual project's configurations rather than the one at the root. The root level file configures Jest multi project support. Primary configurations for Jest will be via the file that generated for your project. Using the -runInBand flag tells jest to run in a single process. This is because each jest process creates a workers based on system resources, running multiple projects via nx and using jest workers will create too many process overall causing the system to run slower than desired. Typically, in CI it's recommended to use nx affected -t test -parallel= -runInBand for the best performance. Make sure to use localhost for the host and 9229 for the port.Snapshot files should be checked in with your code. It would take too long to list out the instructions for each editor, so here are links to some popular ones: Try running this command, wait for tests to execute the first time, then change sum.js or and see what happens. Like test-debug, this will start the container and wait for a debugger to be attached on port 9229, then execute the tests, but then it also watches for file changes and re-runs all tests when something changes. -v "$(pwd):/usr/src/app" to mount the local host directory in the container so that file changes are visible in the container.-it to be able to interact with the process, to control Jest.The -watchAll flag for Jest requires some additional Docker flags: docker run -it -v " $(pwd):/usr/src/app" -p 9229:9229 sum npm run test-watch-debug This will start the container and wait for a debugger to be attached on port 9229, then execute the tests. npm run test-debug to run our test command.This is necessary to attach your IDE or browser to the remote node instance. -p 9229:9229 to map the remote port 9229 to the local port 9229.docker run to run a command in an already built image.To run test-debug we have a fairly short command: docker run -p 9229:9229 sum npm run test-debug Then we'll walk through the different Docker commands that change depending on which testing command we want. įirst, build the container and tag it as sum: docker build -t sum. This is required for debugging the tests -watchAll runs after file changes.Īfter creating those 5 files you will end up with the directory tree. -runInBand causes all tests to be run in the parent process rather than child processes.-watchAll watches for file changes and re-runs all tests when something changes.node_modules/jest/bin/jest.js -watchAll -runInBand Test-watch-debug node -inspect-brk=0.0.0.0. node_modules/jest/bin/jest.js runs Jest just like it would with the jest command. The 0.0.0.0 IP means bind to all interfaces which is required for Docker networking. We're having node wait because the test will likely execute too fast for us to attach to it. -inspect-brk will wait for a remote debugger to attach before executing the code.The jest command doesn't provide a way to turn on the inspector. node is required in order to enable -inspect-brk. Now let's walk through each of those debug commands. Using the examples from Jest's " Getting Started ," create sum.js: function sum( a, b) Let's walk through creating the files necessary to demonstrate the remote debugging. Turns out it's pretty easy when you have the right flags. I ran into the need to debug Jest tests running inside a Docker container recently and didn't find any clear instructions on how to do it.
0 Comments
Read More
Leave a Reply. |