Giter VIP home page Giter VIP logo

Comments (3)

sectore avatar sectore commented on August 10, 2024

To fix this issue just use latest version (v.0.0.4) of karma-json-fixtures-preprocessor and setup it by using the new feature transformPath:

jsonFixturesPreprocessor: {
  variableName: '__json__',
  transformPath: function(path) {
    return path + '.js';
  }
},

@billtrik: Could you update the instruction of "setup the karma-json-fixtures-preprocessor plugin" for using transformPath, please? After this, this issue can be closed ;) Thanks!

from karma-fixture.

billtrik avatar billtrik commented on August 10, 2024

Hey @sectore, @MarcusVeres, i am trying to reproduce this but i cannot.
Let me add here that you did not provide enough info about the problem,
but instead only a proposed solution.

So, some background first:

Due to #7, i started using the json-fixtures-preprocessor to load JSON files.

This preprocessor works by loading every file declared here:

preprocessors: {
  ...
   'test/fixtures/**/*.json'   : ['json_fixtures']
},

into the window.__json__ object in the test page.
For every json file loaded from the filesystem, it creates a key in this object like: "test/fixtures/some_other_folder/json_fixture_filename" and the value is the contents of that file.

Note that the key does not include the '.json' suffix, as described in the problem. I checked every published version and i also used the mentioned transformPath helper,
but it always does the same.
The key is always without the '.json' suffix.

Pretty straight forward stuff.

In this commit:
68bb717#diff-8d54b9a926c8d58538fac64c9aeefef7R50
i search for the requested json file trying out multiple combinations for the key string.

Specifically if you do a fixture.load('json_fixture.json');
the plugin with try the following keys on the __json__ object:

  • json_fixture
  • json_fixture.json
  • base/json_fixture
  • base/json_fixture.json
  • /absolute_fixture_path

So in my setup,
having done fixture.setBase('base'); and then fixture.load('json_fixture.json');
the requested json exists in window.__json__['base/json_fixture'].

So in my mind, i cannot see where the problem might be.

Since @MarcusVeres has the same issue though, maybe there is something else here.

Prior to anything, please double check that you are using the latest version of karma-fixture.

Then put a debugger before your fixture.load() line and check the key in the window.__json__ object. It's keys should include the base and then the filename without the '.json' suffix.
If not, maybe you have issues with how you declare which files to load in your config file.

If you still have a problem, please try to describe it as best as you can.
Finally since this is open source, it goes without saying that you are more than welcome to make a PR with a solution to this problem.

from karma-fixture.

billtrik avatar billtrik commented on August 10, 2024

I am closing this for now.
Will reopen it if there are still issues.

from karma-fixture.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.