chai-jest-snapshot icon indicating copy to clipboard operation
chai-jest-snapshot copied to clipboard

Issues with Mocha + Webpack

Open jarecsni opened this issue 6 years ago • 2 comments

I tried both Mocha configuration and framework-agnostic (manual) ones. Doesn't seem to work, as __dirname points to '/' which is not possible to write to (permission).

Any idea how to get it working with Mocha and Webpack? By the way, when I used the recommended way to configure it for Mocha, I got complaints that test name, snapshot name were not set. Apparently the before() beforeEach() were not run, however they were correctly configured as per suggested way.

jarecsni avatar Jan 12 '18 11:01 jarecsni

You should be able to use babel-plugin-transform-dirname-filename to get __dirname to work. However, if your tests are running in the browser, they won't be able to write to the disk unless fs's synchronous methods work (which isn't true in Chrome or Firefox, but is true in Electron or nw.js). If you are bundling your tests with webpack but running them in node, though, then you should be fine.

suchipi avatar Jan 12 '18 16:01 suchipi

Ok thanks I will give it a bash. In the meantime I resorted to including the snapshots in the tests themselves and comparing to wrapper.html() which is quite readable.

jarecsni avatar Jan 13 '18 07:01 jarecsni