title: Ensure that fixtures exists when running a test. Control order of tests running
body: <p>A lot of this is wrapped in commands, but I've left that part out to make the problem more feasible.</p>
  <p>Consider these two tests:</p>
  <pre><code># Test1: Test login for user
   - Step1: Logs in manually (go to login-URL, fill out credentials and click 'Log in').
   - Step2: Save auth-cookies as fixtures.
  
  # Test2: Test something is dashboard for user.
   - Step1: Set auth-cookies (generated in Test1)
   - Step2: Visits https:://example.org/dashboard and ensures the user can see the dashboard.
  </code></pre>
  <p>If they run as written as listed above, then everything is fine.</p>
  <p>But if Test2 runs before Test1, then Test2 will fail, since Test1 hasn't to generated the cookies yet.</p>
  <p>So Test1 is <em>kind of</em> a prerequisite for Test2.</p>
  <p>But Test1 doesn't need to run <em>every</em> time Test2 runs - only if the auth-cookies aren't generated.</p>
  <p>I wish I could define my Test2 to be like this instead:</p>
  <pre><code>Test2: Test something is dashboard for user.
    - Step1: Run ensureAuthCookiesExists-command
    - Step2: If the AuthCookies.json-fixture doesn't exist, then run Test1
    - Step3: Sets auth-cookies (generated in Test1)
    - Step4: Visits https:://example.org/dashboard and ensures the user can see the dashboard.
  </code></pre>
  <hr />
  <h2>Solution attempt 1: Control by order</h2>
  <p>For a long time I've done this using this answer: <a href="https://stackoverflow.com/a/59690611/1766219">How to control order of tests</a>. And then having my tests defines like this:</p>
  <pre class="lang-json prettyprint-override"><code>{
    &quot;baseUrl&quot;: &quot;http://localhost:5000&quot;,
    &quot;testFiles&quot;: [
      &quot;preparations/*.js&quot;,
      &quot;feature-1/check-header.spec.js&quot;,
      &quot;feature-2/check-buttons.spec.js&quot;,
      &quot;feature-3/check-images.spec.js&quot;,
      &quot;feature-4/check-404-page.spec.js&quot;,
      //...
    ]
  }
  </code></pre>
  <p>But that is annoying, since it means that I keep having to add to add new features to that list, which get's annoying.</p>
  <p>And this only solves the problem if I want to run all the tests. If I want to run <code>preparations.spec.js</code> and thereafter: <code>feature-2/check-buttons.spec.js</code>. Then I can't do that easily.</p>
  <hr />
  <h2>Solution attempt 2: Naming tests smartly</h2>
  <p>I also tried simply naming them appropriately, like explain here: <a href="https://stackoverflow.com/a/62843385/1766219">naming your tests in Cypress</a>.</p>
  <p>But that pollutes the naming of the tests, making it more cluttered. And it faces the same issues as solution attempt 1 (that I can't easily run two specific tests after one another).</p>
  <hr />
  <h2>Solution attempt 3: Making a command for it</h2>
  <p>I considered making a command that tests for it. Here is some pseudo-code:</p>
  <pre class="lang-javascript prettyprint-override"><code>beforeEach(() =&gt; {
    if( preparationsHasntCompleted() ){
      runPreparations();
    }
  }
  </code></pre>
  <p>This seems smart, but it would add extra runtime to all my tests.</p>