Skip to content

Commit 50d9cb3

Browse files
feat(selectivity): add option to map and ignore test dependencies
1 parent 4385c8f commit 50d9cb3

File tree

2 files changed

+102
-0
lines changed

2 files changed

+102
-0
lines changed

docs/reference/config/browsers.mdx

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,9 +1068,60 @@ The section has the following parameters:
10681068
will be disabled.
10691069
</td>
10701070
</tr>
1071+
<tr>
1072+
<td>`mapDependencyRelativePath`</td>
1073+
<td>`null | (dependency: { scope: "browser" | "testplane", relativePath: string }) => string | void`</td>
1074+
<td>`null`</td>
1075+
<td>
1076+
Callback, which accepts test dependency path in POSIX style and maps it to another path
1077+
or filters it completely if `falsy` value is returned
1078+
</td>
1079+
</tr>
10711080
</tbody>
10721081
</table>
10731082

1083+
### `mapDependencyRelativePath` examples {#mapDependencyRelativePath_examples}
1084+
1085+
#### Ignore Next.js internal dependencies {#mapDependencyRelativePath_example_nextjs}
1086+
1087+
```ts
1088+
{
1089+
selectivity: {
1090+
enabled: true,
1091+
mapDependencyRelativePath({relativePath}) {
1092+
if (relativePath.startsWith("turbopack://")) {
1093+
return;
1094+
}
1095+
1096+
return relativePath;
1097+
},
1098+
}
1099+
}
1100+
```
1101+
1102+
#### Usage with @testplane/storybook plugin {#mapDependencyRelativePath_example_testplane_storybook}
1103+
1104+
```ts
1105+
{
1106+
selectivity: {
1107+
enabled: true,
1108+
mapDependencyRelativePath({relativePath}) {
1109+
// Testplane storybook autogenerated tests
1110+
if (relativePath.includes("/testplane-storybook-autogenerated/")) {
1111+
return;
1112+
}
1113+
1114+
// Storybook fake dependencies
1115+
if (relativePath === "storybook-stories.js" || relativePath === "storybook-config-entry.js") {
1116+
return;
1117+
}
1118+
1119+
return relativePath;
1120+
},
1121+
}
1122+
}
1123+
```
1124+
10741125
<Admonition type="info">
10751126
You should not specify `node_modules` in `disableSelectivityPatterns`, as this will cause a
10761127
significant slowdown. Instead, it is recommended to specify Testplane configuration files and

i18n/ru/docusaurus-plugin-content-docs/current/reference/config/browsers.mdx

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,9 +1071,60 @@ export = {
10711071
Список паттернов, при изменении файлов по которым селективность должна отключаться.
10721072
</td>
10731073
</tr>
1074+
<tr>
1075+
<td>`mapDependencyRelativePath`</td>
1076+
<td>`null | (dependency: { scope: "browser" | "testplane", relativePath: string }) => string | void`</td>
1077+
<td>`null`</td>
1078+
<td>
1079+
Коллбэк, который принимает путь зависимости теста в стиле POSIX и преобразует его в другой путь
1080+
или полностью игнорирует зависимость, если возвращено `falsy` значение
1081+
</td>
1082+
</tr>
10741083
</tbody>
10751084
</table>
10761085

1086+
### Примеры `mapDependencyRelativePath` {#mapDependencyRelativePath_examples}
1087+
1088+
#### Игнорирование внутренних зависимостей Next.js {#mapDependencyRelativePath_example_nextjs}
1089+
1090+
```ts
1091+
{
1092+
selectivity: {
1093+
enabled: true,
1094+
mapDependencyRelativePath({relativePath}) {
1095+
if (relativePath.startsWith("turbopack://")) {
1096+
return;
1097+
}
1098+
1099+
return relativePath;
1100+
},
1101+
}
1102+
}
1103+
```
1104+
1105+
#### Использование с плагином @testplane/storybook {#mapDependencyRelativePath_example_testplane_storybook}
1106+
1107+
```ts
1108+
{
1109+
selectivity: {
1110+
enabled: true,
1111+
mapDependencyRelativePath({relativePath}) {
1112+
// Автогенерированные тесты testplane storybook
1113+
if (relativePath.includes("/testplane-storybook-autogenerated/")) {
1114+
return;
1115+
}
1116+
1117+
// Фиктивные зависимости Storybook
1118+
if (relativePath === "storybook-stories.js" || relativePath === "storybook-config-entry.js") {
1119+
return;
1120+
}
1121+
1122+
return relativePath;
1123+
},
1124+
}
1125+
}
1126+
```
1127+
10771128
<Admonition type="info">
10781129
В `disableSelectivityPatterns` не стоит указывать `node_modules` - это приведет к ощутимому
10791130
замедлению. Вместо этого, рекомендуется указать конфигурационные файлы Testplane и исходный код

0 commit comments

Comments
 (0)