-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error when running all snapshots #10
Comments
This was quite hard to fix but I managed it. Probably need to contact Cypress about why |
@tomitrescak can you verify it works? |
I will remove the fix, it was causing other issues and the real reason is a bug in Cypress: |
IMO this issue should be mentioned on the README as it's a huge blocker for me, I only found out after implementing and writing tests (using Please consider adding an eye-catching warning or 'caveat' section which mentions this issue so that other users of this package will not share the same experience I had or at the very least, know of this important bug. Hope Cypress gets the fix in soon, :fingers (added a PR as a suggestion for a new section in the README file: #37) |
adds caveat section which highlights #10 cypress-io/cypress/3090
So the workaround I can offer for now is to fix // cypress/support/index.js
export const fixCypressSpec = filename => () => {
const path = require('path')
const relative = filename.substr(1) // removes leading "/"
const projectRoot = Cypress.config('projectRoot')
const absolute = path.join(projectRoot, relative)
Cypress.spec = {
absolute,
name: path.basename(filename),
relative
}
} From each spec file (that wants to use snapshots) import { fixCypressSpec } from '../support'
beforeEach(fixCypressSpec(__filename)) I have been playing with this in https://github.com/bahmutov/objection-example using this approach to run all specs with snapshots |
Seems not to be working if you are using TypeScript. |
Investigate if this would work as a possible fix.
|
+1 @CSchulz When using typescript, the workaround mentioned by @bahmutov does not work, as the |
Any light at the end of this tunnel? The suggested fixes don't seem to work for me :( |
Especially for Typescript users, it's easier to use a custom command for the workaround like this: Cypress.Commands.add('fixCypressSpec', (filename) => {
const path = require('path')
const relative = filename.substr(1) // removes leading "/"
const projectRoot = Cypress.config('projectRoot')
const absolute = path.join(projectRoot, relative)
Cypress.spec = {
absolute,
name: path.basename(filename),
relative
}
}) add it to the index.d.ts like this: /// <reference types="cypress" />
declare namespace Cypress {
interface Chainable {
fixCypressSpec(filename: string): void
}
} and then in the spec in a describe('my test', () => {
beforeEach(() => {
cy.fixCypressSpec('/cypress/integration/mytest_spec.ts')
(...) |
+ if using Given('I use snapshots for {string} feature', (fileName) => {
cy.fixCypressSpec(fileName);
}); And in specs/features that use the snapshotting specify that: But still would be nice to avoid all these workarounds ;) |
I put the fix suggested by @bahmutov and it seems to work. But it looks like an error is thrown from getSpec.js, If I comment this out the test works fine. The question is how do you handle this for others on the team? Tell them to npm install then go into node_modules and comment out the offending line? Is anyone else doing something more streamlined? |
I had this problem too. Solved the issue by forking the plugin, modifying the fork by commenting out those lines that throw the error, and using that forked module in package.json. |
When I apply @bahmutov's workaround - it works well, thanks for this 😄 however, after running the all the test specs, a folder called "ypress" gets created (ie. |
There is no reason to manually specify the path: |
Thanks @dploeger and @441N143G, that's really helpful. Btw, TypeScript users will also want to install
Also, @krisraven, I have had the same. I believe the issue here is that you may have provided
|
I experienced the same thing, to not have "ypress" folder, you juste have to remove |
This solution works for me universally with TypeScript:
import { basename } from 'path';
declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace Cypress {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
interface Chainable<Subject> {
/**
* Patch cypress-plugin-snapshots
*
* @returns {void}
*/
fixCypressSpec(): void;
}
}
}
Cypress.Commands.add('fixCypressSpec', function () {
const { absoluteFile, relativeFile } = this.test.invocationDetails;
Cypress.spec = {
...Cypress.spec,
absolute: absoluteFile,
name: basename(absoluteFile),
relative: relativeFile,
};
});
import './support/snapshotPatch.ts';
beforeEach(() => {
cy.fixCypressSpec();
}); |
if i use it globally it saves all the snapshots as index.ts.snap, but works if i call it as a command within tests, which i feel is preferable anyway |
@SSDlm Thanks for pointing that issue out! That's a bug I discovered shortly after I posted the above solution. I meant to come back here and update but never did 😖 |
The maintenance of this package is freezed.. I was added to the project but I didn't have any right for merge PR or update project settings (CICD is broken).. |
Could this plugin run the fix (workaround) internally? |
If you change: const { absoluteFile, relativeFile } = this.test.invocationDetails; to: const { absoluteFile, relativeFile } = this.currentTest.invocationDetails; it works in a global beforeEach. |
Hi, thanks for the amazing plugin!!!
There is a possible bug, as when I run all tests in the cypress browser I receive following error:
The text was updated successfully, but these errors were encountered: