Skip to content

Commit b245ba0

Browse files
committed
improve test gate
1 parent 00377f4 commit b245ba0

1 file changed

Lines changed: 21 additions & 7 deletions

File tree

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,35 @@
11
import React from 'react';
2+
// eslint-disable-next-line @typescript-eslint/no-require-imports
3+
const testRendererVersion = require('test-renderer/package.json').version;
24

3-
function isReactMinorOrNewer(targetMinor: number): boolean {
4-
const match = /^(\d+)\.(\d+)/.exec(React.version);
5+
function matchesMinVersion(
6+
versionString: string,
7+
targetMajor: number,
8+
targetMinor: number,
9+
targetPatch: number,
10+
): boolean {
11+
const match = /^(\d+)\.(\d+)\.(\d+)/.exec(versionString);
512

613
if (!match) {
714
return false;
815
}
916

1017
const major = Number(match[1]);
1118
const minor = Number(match[2]);
19+
const patch = Number(match[3]);
1220

13-
if (major !== 19) {
14-
return major > 19;
21+
if (major !== targetMajor) {
22+
return major > targetMajor;
1523
}
1624

17-
return minor >= targetMinor;
25+
if (minor !== targetMinor) {
26+
return minor > targetMinor;
27+
}
28+
29+
return patch >= targetPatch;
1830
}
1931

20-
export const testGateReact19_2 = isReactMinorOrNewer(2) ? test : test.skip;
21-
export const testGateReact19_3 = isReactMinorOrNewer(3) ? test : test.skip;
32+
export const testGateReact19_2 =
33+
matchesMinVersion(React.version, 19, 2, 0) && matchesMinVersion(testRendererVersion, 1, 2, 0)
34+
? test
35+
: test.skip;

0 commit comments

Comments
 (0)