mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-07 17:44:35 +08:00
chore: use portfinder to solve the problem that the port may be occupied (#53968)
This commit is contained in:
parent
95609e57c6
commit
bfc49e4156
@ -287,6 +287,7 @@
|
||||
"package-manager-detector": "^1.0.0",
|
||||
"pixelmatch": "^7.1.0",
|
||||
"pngjs": "^7.0.0",
|
||||
"portfinder": "^1.0.37",
|
||||
"prettier": "^3.4.1",
|
||||
"pretty-format": "^29.7.0",
|
||||
"prismjs": "^1.29.0",
|
||||
|
@ -6,6 +6,7 @@ import { globSync } from 'glob';
|
||||
import { createServer } from 'http-server';
|
||||
import fetch from 'isomorphic-fetch';
|
||||
import uniq from 'lodash/uniq';
|
||||
import portfinder from 'portfinder';
|
||||
|
||||
const components = uniq(
|
||||
globSync('components/!(overview)/*.md', { cwd: join(process.cwd()), dot: false }).map((path) =>
|
||||
@ -15,8 +16,11 @@ const components = uniq(
|
||||
|
||||
describe('site test', () => {
|
||||
let server: http.Server | https.Server;
|
||||
const port = 3000;
|
||||
const portPromise = portfinder.getPortPromise({
|
||||
port: 3000,
|
||||
});
|
||||
const render = async (path: string) => {
|
||||
const port = await portPromise;
|
||||
const resp = await fetch(`http://127.0.0.1:${port}${path}`).then(async (res) => {
|
||||
const html: string = await res.text();
|
||||
const $ = load(html, { xml: true });
|
||||
@ -46,7 +50,8 @@ describe('site test', () => {
|
||||
expect(tables.length).toMatchSnapshot();
|
||||
};
|
||||
|
||||
beforeAll(() => {
|
||||
beforeAll(async () => {
|
||||
const port = await portPromise;
|
||||
server = createServer({ root: join(process.cwd(), '_site') });
|
||||
server.listen(port);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user