未验证 提交 e876ec20 编写于 作者: 陈帅 提交者: GitHub

fix test (#2825)

上级 5beacedd
......@@ -2,14 +2,14 @@ version: 2
jobs:
build:
docker:
- image: circleci/node:8.11.4
- image: circleci/node:latest
steps:
- checkout
- run: npm install
- run: npm run build
test:
docker:
- image: circleci/node:8.11.4
- image: circleci/node:latest
steps:
- checkout
- run: sh ./tests/fix_puppeteer.sh
......
......@@ -11,6 +11,7 @@ module.exports = {
},
globals: {
APP_TYPE: true,
page: true,
},
rules: {
'react/jsx-filename-extension': [1, { extensions: ['.js'] }],
......
FROM node:latest
FROM circleci/node:latest
WORKDIR /usr/src/app/
USER root
COPY package.json ./
RUN npm install --silent --no-cache
RUN yarn
COPY ./ ./
......
......@@ -23,6 +23,8 @@ export default config => {
varFile: path.join(__dirname, '../node_modules/antd/lib/style/themes/default.less'),
mainLessFile: outFile, // themeVariables: ['@primary-color'],
indexFileName: 'index.html',
generateOne: true,
lessUrl: 'https://gw.alipayobjects.com/os/lib/less.js/3.8.1/less.min.js',
},
]);
};
module.exports = {
testURL: 'http://localhost:8000',
preset: 'jest-puppeteer',
};
import RouterConfig from '../../config/router.config';
const BASE_URL = `http://localhost:${process.env.PORT || 8000}`;
function formatter(data) {
return data
.reduce((pre, item) => {
pre.push(item.path);
return pre;
}, [])
.filter(item => item);
}
describe('Homepage', async () => {
const testPage = path =>
new Promise(async reslove => {
console.log(`test ${path}`);
await page.goto(`${BASE_URL}${path}`, {
timeout: 600000,
});
await page.waitForSelector('footer', {
timeout: 600000,
});
reslove();
});
beforeAll(async () => {
jest.setTimeout(1000000);
await page.setCacheEnabled(false);
});
it(`test pages`, async () => {
const routers = formatter(RouterConfig[1].routes);
const testAll = index =>
new Promise(async reslove => {
await testPage(routers[index]);
if (index < routers.length - 1) {
const newIndex = index + 1;
await testAll(newIndex);
reslove();
}
reslove();
});
await testAll(0);
});
});
import puppeteer from 'puppeteer';
const BASE_URL = `http://localhost:${process.env.PORT || 8000}`;
describe('Homepage', () => {
......@@ -7,13 +5,11 @@ describe('Homepage', () => {
jest.setTimeout(1000000);
});
it('it should have logo text', async () => {
const browser = await puppeteer.launch({ args: ['--no-sandbox'] });
const page = await browser.newPage();
await page.goto(BASE_URL, { waitUntil: 'networkidle2' });
await page.goto(BASE_URL);
await page.waitForSelector('h1', {
timeout: 2000,
});
const text = await page.evaluate(() => document.getElementsByTagName('h1')[0].innerText);
expect(text).toContain('Ant Design Pro');
await page.close();
browser.close();
});
});
import puppeteer from 'puppeteer';
const BASE_URL = `http://localhost:${process.env.PORT || 8000}`;
describe('Login', () => {
let browser;
let page;
beforeAll(async () => {
jest.setTimeout(1000000);
browser = await puppeteer.launch({ args: ['--no-sandbox'] });
});
beforeEach(async () => {
page = await browser.newPage();
await page.goto(`${BASE_URL}/user/login`, { waitUntil: 'networkidle2' });
await page.evaluate(() => window.localStorage.setItem('antd-pro-authority', 'guest'));
});
afterEach(() => page.close());
it('should login with failure', async () => {
await page.waitForSelector('#userName', {
timeout: 2000,
......@@ -40,6 +31,4 @@ describe('Login', () => {
const text = await page.evaluate(() => document.body.innerHTML);
expect(text).toContain('<h1>Ant Design Pro</h1>');
});
afterAll(() => browser.close());
});
......@@ -17,7 +17,10 @@ describe('Homepage', () => {
let page;
const testPage = path => async () => {
await page.goto(`${BASE_URL}${path}`, { waitUntil: 'networkidle2' });
await page.goto(`${BASE_URL}${path}`);
await page.waitForSelector('footer', {
timeout: 2000,
});
const haveFooter = await page.evaluate(
() => document.getElementsByTagName('footer').length > 0
);
......@@ -29,11 +32,8 @@ describe('Homepage', () => {
browser = await puppeteer.launch({ args: ['--no-sandbox'] });
page = await browser.newPage();
});
RouterConfig.forEach(({ routes = [] }) => {
formatter(routes).forEach(route => {
it(`test pages ${route}`, testPage(route));
});
formatter(RouterConfig[0].routes).forEach(route => {
fit(`test pages ${route}`, testPage(route));
});
afterAll(() => browser.close());
......
......@@ -29,9 +29,13 @@ startServer.stdout.on('data', data => {
// eslint-disable-next-line
once = true;
console.log('Development server is started, ready to run tests.');
const testCmd = spawn(/^win/.test(process.platform) ? 'npm.cmd' : 'npm', ['test'], {
stdio: 'inherit',
});
const testCmd = spawn(
/^win/.test(process.platform) ? 'npm.cmd' : 'npm',
['test', '--', '--maxWorkers=1'],
{
stdio: 'inherit',
}
);
testCmd.on('exit', code => {
startServer.kill();
process.exit(code);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册