From abc455933ec483176254ecdbaa95388028312e2d Mon Sep 17 00:00:00 2001 From: Dennis Li Date: Tue, 9 Jul 2024 17:34:56 -0700 Subject: [PATCH] Adding lib tests --- features/bacom/libs.spec.js | 28 +++++++++++++++++++++ tests/bacom/libs.test.js | 50 +++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 features/bacom/libs.spec.js create mode 100644 tests/bacom/libs.test.js diff --git a/features/bacom/libs.spec.js b/features/bacom/libs.spec.js new file mode 100644 index 00000000..0e4d3576 --- /dev/null +++ b/features/bacom/libs.spec.js @@ -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', + }, + ], +}; diff --git a/tests/bacom/libs.test.js b/tests/bacom/libs.test.js new file mode 100644 index 00000000..4535e4ca --- /dev/null +++ b/tests/bacom/libs.test.js @@ -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); + }); + }); +});