Skip to content

Commit

Permalink
test: stabilize experiment redirect test by enforcing a variant
Browse files Browse the repository at this point in the history
  • Loading branch information
ramboz committed Aug 19, 2024
1 parent 2a01864 commit 318ae87
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions tests/experiments.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,24 +117,24 @@ test.describe('Page-level experiments', () => {
]);
});

test('Track RUM is fired before redirect.', 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');
await page.waitForURL(/\/tests\/fixtures\/experiments\/page-level(--redirect|-v[12])$/);
expect(await page.evaluate(() => window.document.body.innerText)).toMatch(/Hello (v[12]|World)!/);
expect(rumCalls[0]).toContainEqual([
'experiment',
{
source: 'foo',
target: expect.stringMatching(/control|challenger-1|challenger-2/),
},
]);
test('Track RUM is fired before redirect.', 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?experiment=foo/challenger-1');
await page.waitForURL('/tests/fixtures/experiments/page-level-v1');
expect(await page.evaluate(() => window.document.body.innerText)).toMatch(/Hello v1!/);
expect(rumCalls[0]).toContainEqual([
'experiment',
{
source: 'foo',
target: 'challenger-1',
},
]);
});

test('Exposes the experiment in a JS API.', async ({ page }) => {
await goToAndRunExperiment(page, '/tests/fixtures/experiments/page-level');
expect(await page.evaluate(() => window.hlx.experiments)).toContainEqual(
Expand Down

0 comments on commit 318ae87

Please sign in to comment.