Before running e2e tests in Jest I need to get an authentication token from the server.
Is it possible to do this globally one and set it somehow to the glo
Ini my case, I had to get the token for current session once. Here I used globalSetup
property in jest config. Ref: https://jestjs.io/docs/en/configuration#globalsetup-string
My jest.config:
module.exports = {
globalSetup: "./tests/global-setup.js",
// ..other config...
globals: {
TEST_EMAIL: 'test@test.com',
TEST_PASSWORD: 'some_password',
}
}
global-setup.js:
module.exports = async function() {
const getSessionToken = () => {
// api call to get SessionToken
/* return fetch() */
}
sessionToken = await getSessionToken();
process.env.SESSION_TOKEN = sessionToken;
}