Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/dev-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
submodules: true
- uses: actions/setup-node@v1
with:
node-version: 18
Expand Down
17 changes: 13 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@

## Test suite

### Setup

Before running the tests, you first need to initialize the repository’s submodules:

```
git submodule update --init
```

### Running the tests

To run the Jest tests, simply run the following command:

```bash
Expand All @@ -39,7 +49,6 @@ npm test

To test the bundle that we upload to the CDN:

1. Initialize submodules: `git submodule update --init`
2. Install browser for Playwright to use: `npx run playwright install chromium`
3. Build the bundle: `npm run build`
4. Run the test: `npm run test:cdn-bundle`
1. Install browser for Playwright to use: `npx run playwright install chromium`
2. Build the bundle: `npm run build`
3. Run the test: `npm run test:cdn-bundle`
2 changes: 1 addition & 1 deletion test/cdn-bundle/test/cdnBundle.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test, expect } from '@playwright/test';
import { createSandboxAblyAPIKey } from '../lib/ablySandbox.js';
import { createSandboxAblyAPIKey } from '../../lib/ablySandbox.js';

test.describe('CDN bundle', () => {
/**
Expand Down
610 changes: 610 additions & 0 deletions test/integration/integration.test.ts

Large diffs are not rendered by default.

36 changes: 36 additions & 0 deletions test/integration/utilities/setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Realtime } from 'ably';
import { nanoid } from 'nanoid';
import { createSandboxAblyAPIKey } from '../../lib/ablySandbox.js';
import Spaces from '../../../src/Spaces.js';

/**
* Fetches a key for the Ably sandbox environment. This key is shared between all callers of this function.
*/
const fetchSharedSandboxKey = (() => {
const sandboxKeyPromise = createSandboxAblyAPIKey();

return async () => {
return await sandboxKeyPromise;
};
})();

/**
* Performs the following part of a test setup:
*
* > Given $count Spaces clients, all configured to use the same API key, and each configured to use a different randomly-generated client ID...
*/
export async function createClients({ count }: { count: number }) {
const sandboxKey = await fetchSharedSandboxKey();

return Array.from({ length: count }, () => {
const clientId = nanoid();
const realtime = new Realtime.Promise({
environment: 'sandbox',
key: sandboxKey,
clientId: clientId,
});
const spaces = new Spaces(realtime);

return { spaces: spaces, clientId: clientId };
});
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import https from 'node:https';
import testAppSetup from '../../ably-common/test-resources/test-app-setup.json';
import testAppSetup from '../ably-common/test-resources/test-app-setup.json';

export interface TestApp {
keys: TestAppKey[];
Expand Down
6 changes: 6 additions & 0 deletions test/lib/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"resolveJsonModule": true
}
}