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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,7 @@ | |
"@jupiterone/integration-sdk-runtime": "^8.11.0", | ||
"chalk": "^4", | ||
"commander": "^5.0.0", | ||
"fs-extra": "^10.0.0", | ||
"fs-extra": "^10.1.0", | ||
"globby": "^11.0.0", | ||
"js-yaml": "^4.1.0", | ||
"json-diff": "^0.5.4", | ||
|
@@ -38,16 +38,13 @@ | |
}, | ||
"devDependencies": { | ||
"@jupiterone/integration-sdk-private-test-utils": "^8.11.0", | ||
"@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", | ||
"@pollyjs/core": "^6.0.5", | ||
"@pollyjs/persister-fs": "^6.0.5", | ||
"@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 commentThe reason will be displayed to describe this comment to others. Learn more. See description. These are no longer needed! 🥳 |
||
"@types/pollyjs__core": "^4.3.3", | ||
"@types/pollyjs__persister": "^4.3.1", | ||
"@types/vis": "^4.21.20", | ||
"memfs": "^3.2.0", | ||
"neo-forgery": "^2.0.0", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ import { createCli } from '../index'; | |
import { setupSynchronizerApi } from './util/synchronization'; | ||
|
||
import * as log from '../log'; | ||
import { createTestPolly } from './util/recording'; | ||
|
||
jest.mock('../log'); | ||
|
||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. Small bonus change. Extracted this functionality into |
||
adapters: ['node-http'], | ||
persister: 'fs', | ||
logging: false, | ||
matchRequestsBy: { | ||
headers: false, | ||
}, | ||
}); | ||
polly = createTestPolly('run-cli-failure'); | ||
|
||
mocked(mockCreateIntegrationLogger).mockReturnValue( | ||
createIntegrationLogger({ name: 'test' }), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Polly, PollyConfig } from '@pollyjs/core'; | ||
|
||
export function createTestPolly( | ||
recordingName: string, | ||
pollyConfigOverrides?: PollyConfig, | ||
) { | ||
return new Polly(recordingName, { | ||
adapters: ['node-http'], | ||
persister: 'fs', | ||
logLevel: 'silent', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The only change made when creating new |
||
matchRequestsBy: { | ||
headers: false, | ||
}, | ||
...pollyConfigOverrides, | ||
}); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. The new internal Polly.JS TypeScript definitions allow |
||
res.status(200).json({ job }); | ||
}); | ||
|
||
|
@@ -37,7 +37,9 @@ export function setupSynchronizerApi({ polly, job, baseUrl }: SetupOptions) { | |
.post(`${baseUrl}/persister/synchronization/jobs/${job.id}/relationships`) | ||
.intercept((req, res) => { | ||
allowCrossOrigin(req, res); | ||
job.numRelationshipsUploaded += JSON.parse(req.body).relationships.length; | ||
job.numRelationshipsUploaded += JSON.parse( | ||
req.body!, | ||
).relationships.length; | ||
res.status(200).json({ job }); | ||
}); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,13 +25,9 @@ | |
"dependencies": { | ||
"@jupiterone/integration-sdk-core": "^8.11.0", | ||
"@jupiterone/integration-sdk-runtime": "^8.11.0", | ||
"@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 commentThe reason will be displayed to describe this comment to others. Learn more. No longer needed since this data is exported from |
||
"@types/pollyjs__adapter-node-http": "^2.0.1", | ||
"@types/pollyjs__core": "^4.3.3", | ||
"@types/pollyjs__persister": "^4.3.1", | ||
"@pollyjs/adapter-node-http": "^6.0.5", | ||
"@pollyjs/core": "^6.0.5", | ||
"@pollyjs/persister-fs": "^6.0.5", | ||
"deepmerge": "^4.2.2", | ||
"lodash": "^4.17.15" | ||
}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
import { Har, Entry } from 'har-format'; | ||
import defaultsDeep from 'lodash/defaultsDeep'; | ||
import { gunzipSync } from 'zlib'; | ||
|
||
import NodeHttpAdapter from '@pollyjs/adapter-node-http'; | ||
import { Polly, PollyConfig } from '@pollyjs/core'; | ||
import FSPersister from '@pollyjs/persister-fs'; | ||
import { HarEntry, Har } from '@pollyjs/persister'; | ||
|
||
Polly.register(NodeHttpAdapter); | ||
Polly.register(FSPersister); | ||
|
||
export type Recording = Polly; | ||
export type RecordingEntry = Entry; | ||
export type RecordingEntry = HarEntry; | ||
|
||
export interface SetupRecordingInput { | ||
directory: string; | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. Breaking change in Polly.JS v6. See the Polly.JS CHANGELOG. |
||
data.log.entries.forEach((entry) => { | ||
// Redact tokens, even though they expire | ||
entry.request.headers = entry.request.headers.map((header) => ({ | ||
|
@@ -104,7 +104,7 @@ export function setupRecording({ | |
mutateEntry?.(entry); | ||
}); | ||
|
||
super.saveRecording(recordingId, data); | ||
return super.onSaveRecording(recordingId, data); | ||
} | ||
} | ||
|
||
|
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