-
Notifications
You must be signed in to change notification settings - Fork 59
Add LiveObjects package test #1921
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
test/package/browser/template/server/resources/index-liveobjects.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title>Ably NPM package test (LiveObjects plugin export)</title> | ||
</head> | ||
<body> | ||
<script type="text/javascript" src="index-liveobjects.js"></script> | ||
<script type="text/javascript" src="runTest.js"></script> | ||
</body> | ||
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import * as Ably from 'ably'; | ||
import LiveObjects from 'ably/liveobjects'; | ||
import { createSandboxAblyAPIKey } from './sandbox'; | ||
|
||
globalThis.testAblyPackage = async function () { | ||
const key = await createSandboxAblyAPIKey({ featureFlags: ['enableChannelState'] }); | ||
|
||
const realtime = new Ably.Realtime({ key, environment: 'sandbox', plugins: { LiveObjects } }); | ||
|
||
const channel = realtime.channels.get('channel', { modes: ['STATE_SUBSCRIBE', 'STATE_PUBLISH'] }); | ||
// check liveObjects can be accessed | ||
const liveObjects = channel.liveObjects; | ||
await channel.attach(); | ||
// root should be a LiveMap object | ||
const root: Ably.LiveMap = await liveObjects.getRoot(); | ||
|
||
// check root is recognized as LiveMap TypeScript type | ||
root.get('someKey'); | ||
root.size(); | ||
VeskeR marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// check LiveMap subscription callback has correct TypeScript types | ||
const { unsubscribe } = root.subscribe(({ update }) => { | ||
switch (update.someKey) { | ||
case 'removed': | ||
case 'updated': | ||
break; | ||
default: | ||
// check all possible types are exhausted | ||
const shouldExhaustAllTypes: never = update.someKey; | ||
} | ||
}); | ||
unsubscribe(); | ||
|
||
VeskeR marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// check LiveCounter types also behave as expected | ||
const counter = root.get('randomKey') as Ably.LiveCounter | undefined; | ||
// use nullish coalescing as we didn't actually create a counter object on the root, | ||
// so the next calls would fail. we only need to check that TypeScript types work | ||
const value: number = counter?.value(); | ||
const counterSubscribeResponse = counter?.subscribe(({ update }) => { | ||
const shouldBeANumber: number = update.inc; | ||
}); | ||
counterSubscribeResponse?.unsubscribe(); | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.