I have two test files in Node.js that depend on each other. The first test runs some async work, and at the end exports an object with a UUID that the second test requires.
test_1.js
'use strict';
# simulate some async work
setTimeout(() => {
module.exports = {
id: '83b50527-73a9-4926-8247-e37547f3da6d'
};
}, 2000);
test_2.js
'use strict';
const testOne = require('./test_1.js');
console.log(testOne);
The problem is since the module.exports is called async in the first test, in test two console.log(testOne) is just an empty object.
How can I make test_2.js wait until test_1.js is finished exporting?