testomatio / reporter

Testomatio Reporter
127 stars 22 forks source link

[mocha] Adding global.testomatioArtifacts doesn't work with mocha native parallel test run #77

Closed KhyzhniakAlex closed 9 months ago

KhyzhniakAlex commented 1 year ago

[mocha + TS] Adding test's artifacts via global variable testomatioArtifacts doesn't work when run tests by native parallel mocha run (https://docs.testomat.io/usage/test-artifacts/#nodejs-reporter)

Steps to reproduce the behavior:

  1. There should be S3 bucket connected to tests by env variables (TESTOMATIO_PRIVATE_ARTIFACTS=1, S3_ACCESS_KEY_ID, S3_SECRET_ACCESS_KEY etc.)
  2. Place global.testomatioArtifacts.push(fileName) inside a test context (global afterEach hook, spec file's afterEach hook, directly inside a test)
  3. Run mocha tests with parallel=true parameter

Expected behavior There is no error and the message [TESTOMATIO] 🗄️ Total N artifacts privately uploaded to S3 bucket is displayed in a log file

Actual behavior Error Cannot read properties of undefined (reading 'push') means global.testomatioArtifacts is undefined

Additional context There is no problem if tests are started and run without parallel mode, one by one.

Probable cause In my opinion, it can be caused by mocha's parallel run implementation. Mocha creates a pool of subprocesses (“workers”) for each spec file. TestomatIO client is invoked in the main thread, that's why TestomatIO report is created after tests are finished. But global.testomatioArtifacts is not initialised, so worker's context doesn't see it (https://mochajs.org/#parallel-mode)

DavertMik commented 1 year ago

Write /tmp UID for Run

mykhailiukVitalii commented 1 year ago

need to add a simple project to the examples/ repo with artifacts using!! WIP on this....

mykhailiukVitalii commented 9 months ago

Logs/Steps was implemented as additional option in Testomat-1.1 stable version