From 15783134942cdfac033333fc30969f6d1cc495c0 Mon Sep 17 00:00:00 2001 From: Rayron Victor Date: Mon, 22 Oct 2018 21:46:22 -0300 Subject: [PATCH] fix e2e tests when `PORT` is set in `.env` (#2634) * SelectLang: languages options don't need to be translated * fix e2e tests when `PORT` is set in `.env` --- src/e2e/home.e2e.js | 4 +++- src/e2e/layout.e2e.js | 4 +++- src/e2e/login.e2e.js | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/e2e/home.e2e.js b/src/e2e/home.e2e.js index 20763ff6..914ed7c1 100644 --- a/src/e2e/home.e2e.js +++ b/src/e2e/home.e2e.js @@ -1,10 +1,12 @@ import puppeteer from 'puppeteer'; +const BASE_URL = `http://localhost:${process.env.PORT || 8000}`; + describe('Homepage', () => { it('it should have logo text', async () => { const browser = await puppeteer.launch({ args: ['--no-sandbox'] }); const page = await browser.newPage(); - await page.goto('http://localhost:8000', { waitUntil: 'networkidle2' }); + await page.goto(BASE_URL, { waitUntil: 'networkidle2' }); await page.waitForSelector('#logo h1'); const text = await page.evaluate(() => document.body.innerHTML); expect(text).toContain('

Ant Design Pro

'); diff --git a/src/e2e/layout.e2e.js b/src/e2e/layout.e2e.js index af1d2b33..fa5edfd2 100644 --- a/src/e2e/layout.e2e.js +++ b/src/e2e/layout.e2e.js @@ -1,6 +1,8 @@ import puppeteer from 'puppeteer'; import RouterConfig from '../../config/router.config'; +const BASE_URL = `http://localhost:${process.env.PORT || 8000}`; + function formatter(data) { return data .reduce((pre, item) => { @@ -22,7 +24,7 @@ describe('Homepage', () => { const loadPage = async index => { const path = layout[index]; try { - await page.goto(`http://localhost:8000${path}`, { waitUntil: 'networkidle2' }); + await page.goto(`${BASE_URL}${path}`, { waitUntil: 'networkidle2' }); const haveFooter = await page.evaluate( () => document.getElementsByTagName('footer').length > 0 ); diff --git a/src/e2e/login.e2e.js b/src/e2e/login.e2e.js index 2ecb3fe7..366de8cc 100644 --- a/src/e2e/login.e2e.js +++ b/src/e2e/login.e2e.js @@ -1,5 +1,7 @@ import puppeteer from 'puppeteer'; +const BASE_URL = `http://localhost:${process.env.PORT || 8000}`; + describe('Login', () => { let browser; let page; @@ -10,7 +12,7 @@ describe('Login', () => { beforeEach(async () => { page = await browser.newPage(); - await page.goto('http://localhost:8000/user/login', { waitUntil: 'networkidle2' }); + await page.goto(`${BASE_URL}/user/login`, { waitUntil: 'networkidle2' }); await page.evaluate(() => window.localStorage.setItem('antd-pro-authority', 'guest')); }); -- GitLab