colinbes
colinbes

Reputation: 457

re-initialize global configuration when rerunning TestCafe test in live mode

When using TestCafe in live mode (not using live runner) when it runs on detecting code change it doesn't reload my global variables.

In my test code I have a config page that I use to setup initial state for test and during test I modify this configuration so that I can track and check for expected changes.

For example I have something along lines of:

ConfigPage = {
  description: 'some description'
}

In my test code, along the way I want to do something like

ConfigPage.description = ConfigPage.description+' add to description'

This words, but not on live re-run. If live re-run is triggered, on start of test ConfigPage.description now has 'some description add to description' and not 'some description'

My ConfigPage file is a TypeScript class:

class ConfigurationPage {
  description: string
  constructor () {
    this.description = 'some description'
  }
}

export ConfigPage = new ConfigurationPage()

Upvotes: 0

Views: 92

Answers (1)

Dmitry Ostashev
Dmitry Ostashev

Reputation: 2348

Your ConfigPage file is imported from the cache on the test re-run if it wasn't modified. So the ConfigurationPage object is instantiated only once and exported as a constant. If you change this file, the test will re-run with the result you expect.

Upvotes: 1

Related Questions