Repository: elastic/synthetics
Pull request #390 (2021-10-01 15:50:51)

chore: Use rm instead of rmdir for recursive operations
Starting in Node 16, recursive fs.rmdir calls are deprecated and will log a
warning.  It's recommended to use fs.rm intead.

https://nodejs.org/api/deprecations.html#DEP0147

Kibana currently exits on process warnings, this will look like:
```
  ✓  Step: 'Navigates to details page' succeeded (72 ms)
(node:663222) [DEP0147] DeprecationWarning: In future versions of Node.js, fs.rmdir(path, { recursive: true }) will be removed. Use fs.rm(path, { recursive: true }) instead
(Use `node --trace-deprecation ...` to show where the warning was created)
Node.js process-warning detected:

DeprecationWarning: In future versions of Node.js, fs.rmdir(path, { recursive: true }) will be removed. Use fs.rm(path, { recursive: true }) instead
    at emitRecursiveRmdirWarning (node:internal/fs/utils:816:13)
    at Object.rmdir (node:fs:1115:5)
    at node:internal/util:363:7
    at new Promise (<anonymous>)
    at Object.rmdir [as rmdirAsync] (node:internal/util:349:12)
    at Runner.endJourney (/home/jon/dev/kibana-node-16/node_modules/@elastic/synthetics/src/core/runner.ts:356:11)
    at Runner.runJourney (/home/jon/dev/kibana-node-16/node_modules/@elastic/synthetics/src/core/runner.ts:414:18)
    at runMicrotasks (<anonymous>)
    at runNextTicks (node:internal/process/task_queues:61:5)
    at processImmediate (node:internal/timers:437:9)
    at Runner.run (/home/jon/dev/kibana-node-16/node_modules/@elastic/synthetics/src/core/runner.ts:465:11)
    at run (/home/jon/dev/kibana-node-16/node_modules/@elastic/synthetics/src/index.ts:45:12)
    at playwrightStart (/home/jon/dev/kibana-node-16/x-pack/plugins/uptime/e2e/playwright_start.ts:43:15)
    at /home/jon/dev/kibana-node-16/x-pack/plugins/uptime/e2e/playwright_start.ts:19:22
    at /home/jon/dev/kibana-node-16/node_modules/@kbn/test/target_node/functional_test_runner/functional_test_runner.js:48:17
    at FunctionalTestRunner._run (/home/jon/dev/kibana-node-16/node_modules/@kbn/test/target_node/functional_test_runner/functional_test_runner.js:105:14)

Terminating process...
node:child_process:903
    throw err;
    ^
```

apmmachine: 
## :green_heart: Build Succeeded


<!-- BUILD BADGES-->
> _the below badges are clickable and redirect to their specific view in the CI or DOCS_
[![Pipeline View](https://img.shields.io/badge/pipeline-pipeline%20-green)](https://apm-ci.elastic.co/blue/organizations/jenkins/apm-agent-rum%2Felastic-synthetics%2FPR-390/detail/PR-390/1//pipeline) [![Test View](https://img.shields.io/badge/test-test-green)](https://apm-ci.elastic.co/blue/organizations/jenkins/apm-agent-rum%2Felastic-synthetics%2FPR-390/detail/PR-390/1//tests) [![Changes](https://img.shields.io/badge/changes-changes-green)](https://apm-ci.elastic.co/blue/organizations/jenkins/apm-agent-rum%2Felastic-synthetics%2FPR-390/detail/PR-390/1//changes) [![Artifacts](https://img.shields.io/badge/artifacts-artifacts-yellow)](https://apm-ci.elastic.co/blue/organizations/jenkins/apm-agent-rum%2Felastic-synthetics%2FPR-390/detail/PR-390/1//artifacts) [![preview](https://img.shields.io/badge/docs-preview-yellowgreen)](http://synthetics_390.docs-preview.app.elstc.co/diff)  [![preview](https://img.shields.io/badge/elastic-observability-blue)](https://ci-stats.elastic.co/app/apm/services/apm-ci/transactions/view?rangeFrom=2021-10-01T15:41:06.455Z&rangeTo=2021-10-01T16:01:06.455Z&transactionName=apm-agent-rum/elastic-synthetics/PR-{number}&transactionType=unknown&latencyAggregationType=avg&traceId=cd61d3017c69ce2a980af2326207b5da&transactionId=383dec554e422b26)

<!-- BUILD SUMMARY-->
<details><summary>Expand to view the summary</summary>
<p>

#### Build stats




* Start Time: 2021-10-01T15:51:06.455+0000


* Duration: 14 min 17 sec


* Commit: 888866f9651f862f145625eef9ffd47db7165fa0



#### Test stats :test_tube:

| Test         | Results                         |
| ------------ | :-----------------------------: |
| Failed       | 0  |
| Passed       | 135  |
| Skipped      | 0 |
| Total        | 135   |


</p>
</details>

<!-- TEST RESULTS IF ANY-->


<!-- STEPS ERRORS IF ANY -->












## :robot: GitHub comments

To re-run your PR in the CI, just comment with:


- `/test` : Re-trigger the build.




<!--COMMENT_GENERATED_WITH_ID_comment.id-->

Patch:
diff --git a/src/core/runner.ts b/src/core/runner.ts
index 08b53b7..fb4c3ff 100644
--- a/src/core/runner.ts
+++ b/src/core/runner.ts
@@ -25,6 +25,7 @@
 
 import { once, EventEmitter } from 'events';
 import { join } from 'path';
+import { rm } from 'fs/promises';
 import { Journey } from '../dsl/journey';
 import { Step } from '../dsl/step';
 import { reporters, Reporter } from '../reporters';
@@ -35,7 +36,6 @@ import {
   runParallel,
   generateUniqueId,
   mkdirAsync,
-  rmdirAsync,
   writeFileAsync,
 } from '../helpers';
 import {
@@ -359,7 +359,7 @@ export default class Runner extends EventEmitter {
       await once(this, 'journey:end:reported');
     }
     // clear screenshots cache after each journey
-    await rmdirAsync(Runner.screenshotPath, { recursive: true });
+    await rm(Runner.screenshotPath, { recursive: true, force: true });
   }
 
   /**
@@ -485,7 +485,7 @@ export default class Runner extends EventEmitter {
      * Clear all cache data stored for post processing by
      * the current synthetic agent run
      */
-    await rmdirAsync(CACHE_PATH, { recursive: true });
+    await rm(CACHE_PATH, { recursive: true, force: true });
     this.currentJourney = null;
     this.journeys = [];
     this.active = false;
diff --git a/src/helpers.ts b/src/helpers.ts
index 8b622b5..03072f3 100644
--- a/src/helpers.ts
+++ b/src/helpers.ts
@@ -36,7 +36,6 @@ const readdirAsync = promisify(fs.readdir);
 
 export const readFileAsync = promisify(fs.readFile);
 export const writeFileAsync = promisify(fs.writeFile);
-export const rmdirAsync = promisify(fs.rmdir);
 export const mkdirAsync = promisify(fs.mkdir);
 
 const SEPARATOR = '\n';


Test patch:
diff --git a/__tests__/reporters/json.test.ts b/__tests__/reporters/json.test.ts
index 44b6261..49fd3ca 100644
--- a/__tests__/reporters/json.test.ts
+++ b/__tests__/reporters/json.test.ts
@@ -295,7 +295,7 @@ describe('json reporter', () => {
     });
 
     afterAll(() => {
-      fs.rmdirSync(destDir, { recursive: true });
+      fs.rmSync(destDir, { recursive: true, force: true });
     });
 
     const emitEnd = (options, status = 'failed' as StatusValue) =>