Skip to content

Commit

Permalink
Adding lib tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennis Li committed Jul 11, 2024
1 parent 0dad656 commit abc4559
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
28 changes: 28 additions & 0 deletions features/bacom/libs.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module.exports = {
name: 'libs',
features: [
{
tcid: '0',
name: '@libs test',
mapping: [
['https://business.adobe.com', 'https://business.adobe.com/libs'],
['https://business.adobe.com?milolibs=foo', 'https://business.adobe.com/libs'],
['https://business.stage.adobe.com', 'https://main--milo--adobecom.hlx.live/libs'],
['https://business.stage.adobe.com?milolibs=foo', 'https://foo--milo--adobecom.hlx.live/libs'],
['https://business.stage.adobe.com?milolibs=awesome--milo--forkedowner',
'https://awesome--milo--forkedowner.hlx.live/libs'],
['https://main--bacom--adobecom.hlx.page/', 'https://main--milo--adobecom.hlx.live/libs'],
['https://main--bacom--adobecom.hlx.page/?milolibs=foo', 'https://foo--milo--adobecom.hlx.live/libs'],
['https://main--bacom--adobecom.hlx.page/?milolibs=local', 'http://localhost:6456/libs'],
['https://main--bacom--adobecom.hlx.page/?milolibs=awesome--milo--forkedowner',
'https://awesome--milo--forkedowner.hlx.live/libs'],
['https://main--bacom--adobecom.hlx.live/', 'https://main--milo--adobecom.hlx.live/libs'],
['https://main--bacom--adobecom.hlx.live/?milolibs=foo', 'https://foo--milo--adobecom.hlx.live/libs'],
['https://main--bacom--adobecom.hlx.live/?milolibs=local', 'http://localhost:6456/libs'],
['https://main--bacom--adobecom.hlx.live/?milolibs=awesome--milo--forkedowner',
'https://awesome--milo--forkedowner.hlx.live/libs'],
],
tags: '@libs @bacom @smoke @regression',
},
],
};
50 changes: 50 additions & 0 deletions tests/bacom/libs.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { expect, test } from '@playwright/test';
import fs from 'fs';
import { features } from '../../features/bacom/libs.spec.js';

const authFile = './tests/bacom/.auth/user.json';
let context;
let page;

test.describe('Libs test suite', () => {
test.beforeAll(async ({ browser, browserName, headless }) => {
test.skip(browserName !== 'chromium', "Don't need to run on multiple browsers.");

const options = fs.existsSync(authFile) ? { storageState: authFile } : {};
context = await browser.newContext(options);
page = await context.newPage();
await page.goto('https://main--bacom--adobecom.hlx.page/');

if (Object.keys(options).length === 0 && !headless) {
console.log('authFile is empty. Update the authFile by logging into Okta manually and waiting 2 mins.');
test.setTimeout(1000 * 60 * 3);
await page.waitForTimeout(1000 * 60 * 2);
}

await page.waitForLoadState('networkidle');
await context.storageState({ path: authFile });
});

features[0].mapping.forEach((mapping) => {
const url = mapping[0];
const expectedLibs = mapping[1];

test(`Checking libs on ${url}`, { tag: '@libs' }, async () => {
let libs;

await page.route('**/libs/**', (route) => {
if (route.request().url().includes('/libs/utils/utils.js')) {
[libs] = route.request().url().split('/utils/');
route.abort();
} else {
route.continue();
}
});

await page.goto(url);
await page.waitForLoadState('networkidle');

await expect(libs).toBe(expectedLibs);
});
});
});

0 comments on commit abc4559

Please sign in to comment.