'Is there a way to define variables usable in all subtests in node tap?

I was wondering if there's a way to declare a variable before all the subtests in node tap js in order to use it in each one of them. Something like this:

      tap.test('...', async (t) => {
         
        t.before(async () => {
           const myVariable = ...
        }

        t.test('SubTest 1', async (t) => {
           await someMethod(myVariable)
        }

        t.test('SubTest 2', async (t) => {
           await someMethod(myVariable)
        }
      }  

It can be achieved another way, the idea is that I'd like to initialize some variables that I'll be using through all the subtests.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source