There should be S3 bucket connected to tests by env variables (TESTOMATIO_PRIVATE_ARTIFACTS=1, S3_ACCESS_KEY_ID, S3_SECRET_ACCESS_KEY etc.)
Place global.testomatioArtifacts.push(fileName) inside a test context (global afterEach hook, spec file's afterEach hook, directly inside a test)
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)
[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:
global.testomatioArtifacts.push(fileName)
inside a test context (globalafterEach
hook, spec file'safterEach
hook, directly inside a test)parallel=true
parameterExpected behavior There is no error and the message
[TESTOMATIO] 🗄️ Total N artifacts privately uploaded to S3 bucket
is displayed in a log fileActual behavior Error
Cannot read properties of undefined (reading 'push')
meansglobal.testomatioArtifacts
is undefinedAdditional 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)