Skip to content
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

[ECO-4114] Fix missing ably/react export from ably package on v2 branch #1625

Merged
merged 8 commits into from
Feb 26, 2024
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
"./modules": {
"types": "./modules.d.ts",
"default": "./build/modules/index.js"
},
"./react": {
"require": "./react/cjs/index.js",
"import": "./react/mjs/index.js"
}
},
"typings": "./ably.d.ts",
Expand Down
6 changes: 1 addition & 5 deletions src/platform/react-hooks/res/package.react.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
{
"main": "./cjs/index.js",
"exports": {
"require": "./cjs",
"import": "./mjs"
}
"main": "./cjs/index.js"
}
6 changes: 6 additions & 0 deletions test/package/browser/template/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dist
node_modules/
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
13 changes: 9 additions & 4 deletions test/package/browser/template/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,26 @@ This directory is intended to be used for testing the following aspects of the a
- that its exports are correctly configured and provide access to ably-js’s functionality
- that its TypeScript typings are correctly configured and can be successfully used from a TypeScript-based app that imports the package

It contains two files, each of which import ably-js in different manners, and which export a function which briefly exercises its functionality:
It contains three files, each of which import ably-js in different manners, and provide a way to briefly exercise its functionality:

- `src/index-default.ts` imports the default ably-js package (`import { Realtime } from 'ably'`).
- `src/index-modules.ts` imports the tree-shakable ably-js package (`import { BaseRealtime, WebSocketTransport, FetchRequest } from 'ably/modules'`).
- `src/ReactApp.tsx` imports React hooks from the ably-js package (`import { useChannel } from 'ably/react'`).

## Why is `ably` not in `package.json`?

The `ably` dependency gets added when we run the repository’s `test:package` package script. That script copies the contents of this `template` directory to a new temporary directory, and then adds the `ably` dependency to the copy. We do this so that we can check this directory’s `package-lock.json` into Git, without needing to modify it whenever ably-js’s dependencies change.

## React hooks tests

To test hooks imported from `ably/react` in React components, we used [Playwright for components](https://playwright.dev/docs/test-components). The main logic sits in `src/ReactApp.tsx`, and `AblyProvider` is configured in `playwright/index.tsx` file based on [this guide](https://playwright.dev/docs/test-components#hooks).

## Package scripts

This directory exposes three package scripts that are to be used for testing:

- `build`: Uses esbuild to create:
1. a bundle containing `src/index-default.ts` and ably-js;
2. a bundle containing `src/index-modules.ts` and ably-js.
- `test`: Using the bundles created by `build`, tests that the code that exercises ably-js’s functionality is working correctly in a browser.
1. a bundle containing `src/index-default.ts` and ably-js;
2. a bundle containing `src/index-modules.ts` and ably-js.
- `test`: Using the bundles created by `build` and playwright components setup, tests that the code that exercises ably-js’s functionality is working correctly in a browser.
- `typecheck`: Type-checks the code that imports ably-js.
Loading
Loading