Skip to content

Commit 9eb49d1

Browse files
Move Ably sandbox code to test/lib
I’ll reuse it in the upcoming integration tests.
1 parent fa95f9f commit 9eb49d1

File tree

4 files changed

+62
-2
lines changed

4 files changed

+62
-2
lines changed

test/cdn-bundle/test/cdnBundle.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { test, expect } from '@playwright/test';
2-
import { createSandboxAblyAPIKey } from '../lib/ablySandbox.js';
2+
import { createSandboxAblyAPIKey } from '../../lib/ablySandbox.js';
33

44
test.describe('CDN bundle', () => {
55
/**

test/cdn-bundle/test_cdn_bundle.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* test_cdn_bundle.ts:
3+
*
4+
* Tests the bundle that the .github/workflows/cdn.yml workflow will upload to the CDN.
5+
*
6+
* It does this by checking that a webpage which imports this bundle is able to create and use a Spaces client.
7+
*/
8+
9+
import playwright from 'playwright';
10+
import { createSandboxAblyAPIKey } from '../lib/ably_sandbox.js';
11+
import { startWebServer } from './lib/web_server.js';
12+
13+
async function runTest(testPageURL: URL) {
14+
const browser = await playwright.chromium.launch();
15+
const page = await browser.newPage();
16+
17+
page.on('console', (consoleMessage) => {
18+
console.log('[browser]', consoleMessage);
19+
});
20+
21+
const pageResultPromise = new Promise<void>((resolve, reject) => {
22+
page.exposeFunction('onResult', (error: Error | null) => {
23+
if (error) {
24+
console.log('Browser returned control to test runner, with error', error);
25+
reject(error);
26+
} else {
27+
console.log('Browser returned control to test runner');
28+
resolve();
29+
}
30+
});
31+
32+
page.exposeFunction('createSandboxAblyAPIKey', createSandboxAblyAPIKey);
33+
});
34+
35+
console.log('Running test in browser');
36+
37+
try {
38+
await page.goto(testPageURL.toString());
39+
await pageResultPromise;
40+
} finally {
41+
await browser.close();
42+
}
43+
}
44+
45+
(async () => {
46+
const port = 4567;
47+
const webServer = await startWebServer(port);
48+
49+
try {
50+
await runTest(new URL(`http://localhost:${port}`));
51+
} finally {
52+
await webServer.stop();
53+
}
54+
})();

test/cdn-bundle/lib/ablySandbox.ts renamed to test/lib/ablySandbox.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import https from 'node:https';
2-
import testAppSetup from '../../ably-common/test-resources/test-app-setup.json';
2+
import testAppSetup from '../ably-common/test-resources/test-app-setup.json';
33

44
export interface TestApp {
55
keys: TestAppKey[];

test/lib/tsconfig.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "../../tsconfig.base.json",
3+
"compilerOptions": {
4+
"resolveJsonModule": true
5+
}
6+
}

0 commit comments

Comments
 (0)