Skip to content
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

fix: catch webpack removing require.resolve #69

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,25 @@ Cypress.Commands.add('percySnapshot', (name: string, options: any = {}) => {
})
})

const checkResolved = (x: string) => {
// we are resolving a path to the module
// and Webpack changes it to a number, then something is wrong
if (typeof x !== 'string') {
throw new Error('Should be a string')
}
return x
}

// An attempt to resiliently find the path to the 'percy-healthcheck' script, and to do so
// in a cross-platform manner.
function _healthcheckPath() {
try {
// Try to resolve with respect to the install local module.
return require.resolve('@percy/cypress/dist/percy-healthcheck')
return checkResolved(require.resolve('@percy/cypress/dist/percy-healthcheck'))
} catch {
try {
// Try to resolve relative to the current file.
return require.resolve('./percy-healthcheck')
return checkResolved(require.resolve('./percy-healthcheck'))
} catch {
// Oh well. Assume it's in the local node_modules.
// It would be nice to use __dirname here, but this code is entirely executed inside of
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@percy/cypress",
"version": "1.0.4",
"version": "1.0.5",
"description": "Cypress client library for visual regression testing with Percy (https://percy.io).",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand All @@ -24,6 +24,9 @@
"engines": {
"node": ">=8.0.0"
},
"files": [
"dist"
],
"author": "Perceptual Inc.",
"license": "MIT",
"bugs": {
Expand Down