Tests

The tests in TALY are based on Jest.

1. Debugging Tests

1.1. Visual Studio Code

The Jest Runner extension makes it possible to directly execute the tests.

As an alternative, the following way can also be used:

A predefined configuration is available to debug tests in Visual Studio Code. Follow these steps:

  1. Open the tests file that should be debugged
  2. Set a breakpoint in the file
  3. Run the Jest Current File of specific project debugging target. Select the project where the test file resides, when prompted
  4. The tests are now started and will halt at the breakpoint

2. Profiling Tests

Sometimes, it might be interesting to take a closer look at certain performance aspects of code in tests. v8-profiler-next can be used to do profiling of Jest Tests.

For that, a test can be modified like this:

import { setGenerateType, startProfiling, stopProfiling } from 'v8-profiler-next';
import { writeFileSync } from 'fs';

setGenerateType(1);

describe('A Test', () => {
  startProfiling();

  afterAll(() => {
   const profile = stopProfiling();

    profile.export(function (error, result: any) {
      writeFileSync(`capture.cpuprofile`, result);
      profile.delete();
    });
  });
}

2.1. Why Can't I Use the Built in Profiling Functionalities of for Example VSCode?

At some point, in a not too distant past, the built in profiling of vscode could also be used for the tests. Unfortunately, this currently doesn't work, which is why the v8-profiler approach can be used.

I Want to Check If It Is Still Broken!

Of course, it might be that it was fixed at some point between these words being written and them being read again.

If you want to check on that, follow these steps:

  1. Set a breakpoint directly before the actual tests run. For example in beforeAll
  2. Add a breakpoint directly after they ran. For example in afterAll
  3. Run the tests. For example by following the description above
  4. When the first breakpoint is hit, start the profiling as it is also described in the vscode documentation
  5. When the second breakpoint is hit, save the profile. This is the part that is currently broken: the second breakpoint is never hit and therefore there is no chance to save the profile.

results matching ""

    No results matching ""