getgauge/gauge-ts

Initialize ONCE when execute gauge with `-p`

Closed this issue · 1 comments

I posted same question in stackoverflow.

I use gauge and gauge-ts to test APIs with axios. In our project, when test runs, DB is initialized in @BeforeSuite. It was good enough.

Recently I'm trying to run gauge with -p flag, and DB initialize don't work well. @BeforeSuite runs many times(# of parallel streams), DB initialize runs in each, and initialize fails with message Duplicate entry '1000000' for key 'PRIMARY'.

How can I fix test codes and initialize once?

$ gauge -v                                    
Gauge version: 1.4.3
Plugins
-------
html-report (4.2.0)
js (2.4.0)
screenshot (0.1.0)
ts (0.1.0)
class testimpl {
  @BeforeSuite()
  public async setup() {
    // connect to local DB, clear old data, and insert default data
    await clearDB()
    await setupDB()
  }
}

I decided to work around this by inserting data for each spec file.

@BeforeSpec()
public async beforeSpec(ctx: ExecutionContext) {
    // Insert spec-file-specific data
    await setupDB(ctx.getCurrentSpec().getFileName());
}