From da0d381386bace62e86d6115529e8d98fcbae027 Mon Sep 17 00:00:00 2001 From: Maximilian Stoiber Date: Mon, 11 Dec 2017 10:27:12 +0100 Subject: [PATCH] Run e2e tests against server-side rendered site This should help us catch more errors in our server-side rendering setup. (like infinite loops) This requires an update to our Codeship config, don't be surprised if the tests fail here at first! Closes #2132 --- docs/testing.md | 27 ++++++++++++++++++++++++--- hyperion/index.js | 10 +++++++--- src/test-e2e/channel.test.js | 2 +- src/test-e2e/community.test.js | 2 +- src/test-e2e/inbox.test.js | 2 +- src/test-e2e/login.test.js | 2 +- src/test-e2e/splash.test.js | 2 +- src/test-e2e/thread.test.js | 2 +- src/test-e2e/user.test.js | 2 +- 9 files changed, 38 insertions(+), 13 deletions(-) diff --git a/docs/testing.md b/docs/testing.md index 8d2b3f70f9..04f6bbfc79 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -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 diff --git a/hyperion/index.js b/hyperion/index.js index 13473ed7fe..c33059b65c 100644 --- a/hyperion/index.js +++ b/hyperion/index.js @@ -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(); @@ -40,7 +44,7 @@ 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}` ); }); @@ -48,7 +52,7 @@ 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}` ); }); @@ -56,7 +60,7 @@ 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}` ); }); diff --git a/src/test-e2e/channel.test.js b/src/test-e2e/channel.test.js index 190657b96e..35b599d81a 100644 --- a/src/test-e2e/channel.test.js +++ b/src/test-e2e/channel.test.js @@ -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 diff --git a/src/test-e2e/community.test.js b/src/test-e2e/community.test.js index 9f305131ec..a1c3331c03 100644 --- a/src/test-e2e/community.test.js +++ b/src/test-e2e/community.test.js @@ -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 diff --git a/src/test-e2e/inbox.test.js b/src/test-e2e/inbox.test.js index 6d08de3e46..5f8adb56ed 100644 --- a/src/test-e2e/inbox.test.js +++ b/src/test-e2e/inbox.test.js @@ -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 diff --git a/src/test-e2e/login.test.js b/src/test-e2e/login.test.js index f5856c6553..c6f5297a2e 100644 --- a/src/test-e2e/login.test.js +++ b/src/test-e2e/login.test.js @@ -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 diff --git a/src/test-e2e/splash.test.js b/src/test-e2e/splash.test.js index 3ff77afcbd..d28c044945 100644 --- a/src/test-e2e/splash.test.js +++ b/src/test-e2e/splash.test.js @@ -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 diff --git a/src/test-e2e/thread.test.js b/src/test-e2e/thread.test.js index a528832ebb..f23e7e9864 100644 --- a/src/test-e2e/thread.test.js +++ b/src/test-e2e/thread.test.js @@ -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 diff --git a/src/test-e2e/user.test.js b/src/test-e2e/user.test.js index 91203d4b2f..508dec187e 100644 --- a/src/test-e2e/user.test.js +++ b/src/test-e2e/user.test.js @@ -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