question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fails to automatically load fixture files if more than one . is in file name

See original GitHub issue
  • Operating System: OSX High Sierra 10.13.3
  • Cypress Version: 2.1.0

Is this a Feature or Bug?

Bug

Current behavior:

cy.fixture function does not look up files without extension correctly if they have several dots. Is probably looking for first element after first “.”, but should look for element after last “.”

How to reproduce:

Check this code: tiny test fork Create a fixture file with several dots in name (e.g. parent.child.info.json, and use cy.fixture('parent.child.info') in your test.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
Ancinekcommented, Jul 8, 2018

@bahmutov That’s what I was looking for! For anyone that also needs something like this - from within the plugin/index.js file you invoke an on method, so the file looks like this:

module.exports = (on, config) => {
  // `on` is used to hook into various events Cypress emits
  // `config` is the resolved Cypress config
  on('task', {
    checkFixtureExistance: (fixtureName) => {
      const rootPath = appRootDir.get();
      const filePath = `${rootPath}/cypress/fixtures/${fixtureName}.json`;
      return fs.existsSync(filePath);
    },
  });
};

So in the app you can then simply do:

const provideFixture = (fixtureName, endpointPath) => {
  cy.server();
  const filePath = `cypress/fixtures/${fixtureName}.json`;
  cy.task('checkFixtureExistance', fixtureName).then((exists) => {
    if (exists) return;
    cy.request(endpointPath).then(({ body }) => {
      cy.writeFile(filePath, body);
    });
  });
  cy.route(path, `fixture:${fixtureName}.json`);
}
0reactions
cypress-bot[bot]commented, Mar 15, 2019

Released in 3.2.0.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Load Multiple Fixtures at Once - django - Stack Overflow
Using $ python manage.py loaddata myfixtures/*.json would work as Bash will substitute the wildcard to a list of matching filenames.
Read more >
fixture | Cypress Documentation
Load a fixed set of data located in a file. ... When no extension is passed to cy.fixture() , Cypress will search for...
Read more >
How to use fixtures — pytest documentation
When pytest goes to run a test, it looks at the parameters in that test function's signature, and then searches for fixtures that...
Read more >
Set model name in fixtures as metadata - BigBinary Blog
When automatic detection of model name from fixture file name fails, we can specify the table name using the set_fixture_class method.
Read more >
How to provide initial data for models - Django documentation
If you want to automatically load initial data for an app, create a data ... The most straightforward way of creating a fixture...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found