|
| 1 | +/* |
| 2 | + * Copyright 2026, Salesforce, Inc. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +import { readdirSync, rmSync } from 'node:fs'; |
| 18 | +import { join } from 'node:path'; |
| 19 | + |
| 20 | +/** |
| 21 | + * Root-level cleanup: remove any test_session_* directories left behind. |
| 22 | + * |
| 23 | + * TestSession.clean() normally deletes these, but they can persist when: |
| 24 | + * - rm fails (e.g. Windows file locks from spawned processes) |
| 25 | + * - Process is killed before after() runs (timeout, SIGKILL) |
| 26 | + * - TESTKIT_SAVE_ARTIFACTS is set |
| 27 | + * |
| 28 | + * This hook runs after all NUTs complete as a fallback. |
| 29 | + */ |
| 30 | +after(() => { |
| 31 | + const cwd = process.cwd(); |
| 32 | + try { |
| 33 | + for (const name of readdirSync(cwd)) { |
| 34 | + if (name.startsWith('test_session_')) { |
| 35 | + try { |
| 36 | + rmSync(join(cwd, name), { recursive: true, force: true }); |
| 37 | + } catch { |
| 38 | + /* ignore per-dir failures */ |
| 39 | + } |
| 40 | + } |
| 41 | + } |
| 42 | + } catch { |
| 43 | + /* ignore */ |
| 44 | + } |
| 45 | +}); |
0 commit comments