meinaart / cypress-plugin-snapshots

Plugin for snapshot tests in Cypress.io
MIT License
497 stars 117 forks source link

toMatchImageSnapshot fails with Path must be a string. Received undefined #41

Closed ioana-gln closed 5 years ago

ioana-gln commented 5 years ago

We are trying to use your plugin and when we use the ImageSnapshot cypress throws an error.

Sample code:

cy.document().toMatchImageSnapshot()

The .png image snapshots are created correctly under __imagesnapshots_\ but the tests fail and cypress throws the following error:

CypressError: cy.task('cypress-plugin-snapshot:matchImage') failed with the following error:

> TypeError: Path must be a string. Received undefined
    at assertPath (path.js:28:11)
    at Object.relative (path.js:1267:5)
    at getImageData (/Users/ioanagalan/Templafy/Templafy.AutomatedQualityAssurance/CypressTests/node_modules/cypress-plugin-snapshots/src/utils/image/getImageData.js:8:24)
    at matchImageSnapshot (/Users/ioanagalan/Templafy/Templafy.AutomatedQualityAssurance/CypressTests/node_modules/cypress-plugin-snapshots/src/tasks/matchImageSnapshot.js:70:15)
    at invoke (/Users/ioanagalan/Library/Caches/Cypress/3.3.1/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/child/task.js:37:14)
    at /Users/ioanagalan/Library/Caches/Cypress/3.3.1/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/util.js:48:16
    at tryCatcher (/Users/ioanagalan/Library/Caches/Cypress/3.3.1/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/util.js:16:23)
    at Function.Promise.attempt.Promise.try (/Users/ioanagalan/Library/Caches/Cypress/3.3.1/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/method.js:39:29)
    at Object.wrapChildPromise (/Users/ioanagalan/Library/Caches/Cypress/3.3.1/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/util.js:47:28)
    at Object.wrap (/Users/ioanagalan/Library/Caches/Cypress/3.3.1/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/child/task.js:43:8)
    at execute (/Users/ioanagalan/Library/Caches/Cypress/3.3.1/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/child/run_plugins.js:86:12)
    at EventEmitter.ipc.on (/Users/ioanagalan/Library/Caches/Cypress/3.3.1/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/child/run_plugins.js:136:5)
    at emitThree (events.js:136:13)
    at EventEmitter.emit (events.js:217:7)
    at process.<anonymous> (/Users/ioanagalan/Library/Caches/Cypress/3.3.1/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/util.js:25:29)
    at emitTwo (events.js:126:13)
    at process.emit (events.js:214:7)
    at emit (internal/child_process.js:772:12)
    at _combinedTickCallback (internal/process/next_tick.js:141:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)

Cypress version: 3.3.1 cypress-plugin-snapshots version: 1.2.6 @cypress/snapshot version 2.1.3

Worth mentioning is that we are running on mac. Note: This only happens when screenshots do not exist and they are created for the first time.

lots0logs commented 5 years ago

@meinaart Any reason you haven't published a release lately? It looks like this bug might have been addressed back in March :thinking:

germyjen commented 5 years ago

I'm seeing this exact issue, I set the cypress.json to "autopassNewSnapshots": true, but it didn't resolve the problem.

lots0logs commented 5 years ago

Note: It works fine if you run one test file at a time. It only fails when you try to click the Run All button in the UI. The CLI works fine both ways.

johnmcclumpha commented 5 years ago

Agree with @lots0logs this appears to be fixed (unless running all tests in the ui - different issue) based on changes provided by @rlux-aa over here: https://github.com/meinaart/cypress-plugin-snapshots/pull/31/commits/cf8287706f80ecdfcb829cb03a3ca460724e26d4

Would be awesome the see an updated release published @meinaart :)

meinaart commented 5 years ago

Can you retry with latest version and let me know if that fixes it?

johnmcclumpha commented 5 years ago

thanks @meinaart - can confirm this release has fixed this issue :)

meinaart commented 5 years ago

Thanks @johnmcclumpha