Skip to content

Commit bfc49e4

Browse files
authored
chore: use portfinder to solve the problem that the port may be occupied (ant-design#53968)
1 parent 95609e5 commit bfc49e4

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@
287287
"package-manager-detector": "^1.0.0",
288288
"pixelmatch": "^7.1.0",
289289
"pngjs": "^7.0.0",
290+
"portfinder": "^1.0.37",
290291
"prettier": "^3.4.1",
291292
"pretty-format": "^29.7.0",
292293
"prismjs": "^1.29.0",

scripts/check-site.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { globSync } from 'glob';
66
import { createServer } from 'http-server';
77
import fetch from 'isomorphic-fetch';
88
import uniq from 'lodash/uniq';
9+
import portfinder from 'portfinder';
910

1011
const components = uniq(
1112
globSync('components/!(overview)/*.md', { cwd: join(process.cwd()), dot: false }).map((path) =>
@@ -15,8 +16,11 @@ const components = uniq(
1516

1617
describe('site test', () => {
1718
let server: http.Server | https.Server;
18-
const port = 3000;
19+
const portPromise = portfinder.getPortPromise({
20+
port: 3000,
21+
});
1922
const render = async (path: string) => {
23+
const port = await portPromise;
2024
const resp = await fetch(`http://127.0.0.1:${port}${path}`).then(async (res) => {
2125
const html: string = await res.text();
2226
const $ = load(html, { xml: true });
@@ -46,7 +50,8 @@ describe('site test', () => {
4650
expect(tables.length).toMatchSnapshot();
4751
};
4852

49-
beforeAll(() => {
53+
beforeAll(async () => {
54+
const port = await portPromise;
5055
server = createServer({ root: join(process.cwd(), '_site') });
5156
server.listen(port);
5257

0 commit comments

Comments
 (0)