Today I Learned

9 posts by szymonkieloch

Impact of TYPEORM_CONNECTION on ormconfig in TypeOrm

When TypeOrm detects that either TYPEORM_CONNECTION or TYPEORM_URL env variables are set up, it will read the config from the env variables and ignore the one that is given by the ormconfig.js file:

// try to find connection options from any of available sources of configuration
if (PlatformTools.getEnvVariable("TYPEORM_CONNECTION") || PlatformTools.getEnvVariable("TYPEORM_URL")) {
   connectionOptions = await new ConnectionOptionsEnvReader().read();

From their docs:

Sometimes, you may want to use multiple configurations using different formats. When calling getConnectionOptions() or attempting to use createConnection() without the connection options, Typeorm will attempt to load the configurations, in this order:

  • From the environment variables. Typeorm will attempt to load the .env file using dotEnv if it exists. If the environment variables TYPEORM_CONNECTION or TYPEORM_URL are set, Typeorm will use this method.
  • From the ormconfig.env.
  • From the other ormconfig.[format] files, in this order: [js, ts, json, yml, yaml, xml].

Tip for the future: to use the ormconfig.js file, do not set up the TYPEORM_CONNECTION and TYPEORM_URL env vars.

Resolving "Nest can't resolve dependencies of the X"

From time to time you can see the error:

Nest can’t resolve dependencies of the X. Please make sure that the “Y” property is available in the current context.

In case of services:

  • Ensure the service is exposed in the module
  • Ensure the module exposing the service is included in the module
  • In tests: ensure the service is provided in the createTestingModule function
  • Check for circular dependencies; if you think there is one, use forwardRef in the place where the service is injected: @Inject(forwardRef(() => UserService)) private readonly userService: UserService

Issue with double quoted chars from terraform output

Sometime ago I noticed terraform outputs an error when running a make command:

╰─$ `terraform output gcloud_connection_command`
zsh: command not found: "gcloud

As it appeared, since the 0.14.0 version, terraform changed the way output formats the response. Since that release, terraform adds double back quotes around the returned text:

╰─$ terraform output gcloud_connection_command                                                                                                                                               
"gcloud container clusters get-credentials tilcra-staging-cluster --project tilcra --zone europe-west3-c"

To get back to the old output, add -raw flag to the command:

╰─$ terraform output -raw gcloud_connection_command
gcloud container clusters get-credentials tilcra-staging-cluster --project tilcra --zone europe-west3-

Loading React & Redux dev tools in Cypress

Install webpack plugin: npm install --save-dev react-dev-tools-iframe-webpack-plugin

Update webpack config to enable the react dev tools iframe:

const ReactDevToolsIFramePlugin = require('react-dev-tools-iframe-webpack-plugin');

plugins: [
  // other plugins,
  new ReactDevToolsIFramePlugin(),

Update cypress plugins to load React & Redux dev tools for chrome. Add the paths to these extensions in a comma-separated string:

module.exports = (on, config) => {
  on('before:browser:launch', (browser = {}, args) => {
    if ( === 'chrome') {
      return args;
    return null;

Here’s a post where you can find out where the extensions are.

Delete all local branches except the current one

From time to time it is necessary to delete all local branches. Assuming there are branches:

git branch --verbose

  a             2eb734f6 Update image tag
  b             2eb734f6 Update image tag
  first-branch  2eb734f6 Update image tag
  second-branch 2eb734f6 Update image tag
* staging       2eb734f6 Update image tag

This command will delete all branches except the current one:

git branch | grep -v `git symbolic-ref -q --short HEAD` | xargs git branch -D
Deleted branch a (was 2eb734f6).
Deleted branch b (was 2eb734f6).
Deleted branch first-branch (was 2eb734f6).
Deleted branch second-branch (was 2eb734f6).

An alias is handy:

alias gdal="git branch | grep -v `git symbolic-ref -q --short HEAD` | xargs git branch -D"

Waiting for content to be expanded in Cypress tests

When testing in Cypress, sometimes there are cases that content within accordion needs to be verified. The challenge is that sometimes, Cypress displays an error that an element is not yet visible, but it is on the page. A simple solution could be to wait for the element to be visible:

cy.contains('Text within the accordion')

One downside of this approach is that if there are more elements in the accordion, the last one should be check for visibility. Otherwise, Cypress will not wait for expanding the whole accordion and will proceed further with tests, e.g. trying to click an element that is not visible and hidden within the accordion.

An alternative approach to resolve the issue with the expanded accordions is to check its height and wait till it reaches a certain height:

  .should('', 700);