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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: React frameworks compatibility automation #1719

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
f190823
chore: script to test if the lib works in nextjs
petyosi Aug 19, 2022
8bbd874
chore: test remix app
petyosi Aug 19, 2022
4ad4d15
test(Vite): add Vite setup
arnautov-anton Aug 25, 2022
d6b0c19
test: move Remix and Next to separate directories
arnautov-anton Aug 25, 2022
e95cc7c
chore: update .gitignore
arnautov-anton Aug 25, 2022
caffe42
chore: separate package packing from test scripts
arnautov-anton Aug 25, 2022
3615384
test: update index files to use .env variables
arnautov-anton Aug 25, 2022
f71b666
ci(test-react-frameworks): added CI job
arnautov-anton Aug 25, 2022
cb65b3d
test: update Next and Remix (.sh) paths
arnautov-anton Aug 25, 2022
8666943
ci: move enviroment variables, add Playwright caching
arnautov-anton Aug 26, 2022
f340e1d
test(Vite): generate .env file
arnautov-anton Aug 26, 2022
a9c5aab
chore(Jest): ignore test-react-frameworks folder
arnautov-anton Aug 26, 2022
354d4a5
ci: add Playwright caching to end-to-end tests
arnautov-anton Aug 26, 2022
02b7df6
ci: fix Playwright caching mechanism
arnautov-anton Aug 30, 2022
e8cff10
test(Vite): add EmojiProvider to trigger dynamic imports
arnautov-anton Aug 31, 2022
4dff8b1
test(Next): update next.sh script and index page, add end-to-end test
arnautov-anton Nov 11, 2022
154278a
ci: remove unused condition from Playwright cache step
arnautov-anton Nov 11, 2022
779c25b
test(Remix): update remix.sh script and index page, add end-to-end test
arnautov-anton Nov 11, 2022
8933e51
ci: upgrade runner for the end-to-end tests
arnautov-anton Nov 11, 2022
1b5f055
ci: upgrade runner for the end-to-end tests (to self-hosted)
arnautov-anton Nov 17, 2022
e976d7e
tmp
arnautov-anton Nov 17, 2022
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
63 changes: 60 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@ jobs:
run: yarn types --noEmit

e2e:
runs-on: ubuntu-latest
runs-on: self-hosted
name: End-to-end tests
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18

- name: 馃捑 Cache Dependencies
uses: actions/cache@v3
Expand All @@ -38,10 +41,22 @@ jobs:
- name: 馃敤 Install Dependencies
run: yarn install --frozen-lockfile --ignore-engines --ignore-scripts

- name: 馃捑 Cache Playwright browsers
uses: actions/cache@v3
id: playwright-cache
with:
path: ~/.cache/ms-playwright
key: ${{ runner.os }}${{ runner.arch }}-playwright-browsers

- name: Install Playwright browsers if not cached
if: steps.playwright-cache.outputs.cache-hit != 'true'
run: npx playwright install chromium webkit firefox

- name: Install Playwright system dependencies (always)
run: npx playwright install-deps

- name: 鈿楋笍 End-to-end tests
run: |
npx playwright install
npx playwright install-deps
yarn e2e-fixtures
# running with --browser=all causes failures
yarn e2e --browser=chromium
Expand Down Expand Up @@ -99,3 +114,45 @@ jobs:

- name: 馃И Validate CommonJS bundle with ${{ matrix.node }}
run: yarn validate-cjs
test-frameworks:
runs-on: ubuntu-latest
strategy:
matrix:
framework: ["next", "remix", "vite"]
name: Test with framework ${{ matrix.framework }}
env:
STREAM_API_KEY: ${{ secrets.E2E_APP_KEY }}
USER_ID: test-user-1
USER_TOKEN: ${{ secrets.E2E_TEST_USER_1_TOKEN }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/cache@v3
id: node-modules-cache
with:
path: ./node_modules
key: ${{ runner.os }}-node-modules-${{ hashFiles('./yarn.lock') }}

- name: Install packages
run: yarn install --frozen-lockfile --ignore-engines

- uses: actions/cache@v3
id: playwright-cache
with:
path: ~/.cache/ms-playwright
key: ${{ runner.os }}${{ runner.arch }}-playwright-browsers

- name: Install Playwright browsers if not cached
if: steps.playwright-cache.outputs.cache-hit != 'true'
run: npx playwright install chromium webkit firefox

- name: Install Playwright system dependencies (always)
run: npx playwright install-deps

- name: Pack package (stream-chat-react.tgz)
working-directory: ./test-react-frameworks
run: ./pack-package.sh

- name: Run ${{ matrix.framework }}.sh test
working-directory: ./test-react-frameworks/${{ matrix.framework }}
run: ./${{ matrix.framework }}.sh
8 changes: 7 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ module.exports = {
},
preset: 'ts-jest',
setupFiles: ['core-js'],
testPathIgnorePatterns: ['/node_modules/', '/examples/', '__snapshots__', '/e2e/'],
testPathIgnorePatterns: [
'/node_modules/',
'/examples/',
'__snapshots__',
'/e2e/',
'/test-react-frameworks/',
],
testRegex: [
/**
* If you want to test single file, mention it here
Expand Down
4 changes: 4 additions & 0 deletions test-react-frameworks/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
stream-chat-react.tgz
next/test-next-app
remix/test-remix-app
vite/test-vite-app
58 changes: 58 additions & 0 deletions test-react-frameworks/next/next-page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// @ts-nocheck

import { NextPage } from 'next';
import React, { useEffect, useState } from 'react';

import { StreamChat } from 'stream-chat';
import {
Channel,
ChannelHeader,
ChannelList,
Chat,
MessageInput,
MessageList,
Thread,
Window,
} from 'stream-chat-react';

const Home: NextPage = ({ apiKey, userId, userToken }) => {
const [client, setClient] = useState<StreamChat | null>(null);

const filters: ChannelFilters = { members: { $in: [userId] }, type: 'messaging' };
const options: ChannelOptions = { limit: 10, presence: true, state: true };
const sort: ChannelSort = { last_message_at: -1, updated_at: -1 };

useEffect(() => {
const chatClient = StreamChat.getInstance(apiKey);

chatClient.connectUser({ id: userId }, userToken).then(() => setClient(chatClient));
}, []);

if (client === null) {
return <div>Loading</div>;
}

return (
<Chat client={client}>
<ChannelList filters={filters} options={options} sort={sort} />
<Channel>
<Window>
<ChannelHeader />
<MessageList />
<MessageInput focus />
</Window>
<Thread />
</Channel>
</Chat>
);
};

Home.getInitialProps = () => {
const apiKey = process.env.NEXT_STREAM_API_KEY;
const userId = process.env.NEXT_USER_ID;
const userToken = process.env.NEXT_USER_TOKEN;

return { apiKey, userId, userToken };
};

export default Home;
23 changes: 23 additions & 0 deletions test-react-frameworks/next/next.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

FOLDER_NAME="test-next-app"
PACKAGE_PATH="../../stream-chat-react.tgz"

rm -rf $FOLDER_NAME

yarn create next-app --typescript $FOLDER_NAME --no-eslint

# Apply a hello-world chat page to the project.
cp ./next-page.tsx $FOLDER_NAME/pages/index.tsx

# install the lib...
yarn --cwd ./$FOLDER_NAME add --dev $PACKAGE_PATH stream-chat

echo NEXT_USER_ID=$USER_ID >> $FOLDER_NAME/.env.local
echo NEXT_USER_TOKEN=$USER_TOKEN >> $FOLDER_NAME/.env.local
echo NEXT_STREAM_API_KEY=$STREAM_API_KEY >> $FOLDER_NAME/.env.local

# and build - $? should be 0
yarn --cwd ./test-next-app build --no-lint

npx playwright test --config ./playwright.config.ts ./next.test.ts
19 changes: 19 additions & 0 deletions test-react-frameworks/next/next.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* eslint-disable jest/require-top-level-describe */
/* eslint-disable jest/no-done-callback */

import { expect, test } from '@playwright/test';

test.describe('Next', () => {
test('MessageList rendered', async ({ page }) => {
page.on('console', (message) => console.log('NEXT_LOGS: ', message.text()));

await Promise.all([
page.waitForSelector('#__next'),
page.waitForLoadState('networkidle'),
page.goto('/'),
]);

const list = page.locator('.str-chat__list');
await expect(list).toBeVisible();
});
});
16 changes: 16 additions & 0 deletions test-react-frameworks/next/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { PlaywrightTestConfig } from '@playwright/test';

export default {
timeout: 15 * 1000,
use: {
baseURL: 'http://localhost:3000',
browserName: 'chromium',
headless: true,
},
webServer: {
command: 'yarn --cwd ./test-next-app dev',
port: 3000,
reuseExistingServer: !process.env.CI,
timeout: 15 * 1000,
},
} as PlaywrightTestConfig;
6 changes: 6 additions & 0 deletions test-react-frameworks/pack-package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

# pack stream-chat-react. Linking causes issues with React.
FILE_NAME="stream-chat-react.tgz"
rm -rf ./$FILE_NAME
yarn pack --cwd "../" -f $FILE_NAME
16 changes: 16 additions & 0 deletions test-react-frameworks/remix/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { PlaywrightTestConfig } from '@playwright/test';

export default {
timeout: 15 * 1000,
use: {
baseURL: 'http://localhost:3000',
browserName: 'chromium',
headless: true,
},
webServer: {
command: 'yarn --cwd ./test-remix-app start',
port: 3000,
reuseExistingServer: !process.env.CI,
timeout: 30 * 1000,
},
} as PlaywrightTestConfig;
64 changes: 64 additions & 0 deletions test-react-frameworks/remix/remix-index-route.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// @ts-nocheck

import { json, LinksFunction } from '@remix-run/node';
import { useLoaderData } from '@remix-run/react';
import React from 'react';

import { StreamChat } from 'stream-chat';
import {
Channel,
ChannelHeader,
ChannelList,
Chat,
MessageInput,
MessageList,
Thread,
Window,
} from 'stream-chat-react';

// eslint-disable-next-line require-await
export async function loader() {
return json({
apiKey: process.env.REMIX_STREAM_API_KEY,
userId: process.env.REMIX_USER_ID,
userToken: process.env.REMIX_USER_TOKEN,
});
}

import stream from 'stream-chat-react/dist/css/index.css';

export const links: LinksFunction = () => [{ href: stream, rel: 'stylesheet' }];

export default function Index() {
const { apiKey, userId, userToken } = useLoaderData();

const filters: ChannelFilters = { members: { $in: [userId] }, type: 'messaging' };
const options: ChannelOptions = { limit: 10, presence: true, state: true };
const sort: ChannelSort = { last_message_at: -1, updated_at: -1 };

const [client, setClient] = React.useState<StreamChat | null>(null);

React.useEffect(() => {
const chatClient = StreamChat.getInstance(apiKey);

chatClient.connectUser({ id: userId }, userToken).then(() => setClient(chatClient));
}, []);

if (client === null) {
return <div>Loading</div>;
}

return (
<Chat client={client}>
<ChannelList filters={filters} options={options} sort={sort} />
<Channel>
<Window>
<ChannelHeader />
<MessageList />
<MessageInput focus />
</Window>
<Thread />
</Channel>
</Chat>
);
}
23 changes: 23 additions & 0 deletions test-react-frameworks/remix/remix.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

FOLDER_NAME="test-remix-app"
PACKAGE_PATH="../../stream-chat-react.tgz"

rm -rf $FOLDER_NAME

yes | yarn create remix --template remix-run/indie-stack $FOLDER_NAME

# Apply a hello-world chat page to the project.
cp ./remix-index-route.tsx $FOLDER_NAME/app/routes/index.tsx

# install the lib...
yarn --cwd ./$FOLDER_NAME add --dev $PACKAGE_PATH stream-chat

echo REMIX_USER_ID=$USER_ID >> $FOLDER_NAME/.env
echo REMIX_USER_TOKEN=$USER_TOKEN >> $FOLDER_NAME/.env
echo REMIX_STREAM_API_KEY=$STREAM_API_KEY >> $FOLDER_NAME/.env

# and build - $? should be 0
yarn --cwd ./$FOLDER_NAME build

npx playwright test --config ./playwright.config.ts ./remix.test.ts
19 changes: 19 additions & 0 deletions test-react-frameworks/remix/remix.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* eslint-disable jest/require-top-level-describe */
/* eslint-disable jest/no-done-callback */

import { expect, test } from '@playwright/test';

test.describe('Remix', () => {
test('MessageList rendered', async ({ page }) => {
page.on('console', (message) => console.log('REMIX_LOGS: ', message.text()));

await Promise.all([
page.waitForSelector('.h-full'),
page.waitForLoadState('networkidle'),
page.goto('/'),
]);

const list = page.locator('.str-chat__list');
await expect(list).toBeVisible();
});
});
Loading