-
Notifications
You must be signed in to change notification settings - Fork 9
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
test: add tests for page level redirects #45
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## v2 #45 +/- ##
=====================================
Coverage ? 93.60%
=====================================
Files ? 1
Lines ? 704
Branches ? 11
=====================================
Hits ? 659
Misses ? 34
Partials ? 11 ☔ View full report in Codecov by Sentry. |
@ramboz Then I thought of leveraging Then this sparks my thinking that "Should we allow serving the control page if the property I really appreciate if you could provide any thoughts here :) test('Track RUM is fired before redirect 2 ', async ({ page }) => {
const rumCalls = [];
await page.exposeFunction('logRumCall', (...args) => rumCalls.push(args));
await page.addInitScript(() => {
window.hlx = { rum: { sampleRUM: (...args) => window.logRumCall(args) } };
});
await page.goto('/tests/fixtures/experiments/page-level--redirect');
// verify rum is fired
await page.waitForFunction(() => window.hlx.rum.sampleRUM);
expect(rumCalls[0]).toContainEqual([
'experiment',
{
source: 'foo',
target: expect.stringMatching(/control|challenger-1|challenger-2/),
},
]);
// verify page is redirected
const expectedContent = {
'v1': 'Hello v1!',
'v2': 'Hello v2!',
'redirect': 'Hello World!'
};
const expectedUrlPath = {
'v1': '/tests/fixtures/experiments/page-level-v1',
'v2': '/tests/fixtures/experiments/page-level-v2',
'redirect': '/tests/fixtures/experiments/page-level--redirect'
};
const url = new URL(page.url());
const variant = Object.keys(expectedUrlPath).find(k => url.pathname.endsWith(k));
expect(await page.evaluate(() => window.document.body.innerText)).toMatch(new RegExp(expectedContent[variant]));
expect(expectedUrlPath[variant]).toBe(url.pathname);
}); |
@FentPams Good idea with the test. I think this is definitely valid as well.
Yes, we should. if the customer wants to force the redirect and not use the control, then they can set the split ratio to 0 for the control |
Description
To test:
Finding:
window.location.replace ()
to let it do nothing when testing RUM is fired before redirect.However, some browsers have strict security restriction that don't allow certain function to be overridden, which leads to test fails.
window.location.replace ()
is commented out before the script is executed and security policies are applied.Types of changes
Checklist: