Skip to content
This repository was archived by the owner on Oct 11, 2022. It is now read-only.
Closed
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
27 changes: 24 additions & 3 deletions docs/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,34 @@ In edge cases it could happen that you end up with bad data locally and that tes

### End-to-end tests

To run e2e tests locally you have to have both iris and the client running. You also need Iris to be connected to the test database, which you do by setting `TEST_DB`:
e2e tests should run against our production setup in order to simulate a users experience as closely as possible. This includes the built versions of all code, but also server-side rendering.

To that end, there is a couple points you need to take care of to run them locally:

1. You need to have a built version of the client, hyperion and iris
2. You need to have the production versions of hyperion and iris running, with Iris connection to the test database and both of them connecting to the local versions of all services
3. You need to run tests with `E2E=true`

Let's get these done in order. First, let's build all the things:

```sh
# Important: Building the client has to happen before building hyperion
yarn run build:client
yarn run build:hyperion
yarn run build:iris
```

Then, let's get Iris up and running against the test database and hyperion started:

```sh
TEST_DB=true yarn run dev:iris
TEST_DB=true FORCE_DEV=true yarn run start:iris
# In a second tab, start hyperion
FORCE_DEV=true yarn run start
```

Then, with both client and iris connected to the test database running, to run the full test suite including e2e tests:
> Note: The `FORCE_DEV` environment variable takes care of connecting these servers to their local services

Finally, let's run our e2e tests:

```sh
E2E=true yarn run test
Expand Down
10 changes: 7 additions & 3 deletions hyperion/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import { getUser } from 'iris/models/user';
import Raven from 'shared/raven';

const PORT = process.env.PORT || 3006;
const FORCE_DEV = process.env.FORCE_DEV;
const BASE_DOMAIN = FORCE_DEV
? 'http://localhost:3001'
: 'https://spectrum.chat';

const app = express();

Expand Down Expand Up @@ -40,23 +44,23 @@ app.use('/api', (req: express$Request, res: express$Response) => {
const redirectUrl = `${req.baseUrl}${req.path}`;
res.redirect(
req.method === 'POST' || req.xhr ? 307 : 301,
`https://spectrum.chat${redirectUrl}`
`${BASE_DOMAIN}${redirectUrl}`
);
});

app.use('/auth', (req: express$Request, res: express$Response) => {
const redirectUrl = `${req.baseUrl}${req.path}`;
res.redirect(
req.method === 'POST' || req.xhr ? 307 : 301,
`https://spectrum.chat${redirectUrl}`
`${BASE_DOMAIN}${redirectUrl}`
);
});

app.use('/websocket', (req: express$Request, res: express$Response) => {
const redirectUrl = `${req.baseUrl}${req.path}`;
res.redirect(
req.method === 'POST' || req.xhr ? 307 : 301,
`https://spectrum.chat${redirectUrl}`
`${BASE_DOMAIN}${redirectUrl}`
);
});

Expand Down
2 changes: 1 addition & 1 deletion src/test-e2e/channel.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ beforeAll(async () => {
browser = await puppeteer.launch(config);
page = await browser.newPage();
// Navigate the page to the login page for all tests
await page.goto(`http://localhost:3000/${community.slug}/${channel.slug}`);
await page.goto(`http://localhost:3006/${community.slug}/${channel.slug}`);
});

// Afterwards close the browser
Expand Down
2 changes: 1 addition & 1 deletion src/test-e2e/community.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ beforeAll(async () => {
browser = await puppeteer.launch(config);
page = await browser.newPage();
// Navigate the page to the login page for all tests
await page.goto(`http://localhost:3000/${community.slug}`);
await page.goto(`http://localhost:3006/${community.slug}`);
});

// Afterwards close the browser
Expand Down
2 changes: 1 addition & 1 deletion src/test-e2e/inbox.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ beforeAll(async () => {
secure: false,
});
// Navigate the page to the inbox page for all tests
await page.goto('http://localhost:3000/');
await page.goto('http://localhost:3006/');
});

// Afterwards close the browser
Expand Down
2 changes: 1 addition & 1 deletion src/test-e2e/login.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ beforeAll(async () => {
browser = await puppeteer.launch(config);
page = await browser.newPage();
// Navigate the page to the login page for all tests
await page.goto('http://localhost:3000/login');
await page.goto('http://localhost:3006/login');
});

// Afterwards close the browser
Expand Down
2 changes: 1 addition & 1 deletion src/test-e2e/splash.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ beforeAll(async () => {
browser = await puppeteer.launch(config);
page = await browser.newPage();
// Navigate the page to the splash page for all tests
await page.goto('http://localhost:3000/');
await page.goto('http://localhost:3006/');
});

// Afterwards close the browser
Expand Down
2 changes: 1 addition & 1 deletion src/test-e2e/thread.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ beforeAll(async () => {
browser = await puppeteer.launch(config);
page = await browser.newPage();
// Navigate the page to the login page for all tests
await page.goto(`http://localhost:3000/thread/${thread.id}`);
await page.goto(`http://localhost:3006/thread/${thread.id}`);
});

// Afterwards close the browser
Expand Down
2 changes: 1 addition & 1 deletion src/test-e2e/user.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ beforeAll(async () => {
browser = await puppeteer.launch(config);
page = await browser.newPage();
// Navigate the page to the login page for all tests
await page.goto(`http://localhost:3000/users/${user.username}`);
await page.goto(`http://localhost:3006/users/${user.username}`);
});

// Afterwards close the browser
Expand Down