Skip to content

Commit 717b15c

Browse files
Merge pull request #126 from gemini-testing/TESTPLANE-981
docs(selectivity): mapSourceMapUrl + recover failed docs
2 parents 34e02ae + fa4e974 commit 717b15c

4 files changed

Lines changed: 226 additions & 8 deletions

File tree

docs/guides/selectivity.mdx

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ After a file changes, on the next run only those tests that depend on the change
1717

1818
<Admonition type="info">
1919
If at least one test fails, then on the next run all the same tests will be executed again —
20-
Testplane will "remember" the new state only after a fully successful run.
20+
Testplane will "remember" the new state only after a fully successful run. However, you can use
21+
[`saveIncompleteDumpOnFail`][selectivity-config] to save the dump even on failure and then
22+
complete it by re-running only the failed tests. See [Recovering from a failed selectivity
23+
run](#recovering-incomplete-dump) below.
2124
</Admonition>
2225

2326
## Setup
@@ -222,9 +225,53 @@ You can also disable selectivity manually using an environment variable:
222225
testplane_selectivity_enabled=false # disable
223226
```
224227
228+
## Recovering from a failed selectivity run {#recovering-incomplete-dump}
229+
230+
By default, if any test fails during a Testplane run, the selectivity dump is **not updated**. This means that if you ran Testplane to collect a selectivity dump (e.g. in CI) and only a few tests failed, you would need to re-run the **entire** test suite just to get a valid dump.
231+
232+
The `saveIncompleteDumpOnFail` option solves this problem. Here is the step-by-step workflow:
233+
234+
### 1. Run Testplane with `saveIncompleteDumpOnFail: true`
235+
236+
Enable selectivity in `enabled` or `writeOnly` mode with `saveIncompleteDumpOnFail: true` in your config:
237+
238+
```typescript
239+
selectivity: {
240+
enabled: true, // or "writeOnly"
241+
saveIncompleteDumpOnFail: true,
242+
}
243+
```
244+
245+
Run Testplane as usual. If some tests fail, the dump will still be saved — but it is in an **incomplete state**. An incomplete dump may incorrectly skip some of the failed tests, so it should **not** be used directly for selective runs.
246+
247+
### 2. Re-run only the failed tests
248+
249+
Use the [`--last-failed-only`][last-failed] flag to re-run only the tests that failed:
250+
251+
```bash
252+
npx testplane --last-failed-only
253+
```
254+
255+
Make sure `saveIncompleteDumpOnFail: true` is still set in the config. This run will only execute the previously failed tests and update the incomplete dump with their results.
256+
257+
### 3. Repeat until all tests pass
258+
259+
You can repeat step 2 multiple times if needed — for example, if some tests are flaky and fail again. Each subsequent `--last-failed-only` run updates the dump incrementally.
260+
261+
### 4. Dump is complete
262+
263+
Once a run succeeds with no failures, the dump is considered **complete** and can safely be used for selective test execution.
264+
265+
<Admonition type="warning">
266+
Do not use the incomplete dump (saved after a failed run) for selective test execution. An
267+
incomplete dump may skip tests that actually need to be re-run. Always complete the dump by
268+
re-running failed tests until the run is fully successful.
269+
</Admonition>
270+
225271
## Configuration
226272
227273
Additional information about selectivity configuration is provided in the [browsers-selectivity][selectivity-config] section of the documentation.
228274
229275
[dev-server]: ../../reference/config/dev-server
230276
[selectivity-config]: ../../reference/config/browsers#selectivity
277+
[last-failed]: ../../reference/config/last-failed

docs/reference/config/browsers.mdx

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,11 +1075,33 @@ The section has the following parameters:
10751075
</tr>
10761076
<tr>
10771077
<td>`mapDependencyRelativePath`</td>
1078-
<td>`null | (dependency: { scope: "browser" | "testplane", relativePath: string }) => string | void`</td>
1078+
<td>`null | (dependency: { scope: "browser" | "testplane", relativePath: string }) => string | boolean | void`</td>
10791079
<td>`null`</td>
10801080
<td>
1081-
Callback, which accepts test dependency path in POSIX style and maps it to another path
1082-
or filters it completely if `falsy` value is returned
1081+
Callback, which accepts test dependency path in POSIX style and maps it to another path.
1082+
Return a mapped `string` path to remap, `true` to keep the original path unchanged,
1083+
or a falsy value (`false`, `undefined`, `void`) to filter the dependency out completely.
1084+
</td>
1085+
</tr>
1086+
<tr>
1087+
<td>`mapSourceMapUrl`</td>
1088+
<td>`null | (assetInfo: { type: "css" | "js", sourceUrl: string, sourceMapUrl: string }) => string | boolean | void`</td>
1089+
<td>`null`</td>
1090+
<td>
1091+
Callback to filter or remap source map URLs before they are fetched.
1092+
Return a mapped `string` URL to remap, `true` to keep the original URL unchanged,
1093+
or a falsy value to skip the asset entirely (both the script/style and its source map will be ignored).
1094+
</td>
1095+
</tr>
1096+
<tr>
1097+
<td>`saveIncompleteDumpOnFail`</td>
1098+
<td>`boolean`</td>
1099+
<td>`false`</td>
1100+
<td>
1101+
When `true`, selectivity dump is saved even if some tests failed.
1102+
This allows you to later rerun only the failed tests with
1103+
[`--last-failed-only`][last-failed] to complete the dump without re-running the entire suite.
1104+
See the [guide on recovering from a failed selectivity run][selectivity-incomplete-dump-guide].
10831105
</td>
10841106
</tr>
10851107
<tr>
@@ -1133,6 +1155,44 @@ The section has the following parameters:
11331155
}
11341156
```
11351157

1158+
### `mapSourceMapUrl` examples {#mapSourceMapUrl_examples}
1159+
1160+
#### Filter out third-party scripts {#mapSourceMapUrl_example_filter}
1161+
1162+
```ts
1163+
{
1164+
selectivity: {
1165+
enabled: true,
1166+
mapSourceMapUrl({ type, sourceUrl, sourceMapUrl }) {
1167+
// Skip analytics and tracking scripts
1168+
if (sourceUrl.includes("analytics") || sourceUrl.includes("tracking")) {
1169+
return false;
1170+
}
1171+
1172+
return true;
1173+
},
1174+
}
1175+
}
1176+
```
1177+
1178+
#### Remap source map URL to a local server {#mapSourceMapUrl_example_remap}
1179+
1180+
```ts
1181+
{
1182+
selectivity: {
1183+
enabled: true,
1184+
mapSourceMapUrl({ type, sourceUrl, sourceMapUrl }) {
1185+
// Redirect source map fetching to a local server
1186+
if (sourceMapUrl.startsWith("https://cdn.example.com/")) {
1187+
return sourceMapUrl.replace("https://cdn.example.com/", "http://localhost:3000/");
1188+
}
1189+
1190+
return true;
1191+
},
1192+
}
1193+
}
1194+
```
1195+
11361196
<Admonition type="info">
11371197
You should not specify `node_modules` in `disableSelectivityPatterns`, as this will cause a
11381198
significant slowdown. Instead, it is recommended to specify Testplane configuration files and
@@ -1207,3 +1267,5 @@ export = {
12071267
[restoreState]: ../../../commands/browser/restoreState
12081268
[getState]: ../../../commands/browser/getState
12091269
[url-resolve]: https://nodejs.org/api/url.html#urlresolvefrom-to
1270+
[last-failed]: ../last-failed
1271+
[selectivity-incomplete-dump-guide]: ../../../guides/selectivity#recovering-incomplete-dump

i18n/ru/docusaurus-plugin-content-docs/current/guides/selectivity.mdx

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ import Admonition from "@theme/Admonition";
1717

1818
<Admonition type="info">
1919
Если хотя бы один тест упадет, то при следующем прогоне будут запущены все те же тесты —
20-
Testplane "запомнит" новое состояние только после полностью успешного прогона.
20+
Testplane "запомнит" новое состояние только после полностью успешного прогона. Однако вы можете
21+
использовать [`saveIncompleteDumpOnFail`][selectivity-config] для сохранения дампа даже при
22+
падении и затем дополнить его, перезапустив только упавшие тесты. См. [Восстановление после
23+
неудачного прогона селективности](#recovering-incomplete-dump) ниже.
2124
</Admonition>
2225

2326
## Настройка
@@ -222,9 +225,53 @@ selectivity: {
222225
testplane_selectivity_enabled=false # отключить
223226
```
224227
228+
## Восстановление после неудачного прогона селективности {#recovering-incomplete-dump}
229+
230+
По умолчанию, если хотя бы один тест упал во время прогона Testplane, дамп селективности **не обновляется**. Это означает, что если вы запускали Testplane для сбора дампа селективности (например, в CI) и упало лишь несколько тестов, вам пришлось бы перезапускать **весь** набор тестов для получения валидного дампа.
231+
232+
Опция `saveIncompleteDumpOnFail` решает эту проблему. Вот пошаговый процесс:
233+
234+
### 1. Запустите Testplane с `saveIncompleteDumpOnFail: true`
235+
236+
Включите селективность в режиме `enabled` или `writeOnly` с `saveIncompleteDumpOnFail: true` в конфигурации:
237+
238+
```typescript
239+
selectivity: {
240+
enabled: true, // или "writeOnly"
241+
saveIncompleteDumpOnFail: true,
242+
}
243+
```
244+
245+
Запустите Testplane как обычно. Если некоторые тесты упадут, дамп все равно будет сохранен — но в **неполном состоянии**. Неполный дамп может некорректно пропускать некоторые из упавших тестов, поэтому его **нельзя** использовать напрямую для селективных прогонов.
246+
247+
### 2. Перезапустите только упавшие тесты
248+
249+
Используйте флаг [`--last-failed-only`][last-failed] для перезапуска только упавших тестов:
250+
251+
```bash
252+
npx testplane --last-failed-only
253+
```
254+
255+
Убедитесь, что `saveIncompleteDumpOnFail: true` по-прежнему установлен в конфигурации. Этот запуск выполнит только ранее упавшие тесты и обновит неполный дамп их результатами.
256+
257+
### 3. Повторяйте до полного успеха
258+
259+
Вы можете повторять шаг 2 несколько раз — например, если некоторые тесты нестабильны и падают снова. Каждый последующий запуск с `--last-failed-only` инкрементально обновляет дамп.
260+
261+
### 4. Дамп готов
262+
263+
Как только прогон завершится без падений, дамп считается **полным** и может безопасно использоваться для селективного запуска тестов.
264+
265+
<Admonition type="warning">
266+
Не используйте неполный дамп (сохраненный после неудачного прогона) для селективного запуска
267+
тестов. Неполный дамп может пропускать тесты, которые на самом деле нужно перезапустить. Всегда
268+
дополняйте дамп, перезапуская упавшие тесты до полностью успешного прогона.
269+
</Admonition>
270+
225271
## Конфигурация
226272
227273
Дополнительная информация о конфигурации селективности описана в разделе [browsers-selectivity][selectivity-config] документации.
228274
229275
[dev-server]: ../../reference/config/dev-server
230276
[selectivity-config]: ../../reference/config/browsers#selectivity
277+
[last-failed]: ../../reference/config/last-failed

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

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,11 +1078,33 @@ export = {
10781078
</tr>
10791079
<tr>
10801080
<td>`mapDependencyRelativePath`</td>
1081-
<td>`null | (dependency: { scope: "browser" | "testplane", relativePath: string }) => string | void`</td>
1081+
<td>`null | (dependency: { scope: "browser" | "testplane", relativePath: string }) => string | boolean | void`</td>
10821082
<td>`null`</td>
10831083
<td>
1084-
Коллбэк, который принимает путь зависимости теста в стиле POSIX и преобразует его в другой путь
1085-
или полностью игнорирует зависимость, если возвращено `falsy` значение
1084+
Коллбэк, который принимает путь зависимости теста в стиле POSIX и преобразует его в другой путь.
1085+
Верните строку `string` для переназначения пути, `true` для сохранения исходного пути без изменений,
1086+
или falsy-значение (`false`, `undefined`, `void`) для полного исключения зависимости.
1087+
</td>
1088+
</tr>
1089+
<tr>
1090+
<td>`mapSourceMapUrl`</td>
1091+
<td>`null | (assetInfo: { type: "css" | "js", sourceUrl: string, sourceMapUrl: string }) => string | boolean | void`</td>
1092+
<td>`null`</td>
1093+
<td>
1094+
Коллбэк для фильтрации или переназначения URL-адресов source map перед их загрузкой.
1095+
Верните строку `string` для переназначения URL, `true` для сохранения исходного URL без изменений,
1096+
или falsy-значение для полного пропуска ресурса (и скрипт/стиль, и его source map будут проигнорированы).
1097+
</td>
1098+
</tr>
1099+
<tr>
1100+
<td>`saveIncompleteDumpOnFail`</td>
1101+
<td>`boolean`</td>
1102+
<td>`false`</td>
1103+
<td>
1104+
Если `true`, дамп селективности сохраняется даже при падении некоторых тестов.
1105+
Это позволяет затем перезапустить только упавшие тесты с помощью
1106+
[`--last-failed-only`][last-failed] для дополнения дампа без полного перезапуска всех тестов.
1107+
См. [руководство по восстановлению после неудачного прогона селективности][selectivity-incomplete-dump-guide].
10861108
</td>
10871109
</tr>
10881110
<tr>
@@ -1136,6 +1158,44 @@ export = {
11361158
}
11371159
```
11381160

1161+
### Примеры `mapSourceMapUrl` {#mapSourceMapUrl_examples}
1162+
1163+
#### Фильтрация сторонних скриптов {#mapSourceMapUrl_example_filter}
1164+
1165+
```ts
1166+
{
1167+
selectivity: {
1168+
enabled: true,
1169+
mapSourceMapUrl({ type, sourceUrl, sourceMapUrl }) {
1170+
// Пропускаем скрипты аналитики и трекинга
1171+
if (sourceUrl.includes("analytics") || sourceUrl.includes("tracking")) {
1172+
return false;
1173+
}
1174+
1175+
return true;
1176+
},
1177+
}
1178+
}
1179+
```
1180+
1181+
#### Переназначение URL source map на локальный сервер {#mapSourceMapUrl_example_remap}
1182+
1183+
```ts
1184+
{
1185+
selectivity: {
1186+
enabled: true,
1187+
mapSourceMapUrl({ type, sourceUrl, sourceMapUrl }) {
1188+
// Перенаправляем загрузку source map на локальный сервер
1189+
if (sourceMapUrl.startsWith("https://cdn.example.com/")) {
1190+
return sourceMapUrl.replace("https://cdn.example.com/", "http://localhost:3000/");
1191+
}
1192+
1193+
return true;
1194+
},
1195+
}
1196+
}
1197+
```
1198+
11391199
<Admonition type="info">
11401200
В `disableSelectivityPatterns` не стоит указывать `node_modules` - это приведет к ощутимому
11411201
замедлению. Вместо этого, рекомендуется указать конфигурационные файлы Testplane и исходный код
@@ -1209,3 +1269,5 @@ export = {
12091269
[saveState]: .../../../../../commands/browser/saveState
12101270
[restoreState]: .../../../../../commands/browser/restoreState
12111271
[getState]: .../../../../../commands/browser/getState
1272+
[last-failed]: ../last-failed
1273+
[selectivity-incomplete-dump-guide]: ../../../guides/selectivity#recovering-incomplete-dump

0 commit comments

Comments
 (0)