Skip to content

Commit

Permalink
run 100 times
Browse files Browse the repository at this point in the history
  • Loading branch information
mydea committed Mar 8, 2023
1 parent d078e8b commit 104e54f
Showing 1 changed file with 92 additions and 90 deletions.
182 changes: 92 additions & 90 deletions packages/integration-tests/suites/replay/privacyInputMaskAll/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,103 +16,105 @@ function isInputMutation(
return snap.data.source == IncrementalSource.Input;
}

sentryTest(
'should mask input initial value and its changes from `maskAllInputs` and allow unmasked selector',
async ({ browserName, forceFlushReplay, getLocalTestPath, page }) => {
// TODO(replay): This is flakey on firefox and webkit (~1%) where we do not always get the latest mutation.
if (shouldSkipReplayTest() || ['firefox', 'webkit'].includes(browserName)) {
sentryTest.skip();
}

// We want to ensure to check the correct event payloads
let firstInputMutationSegmentId: number | undefined = undefined;
const reqPromise0 = waitForReplayRequest(page, 0);
const reqPromise1 = waitForReplayRequest(page, (event, res) => {
const check =
firstInputMutationSegmentId === undefined && getIncrementalRecordingSnapshots(res).some(isInputMutation);

if (check) {
firstInputMutationSegmentId = event.segment_id;
for (let i = 0; i < 100; i++) {
sentryTest(
`should mask input initial value and its changes from \`maskAllInputs\` and allow unmasked selector RUN ${i}`,
async ({ browserName, forceFlushReplay, getLocalTestPath, page }) => {
// TODO(replay): This is flakey on firefox and webkit (~1%) where we do not always get the latest mutation.
if (shouldSkipReplayTest() || ['firefox', 'webkit'].includes(browserName)) {
sentryTest.skip();
}

return check;
});
const reqPromise2 = waitForReplayRequest(page, (event, res) => {
return (
typeof firstInputMutationSegmentId === 'number' &&
firstInputMutationSegmentId < event.segment_id &&
getIncrementalRecordingSnapshots(res).some(isInputMutation)
);
});

await page.route('https://dsn.ingest.sentry.io/**/*', route => {
return route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({ id: 'test-id' }),
// We want to ensure to check the correct event payloads
let firstInputMutationSegmentId: number | undefined = undefined;
const reqPromise0 = waitForReplayRequest(page, 0);
const reqPromise1 = waitForReplayRequest(page, (event, res) => {
const check =
firstInputMutationSegmentId === undefined && getIncrementalRecordingSnapshots(res).some(isInputMutation);

if (check) {
firstInputMutationSegmentId = event.segment_id;
}

return check;
});
const reqPromise2 = waitForReplayRequest(page, (event, res) => {
return (
typeof firstInputMutationSegmentId === 'number' &&
firstInputMutationSegmentId < event.segment_id &&
getIncrementalRecordingSnapshots(res).some(isInputMutation)
);
});

await page.route('https://dsn.ingest.sentry.io/**/*', route => {
return route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({ id: 'test-id' }),
});
});
});

const url = await getLocalTestPath({ testDir: __dirname });

await page.goto(url);
await reqPromise0;

const text = 'test';

await page.locator('#input').fill(text);
await forceFlushReplay();

const snapshots = getIncrementalRecordingSnapshots(await reqPromise1).filter(isInputMutation);
const lastSnapshot = snapshots[snapshots.length - 1];
expect(lastSnapshot.data.text).toBe('*'.repeat(text.length));

await page.locator('#input-unmasked').fill(text);
await forceFlushReplay();
const snapshots2 = getIncrementalRecordingSnapshots(await reqPromise2).filter(isInputMutation);
const lastSnapshot2 = snapshots2[snapshots2.length - 1];
expect(lastSnapshot2.data.text).toBe(text);
},
);

sentryTest(
'should mask textarea initial value and its changes from `maskAllInputs` and allow unmasked selector',
async ({ browserName, forceFlushReplay, getLocalTestPath, page }) => {
// TODO(replay): This is flakey on firefox and webkit (~1%) where we do not always get the latest mutation.
if (shouldSkipReplayTest() || ['firefox', 'webkit'].includes(browserName)) {
sentryTest.skip();
}

const reqPromise0 = waitForReplayRequest(page, 0);
const reqPromise1 = waitForReplayRequest(page, 1);
const reqPromise2 = waitForReplayRequest(page, 2);

await page.route('https://dsn.ingest.sentry.io/**/*', route => {
return route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({ id: 'test-id' }),

const url = await getLocalTestPath({ testDir: __dirname });

await page.goto(url);
await reqPromise0;

const text = 'test';

await page.locator('#input').fill(text);
await forceFlushReplay();

const snapshots = getIncrementalRecordingSnapshots(await reqPromise1).filter(isInputMutation);
const lastSnapshot = snapshots[snapshots.length - 1];
expect(lastSnapshot.data.text).toBe('*'.repeat(text.length));

await page.locator('#input-unmasked').fill(text);
await forceFlushReplay();
const snapshots2 = getIncrementalRecordingSnapshots(await reqPromise2).filter(isInputMutation);
const lastSnapshot2 = snapshots2[snapshots2.length - 1];
expect(lastSnapshot2.data.text).toBe(text);
},
);

sentryTest(
`should mask textarea initial value and its changes from \`maskAllInputs\` and allow unmasked selector RUN ${i}`,
async ({ browserName, forceFlushReplay, getLocalTestPath, page }) => {
// TODO(replay): This is flakey on firefox and webkit (~1%) where we do not always get the latest mutation.
if (shouldSkipReplayTest() || ['firefox', 'webkit'].includes(browserName)) {
sentryTest.skip();
}

const reqPromise0 = waitForReplayRequest(page, 0);
const reqPromise1 = waitForReplayRequest(page, 1);
const reqPromise2 = waitForReplayRequest(page, 2);

await page.route('https://dsn.ingest.sentry.io/**/*', route => {
return route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({ id: 'test-id' }),
});
});
});

const url = await getLocalTestPath({ testDir: __dirname });
const url = await getLocalTestPath({ testDir: __dirname });

await page.goto(url);
await page.goto(url);

await reqPromise0;
await reqPromise0;

const text = 'test';
const text = 'test';

await page.locator('#textarea').fill(text);
await forceFlushReplay();
const snapshots = getIncrementalRecordingSnapshots(await reqPromise1).filter(isInputMutation);
const lastSnapshot = snapshots[snapshots.length - 1];
expect(lastSnapshot.data.text).toBe('*'.repeat(text.length));
await page.locator('#textarea').fill(text);
await forceFlushReplay();
const snapshots = getIncrementalRecordingSnapshots(await reqPromise1).filter(isInputMutation);
const lastSnapshot = snapshots[snapshots.length - 1];
expect(lastSnapshot.data.text).toBe('*'.repeat(text.length));

await page.locator('#textarea-unmasked').fill(text);
await forceFlushReplay();
const snapshots2 = getIncrementalRecordingSnapshots(await reqPromise2).filter(isInputMutation);
const lastSnapshot2 = snapshots2[snapshots2.length - 1];
expect(lastSnapshot2.data.text).toBe(text);
},
);
await page.locator('#textarea-unmasked').fill(text);
await forceFlushReplay();
const snapshots2 = getIncrementalRecordingSnapshots(await reqPromise2).filter(isInputMutation);
const lastSnapshot2 = snapshots2[snapshots2.length - 1];
expect(lastSnapshot2.data.text).toBe(text);
},
);
}

0 comments on commit 104e54f

Please sign in to comment.