Skip to content

Commit

Permalink
other: Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
olexandr-mazepa committed Feb 14, 2025
1 parent 81af7fb commit 03ee42c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ jobs:
logTime: "false"

- run: curl -vvvv http://localhost:3000/pages/AMD.html && cat log.txt
- run: curl -vvvv http://localhost:3000/pages/ESM.html && cat log.txt
- run: curl -vvvv http://localhost:3000/pages/ESM-dynamic.html && cat log.txt

- name: Run Browser integration tests
run: npm run test:integration:browser
13 changes: 7 additions & 6 deletions tests/integration/browser/tests/esm-dynamic/import.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,19 @@ type Window = globalThis.Window & {

describe('AMD import validation', () => {
beforeAll(async () => {
await page.goto('http://localhost:3000/pages/ESM.html');
await page.goto('http://localhost:3000/pages/ESM-dynamic.html');
await page.waitForFunction(function () { return typeof (window as Window).mailgunClient !== 'undefined'; });
await page.waitForFunction(function () { return typeof (window as Window).packageExport !== 'undefined'; });
await page.waitForFunction(function () { return typeof (window as Window).definitionsExport !== 'undefined'; });
});

test('AMD package exports function', async () => {
const isFunction = await page.evaluate(() => (typeof (window as Window).packageExport === 'function'));
expect(isFunction).toBe(true);
test('ESM-dynamic package exports object', async () => {
const exported = await page.evaluate(() => ((window as Window).packageExport));
expect(exported).toEqual(expect.any(Object));
expect(exported).toHaveProperty('default');
});

test('AMD definitions exports object', async () => {
test('ESM-dynamic definitions exports object', async () => {
const definitionsExport = await page.evaluate(() => (window as Window).definitionsExport);
expect(typeof definitionsExport).toBe('object');
expect(definitionsExport).toEqual(expect.objectContaining({
Expand All @@ -40,7 +41,7 @@ describe('AMD import validation', () => {
}));
});

test('AMD client has expected structure', async () => {
test('ESM-dynamic client has expected structure', async () => {
const client = await page.evaluate(() => (window as Window).mailgunClient);
const expected = ['request', 'domains', 'webhooks', 'events', 'stats', 'suppressions', 'messages', 'routes', 'ips', 'ip_pools', 'lists', 'validate'];
expect(client).toBeDefined();
Expand Down
10 changes: 5 additions & 5 deletions tests/integration/browser/tests/esm-dynamic/messages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ type ExtendedWindow = globalThis.Window & {
packageExport?: object
};

describe('Send message functionality (AMD)', () => {
describe('Send message functionality (ESM-dynamic)', () => {
beforeAll(async () => {
await page.goto('http://localhost:3000/pages/ESM.html');
await page.goto('http://localhost:3000/pages/ESM-dynamic.html');
await page.waitForFunction(function () { return typeof (window as ExtendedWindow).mailgunClient !== 'undefined'; });
await page.setRequestInterception(true);

Expand All @@ -41,7 +41,7 @@ describe('Send message functionality (AMD)', () => {
await page.setRequestInterception(false);
});

test('Sends plain email (AMD)', async () => {
test('Sends plain email (ESM-dynamic)', async () => {
const result = await page.evaluate(
(domain, messageData) => (window as ExtendedWindow)?.mailgunClient?.messages.create(
domain,
Expand All @@ -62,7 +62,7 @@ describe('Send message functionality (AMD)', () => {
});
});

test('Sends mime email (AMD)', async () => {
test('Sends mime email (ESM-dynamic)', async () => {
const result = await page.evaluate(
(domain, messageData) => (window as ExtendedWindow).mailgunClient?.messages.create(
domain,
Expand All @@ -83,7 +83,7 @@ describe('Send message functionality (AMD)', () => {
});
});

test('Sends an attachment (AMD)', async () => {
test('Sends an attachment (ESM-dynamic)', async () => {
await page.waitForSelector('input[type=file]', { timeout: 3000 });
const input = await page.$('input[type=file]');
expect(input).toBeTruthy();
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/browser/tests/esm/import.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ describe('AMD import validation', () => {
await page.waitForFunction(function () { return typeof (window as Window).definitionsExport !== 'undefined'; });
});

test('AMD package exports function', async () => {
test('ESM package exports function', async () => {
const isFunction = await page.evaluate(() => (typeof (window as Window).packageExport === 'function'));
expect(isFunction).toBe(true);
});

test('AMD definitions exports object', async () => {
test('ESM definitions exports object', async () => {
const definitionsExport = await page.evaluate(() => (window as Window).definitionsExport);
expect(typeof definitionsExport).toBe('object');
expect(definitionsExport).toEqual(expect.objectContaining({
Expand All @@ -40,7 +40,7 @@ describe('AMD import validation', () => {
}));
});

test('AMD client has expected structure', async () => {
test('ESM client has expected structure', async () => {
const client = await page.evaluate(() => (window as Window).mailgunClient);
const expected = ['request', 'domains', 'webhooks', 'events', 'stats', 'suppressions', 'messages', 'routes', 'ips', 'ip_pools', 'lists', 'validate'];
expect(client).toBeDefined();
Expand Down
10 changes: 5 additions & 5 deletions tests/integration/browser/tests/esm/messages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ type ExtendedWindow = globalThis.Window & {
packageExport?: object
};

describe('Send message functionality (AMD)', () => {
describe('Send message functionality (ESM)', () => {
beforeAll(async () => {
await page.goto('http://localhost:3000/pages/esm-dynamic.html');
await page.goto('http://localhost:3000/pages/ESM.html');
await page.waitForFunction(function () { return typeof (window as ExtendedWindow).mailgunClient !== 'undefined'; });
await page.setRequestInterception(true);

Expand All @@ -41,7 +41,7 @@ describe('Send message functionality (AMD)', () => {
await page.setRequestInterception(false);
});

test('Sends plain email (AMD)', async () => {
test('Sends plain email (ESM)', async () => {
const result = await page.evaluate(
(domain, messageData) => (window as ExtendedWindow)?.mailgunClient?.messages.create(
domain,
Expand All @@ -62,7 +62,7 @@ describe('Send message functionality (AMD)', () => {
});
});

test('Sends mime email (AMD)', async () => {
test('Sends mime email (ESM)', async () => {
const result = await page.evaluate(
(domain, messageData) => (window as ExtendedWindow).mailgunClient?.messages.create(
domain,
Expand All @@ -83,7 +83,7 @@ describe('Send message functionality (AMD)', () => {
});
});

test('Sends an attachment (AMD)', async () => {
test('Sends an attachment (ESM)', async () => {
await page.waitForSelector('input[type=file]', { timeout: 3000 });
const input = await page.$('input[type=file]');
expect(input).toBeTruthy();
Expand Down

0 comments on commit 03ee42c

Please sign in to comment.