https://cypress.io logo
Where are people placing code that should be run o...
# general-chat
s
Where are people placing code that should be run only once at the beginning of the all the tests? I tried some tricks with before() in e2e.js but that seems to run before every file. Unfortunately, I can't seem to get a global variable to work in there (run the code when typeof var === "undefined" then let var = true so it won't run again) I'm currently exploring on('before:run'), but then I don't get access to cy. Is there another way or is this the best method?
d
In the support directory you can create for example a global.js file, put there in before() code that should be run only once at the beginning of the all the tests. Next, import this file in the e2e file: import './global'
s
Ok, I'll give that a whirl.
Perhaps e2e.js is treated differently.