Skip to content

Docs snippets tests - #538

Open
techwritermat wants to merge 8 commits into
masterfrom
docs-snippets-live-tests
Open

techwritermat wants to merge 8 commits into
masterfrom
docs-snippets-live-tests

Conversation

@techwritermat

Copy link
Copy Markdown
Contributor

No description provided.

@pubnub-snyk-universal-prd

pubnub-snyk-universal-prd Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

✅ Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues
✅ Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

techwritermat and others added 4 commits November 4, 2026 12:40
- Added a new test to verify occupant visibility through channel groups in presence.ts, addressing potential timing issues in CI.
- Refactored exitWhenIdle function in cli.ts to provide clearer error messages when the event loop remains busy, and introduced a new describeHandles function to detail active handles and resources.
…tions

- Updated the exitWhenIdle function in cli.ts to provide clearer warnings when only timers are keeping the event loop busy.
- Added unref() calls in wait.ts to ensure abandoned timers do not prevent process exit after tests complete.
The presence fixture now waits until each channel group (cg1,
my_channel_group) and the ch1 plus cg1 combination list the occupant.
A group read resolves the group's member channels first and can lag
the per-channel reads, which made hereNowBasicUsage fail in CI.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Five steps read back what the docs sample just wrote, from another
client, in one shot. App Context reads lag behind writes, and on the
fast CI runner setMembershipBasicUsage read an empty list. The same
assertions now run inside eventually().

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
techwritermat and others added 3 commits November 5, 2026 09:41
- Introduced a new script `snippet-summary.cjs` to generate a Markdown summary of snippet results per ID for GitHub Actions.
- Updated `package.json` to include a new command for running the summary script.
- Modified GitHub Actions workflows to utilize the new summary script and adjusted checkout actions for consistency.
- Enhanced error handling in `mocha-entry.ts` to ensure all keysets are processed, even if some fail.

This improves visibility into snippet test results and ensures comprehensive reporting in CI runs.
- Revised multiple snippets and README entries to specify that React and React Native sources cannot be run in this repository due to the absence of necessary dependencies.
- Adjusted comments and documentation to reflect that the snippets are retained for documentation purposes only and are type-checked but not executed.
- Enhanced clarity in various files regarding the environment setup and execution context for the snippets.

This improves the accuracy of documentation and helps users understand the limitations of running certain snippets.

@parfeon parfeon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly looks good.

live: ${{ steps.diff.outputs.live }}
steps:
- name: Checkout repository
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is brutal. We actually can at least trust official GitHub account to deliver stable products.
Current checkout is v7

# of its own role only. The janitor step after them needs every role, so it keeps all of them.
- name: Shard open
id: open
if: success() || failure()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so, we will still run this step event previous setup steps failed? Does it really make sense?

Comment on lines +13 to +27
function SubscribedComponent() {
useEffect(() => {
const channel = pubnub.channel('my_channel');
const subscription = channel.subscription({
receivePresenceEvents: true,
});
subscription.subscribe();

return () => {
subscription.unsubscribe();
};
}, []);

return <div>Subscribed to my_channel</div>;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Subscription is asynchronous process and it won't be really truthful to report Subscribed to my_channel right away.

Suggested change
function SubscribedComponent() {
useEffect(() => {
const channel = pubnub.channel('my_channel');
const subscription = channel.subscription({
receivePresenceEvents: true,
});
subscription.subscribe();
return () => {
subscription.unsubscribe();
};
}, []);
return <div>Subscribed to my_channel</div>;
}
function SubscribedComponent() {
const [isSubscribed, setIsSubscribed] = useState(false);
useEffect(() => {
const channel = pubnub.channel('my_channel');
const subscription = channel.subscription({
receivePresenceEvents: true,
});
subscription.onStatus = (statusEvent) => {
if (statusEvent.category === 'PNConnectedCategory') {
setIsSubscribed(true);
}
};
subscription.subscribe();
return () => {
subscription.unsubscribe();
};
}, []);
if (!isSubscribed) {
return <div>Connecting to channel...</div>;
}
return <div>Subscribed to my_channel</div>;
}

setPresenceState();
}, []);

return <div>User with presence state</div>;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it show progress as it has been shown with react-subscribe.jsx?

Comment on lines +43 to +44
const channel = pubnub.channel('hello_world');
const subscription = channel.subscription();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we show it in the following way:

Suggested change
const channel = pubnub.channel('hello_world');
const subscription = channel.subscription();
const subscription = pubnub.channel('hello_world').subscription();

<head>
<meta charset="utf-8" />
<title>PubNub quickstart</title>
<script src="https://cdn.pubnub.com/sdk/javascript/pubnub.13.1.3.js"></script>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could become invalid really soon.
Version bumping available through the release process but it requires modification in this file.

// snippet.hide
// @ts-expect-error the shipped types lack subscriptionWorkerUrl (SDK bug, STATUS.md)
// snippet.show
subscriptionWorkerUrl: 'https://www.my-domain.com/static/js/pubnub.worker.9.6.0.js',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need in separate .d.ts especially when it can't be used directly inside of HTML page.
Not minified version from the CDN has a JSDoc for functions and they list field.
WebStorm IDE were able to assist me:

Image

Currently we have whole codebase written with TypeScript, so other environments see types without any issues.

So I don't know why SDK bug. It was intentional decision.

// have proper html element to display the file
const myImageTag = document.createElement('img');
// snippet.hide
// @ts-expect-error the shipped types declare toFile(): Promise<void>, the browser returns a File (SDK bug, STATUS.md)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What exact SDK bug mentioned here?
TypeScript has infer capability and generics, that function for web version of the PubNubFile looks like this:
Image

So it actually returns Promise<File>.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants