velesin / jasmine-jquery

jQuery matchers and fixture loader for Jasmine framework
MIT License
1.89k stars 347 forks source link

Cache for fixtures is based on relative paths not absolute #286

Closed GerroDen closed 3 years ago

GerroDen commented 8 years ago

This error was hard to find for us. We write tests more in a module like way, so that a fixture in HTML has the same name as the test file in JS and is in the same path. In the test we setup the path to the fixtures separately to the module's path. So basically it could be possible that we use the same classnames but in different namespaces. But if two fixtures have the same name in different paths, it is cached only by the fixture's basename. So it in either test it loads the wrong fixture.

So our testfile structure is like this:

+-src
| +-moduleA
| | +-class.js
| | ...
| +-moduleB
|   +-class.js
|   ...
+-test
  +-moduleA
  | +-class.spec.js
  | +-class.html <- The fixture
  | ...
  +-moduleB
    +-class.spec.js
    +-class.html <- The fixture
    ...

And our tests are sctructured like this for moduleA/class.spec.js:

describe("moduleA.class", function () {
    ...
    beforeEach(function () {
        jasmine.getFixtures().fixturesPath = 'base/moduleA';
        loadFixtures("class.html");
    });
    ...
});

And for moduleB/class.spec.js:

describe("moduleB.class", function () {
    ...
    beforeEach(function () {
        jasmine.getFixtures().fixturesPath = 'base/moduleB';
        loadFixtures("class.html");
    });
    ...
});

And now depending on the order of test execution does either moduleA.class or moduleB.class load the wrong cached fixture, because they both have the same basename class.html. I know this is not the way it is documented, but it is more practical to have the fixtures along with the tests, because we deevelop in a kind of hostile environment, where it is necessary to provide different fixtures for tests of a class. jQuery-jasmine does not support a more module like approach to write tests with fixtures, because the keys inside the fixturesCache_ is based on the relative path without the configured fixturePath.