mochiya98 / mocha-chai-jest-snapshot

provides snapshot testing like jest
MIT License
28 stars 5 forks source link

Configuration `rootDir` Appears Ignored? #14

Open 67726e opened 2 years ago

67726e commented 2 years ago

For the life of me, I cannot get the plugin to respect the rootDir configuration. I've tried passing it in via:

# In Test
chai.use(jestSnapshotPlugin({ rootDir: '/absolute/path/to/directory' })

chai.use(jestSnapshotPlugin({ rootDir: '../relative/path/to/directory' })

# In <PROJECT_ROOT>/jest.config.js
module.exports = {
  rootDir: '/absolute/path/to/directory',
};

# In <PROJECT_ROOT>/package.json
{
  "jest": {
    "rootDir": "/absolute/path/to/directory"
  }
}

For whatever reason, the resulting structure looks like:

tests/
  __snapshots__/
  test.spec.ts

Whereas, I would prefer it to be something like:

snapshots/
tests/
  test.spec.ts
mochiya98 commented 2 years ago

Thanks for the report. I will fix it in my spare time.

67726e commented 2 years ago

After consulting the Jest documentation on their usage of rootDir, it is used to tell the Jest framework where to look for tests in the same way that one would mocha test/**/*.js so the behavior regarding __snapshot__ directory placement is likely correct.

67726e commented 2 years ago

In looking at what I want(ed) to achieve, I would want to look at the snapshotResolver property rather than rootDir which appears to mostly dictate the location from which the library pulls the jest.config.js file.

https://stackoverflow.com/questions/57682736/how-to-configure-jest-snapshot-locations

67726e commented 2 years ago

As opposed to an actual bug, this "issue" would be better solved via clarified documentation in the README and or some examples.