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

INT-3349 - Upgrade Polly.JS #688

Merged
merged 2 commits into from Apr 18, 2022
Merged

INT-3349 - Upgrade Polly.JS #688

merged 2 commits into from Apr 18, 2022

Conversation

austinkelleher
Copy link
Contributor

@austinkelleher austinkelleher commented Apr 16, 2022

The following packages have been upgraded:

  • @pollyjs/adapter-node-http
  • @pollyjs/core
  • @pollyjs/persister-fs

The new Polly.JS packages ship with TypeScript definition files,
so the old @type/pollyjs__ packages have been removed!

Additionally, fs-extra has been pinned to semver range ^9.0.0
because there a change was released in ^10.0.0 that caused
a regression. See: jprichardson/node-fs-extra#953.

NOTE: I also linked the @jupiterone/integration-sdk-testing package into an integration and manually tested the following scenarios:

  • Run tests with existing recordings
  • Delete a recording, generate a new recording, and test against the new recording

package.json Outdated
@@ -35,5 +35,8 @@
"ts-jest": "^27.1.0",
"typescript": "^4.2.4"
},
"resolutions": {
"fs-extra": "^9.0.0"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See description for the reason for this

"@pollyjs/adapter-node-http": "^5.1.1",
"@pollyjs/core": "^5.1.1",
"@pollyjs/persister-fs": "^5.1.1",
"@pollyjs/adapter-node-http": "^6.0.5",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Major version changes were considered and various testing utilities have been updated. CHANGELOG can be found here: https://github.com/Netflix/pollyjs/blob/master/CHANGELOG.md#600-2021-11-30

"@types/fs-extra": "^9.0.13",
"@types/js-yaml": "^4.0.3",
"@types/json-diff": "^0.5.1",
"@types/lodash": "^4.14.158",
"@types/pollyjs__adapter-node-http": "^2.0.1",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See description. These are no longer needed! 🥳

@@ -37,14 +38,7 @@ beforeEach(() => {
process.env.JUPITERONE_ACCOUNT = 'mochi';
loadProjectStructure('validationFailure');

polly = new Polly('run-cli-failure', {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small bonus change. Extracted this functionality into createTestPolly because it is used in 3 tests.

return new Polly(recordingName, {
adapters: ['node-http'],
persister: 'fs',
logLevel: 'silent',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only change made when creating new Polly instances is here. There used to be a logging boolean, which was assigned false. In Polly.JS v6, logging was removed and replaced with logLevel. I kept the existing behavior by assigning silent as the value.

@@ -22,7 +22,7 @@ export function setupSynchronizerApi({ polly, job, baseUrl }: SetupOptions) {
.post(`${baseUrl}/persister/synchronization/jobs/${job.id}/entities`)
.intercept((req, res) => {
allowCrossOrigin(req, res);
job.numEntitiesUploaded += JSON.parse(req.body).entities.length;
job.numEntitiesUploaded += JSON.parse(req.body!).entities.length;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new internal Polly.JS TypeScript definitions allow body to be undefined. For this test to pass, body would need to be defined.

@@ -78,7 +78,7 @@ export function setupRecording({
return 'JupiterOneIntegationFSPersister';
}

saveRecording(recordingId: number, data: Har): void {
async onSaveRecording(recordingId: string, data: Har): Promise<void> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Breaking change in Polly.JS v6. See the Polly.JS CHANGELOG.

The following packages have been upgraded:

- `@pollyjs/adapter-node-http`
- `@pollyjs/core`
- `@pollyjs/persister-fs`

The new Polly.JS packages ship with TypeScript definition files,
so the old `@type/pollyjs__` packages have been removed!

Additionally, `fs-extra` has been pinned to semver range `^9.0.0`
because there a change was released in `^10.0.0` that caused
a regression. See: jprichardson/node-fs-extra#953.
"@pollyjs/adapter-node-http": "^5.1.1",
"@pollyjs/core": "^5.1.1",
"@pollyjs/persister-fs": "^5.1.1",
"@types/har-format": "^1.2.4",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer needed since this data is exported from @pollyjs/persister! 🥳

@austinkelleher austinkelleher marked this pull request as ready for review April 16, 2022 13:47
@austinkelleher austinkelleher requested a review from a team April 16, 2022 13:47
package.json Outdated
@@ -35,5 +35,8 @@
"ts-jest": "^27.1.0",
"typescript": "^4.2.4"
},
"resolutions": {
"fs-extra": "^9.0.0"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related to fs.realpath.native being undefined, causing import of fs-extra@10.0.0 to throw error.

Defensively patched in jprichardson/node-fs-extra#953 and released in fs-extra@10.1.0.

Might want to bump it up instead, maybe?

But still, why is fs.realpath.native undefined? That is a root cause to be investigated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@peteriman Thanks a lot for putting a fix in for this issue and for following up here!

It's not clear to me why fs.realpath.native is undefined either. I may spend a little time trying to figure that out and get back to you if I find anything.

Thanks again!

Copy link

@lamweili lamweili Apr 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While fs-extra no longer throws error on require/import, if someone still uses fs.realpath.native (be it from fs-extra or from native fs) they would still face errors.

@austinkelleher You might want to console.log(typeof fs.realpath.native) at the first line of code as a pre-requisite, then the subsequently before and after every require/import to identify the offending dependency that "deleted" it.

@austinkelleher austinkelleher merged commit cdd6741 into main Apr 18, 2022
@austinkelleher austinkelleher deleted the INT-3349-polly branch April 18, 2022 20:35
@austinkelleher austinkelleher mentioned this pull request Apr 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants