Debug jest tests

Source: https://stackoverflow.com/a/63909711

You do not need Chrome for Jest tests.

The simplest solution I found is to use VS Code JavaScript Debug Terminal.

And it works with Typescript and Nrvl.Nx work-spaces out of the box.

  1. Open the command palette and start Debug: JavaScript Debug Terminal:
enter image description here
  1. Run tests in that terminal in a Watch mode npm test -- --watch. (or yarn test --watch if you are using yarn)
  2. Set a break-point in your file.
  3. Make any change in a file you want to debug and save.
  4. watch will run Jest tests against modified files.

When you want to narrow down the number of files run by the –watch, press p in the terminal and enter a pattern, which is just a part of the file name you want to test and hit [Enter]

To limit it to a single test in a file – focus it with f, so change it(…) to fit(…)

xUnit MemberData only returns one test

I found this issue when the test data is very large (some large JSON and GraphQL query strings). For some reason MemberData only generates one test, probably some limitation or an edge case that xUnit does not handle.

In this case, the way to solve this problem is to generate a very small test parameter, and then in the test run the generation code to create other test values. Then xUnit will work correctly.

Cannot connect to MSSQL database from .NET 6 application

If you encounter SSL error when a .NET 6 application tries to connect to the MSSQL database

Microsoft.Data.SqlClient.SqlException : A connection was successfully established with the server, but then an error occurred during the login process. (provider: SSL Provider, error: 0 – The certificate chain was issued by an authority that is not trusted.)
System.ComponentModel.Win32Exception : The certificate chain was issued by an authority that is not trusted.

Not sure why, it might be that the new libraries are more strict regarding security. A workaround is to add TrustServerCertificate=True to the connection string.

Cannot restore internal NuGet packages

When working with projects that has dependencies on an internal NuGet registry, you may need add credentials for the internal registry so that NuGet can fetch the packages.

If you restore in Visual Studio, it’s possible that VS will ask you to provide credentials (not yet tested).

If you try to restore or build using the command line, it may fail with unauthorized error.

To resolve, modify nuget.config file, either in the same folder of the solution file, or modify the global nuget.config file.

<packageSourceCredentials>
<MyPrivateNugetRegistry>
<add key=”Username” value=”Your username here” />
<add key=”ClearTextPassword” value=”your password/access token here” />
</MyPrivateNugetRegistry>
</packageSourceCredentials>

ApiController attribute magic

While working with ASP.NET Core, I find that the [ApiController] attribute does a lot of magic to my controller.

https://docs.microsoft.com/en-us/aspnet/core/web-api/?view=aspnetcore-3.1#apicontroller-attribute

It will automatically throws 400 bad request error back to the client, parse the service model from the request payload, and a bunch of other things.

I’m still not sure how model binding works without this attribute, maybe I would have to decorate the service with binding attributes for it to work.

Creating Domain controller and joining domain in VirtualBox

Make sure you use Host-Only network adapters for both DC and guest machines, Host-Only network adapter provides DHCP and DNS service.

If you’re using internal network, either configure your own DHCP or set static IP addresses.

Configure the DC also as a DNS server, so that it can resolve domain name to IP address when query. If not, register the DC to the DNS server.

If the DC is also a DNS server, set its IP address to the network adapter of member machines, so those machines can find the DC to join domain.

Make sure ports are allowed in firewall settings.