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
Conversation
package.json
Outdated
@@ -35,5 +35,8 @@ | |||
"ts-jest": "^27.1.0", | |||
"typescript": "^4.2.4" | |||
}, | |||
"resolutions": { | |||
"fs-extra": "^9.0.0" |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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', { |
There was a problem hiding this comment.
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', |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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> { |
There was a problem hiding this comment.
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.
c4577e9
to
a663060
Compare
"@pollyjs/adapter-node-http": "^5.1.1", | ||
"@pollyjs/core": "^5.1.1", | ||
"@pollyjs/persister-fs": "^5.1.1", | ||
"@types/har-format": "^1.2.4", |
There was a problem hiding this comment.
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
! 🥳
package.json
Outdated
@@ -35,5 +35,8 @@ | |||
"ts-jest": "^27.1.0", | |||
"typescript": "^4.2.4" | |||
}, | |||
"resolutions": { | |||
"fs-extra": "^9.0.0" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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.
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 causeda 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: