spotify / polly-jest-presets

Apache License 2.0
64 stars 10 forks source link

Cannot read property 'testPath' of undefined - Jest 26 #30

Open pietrofxq opened 3 years ago

pietrofxq commented 3 years ago

this package does not work with the last version of jest. This is the problematic code:

function getDefaultRecordingDir() {
    const testPath = global.jasmine.testPath;
    return path_1.default.relative(process.cwd(), `${path_1.default.dirname(testPath)}/__recordings__`);
}

Seems like a quick fix but not sure what is the current best way to get testPath

palmerj3 commented 3 years ago

Thanks for reporting!

I did a little digging into this. This only occurs if you use the jest-circus test runner. If you use the default test runner or explicitly set jest-jasmine2 as the test runner it works fine with the latest version of jest.

I think I have a way to make this work with jest-circus in the latest jest version but it would require changing where the recordings are actually stored, possibly. I'm going to sync with a few others on this next week and revisit.

pietrofxq commented 3 years ago

Thanks @palmerj3, since my project is on create-react-app, it would be very difficult to change the runner since I would need to configure jest from scratch

pietrofxq commented 3 years ago

@palmerj3 I see that setup-polly-jest supports jest-circus, maybe updating this dependency would help?

palmerj3 commented 3 years ago

Yeah I saw that too. Locally when I updated setup-polly-jest to the latest version and removed the block of code you referenced above I still saw some other errors that get triggered. So it will require a bit more thought.

That's why I wanted to involve some more colleagues into this.

mits87 commented 3 years ago

The same issue, any progress with that?