-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfixtures.mjs
More file actions
38 lines (34 loc) · 1.08 KB
/
fixtures.mjs
File metadata and controls
38 lines (34 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// tests/global-teardown.mjs
import {
findBadges,
requestToken,
findAssertions,
revokeAssertions,
deleteBadge,
} from "./util/api.js";
import { username, password } from "./secret.js";
/**
* Playwright calls this function once after the entire test run finishes.
* It receives the test configuration, but we only need it for logging.
*/
export default async ({ config }) => {
console.log("🧹 Tearing down Playwright test run …");
try {
await cleanupBadges();
console.log("✅ Teardown completed.");
} catch (err) {
console.error("❌ Teardown failed:", err);
}
};
async function cleanupBadges() {
const token = await requestToken(username, password);
const badges = await findBadges(token, "automated", true);
for (let badge of badges) {
const assertions = await findAssertions(token, badge.entityId);
await revokeAssertions(token, assertions);
await deleteBadge(token, badge.entityId);
}
const residue = await findBadges(token, "automated", true);
if (residue.length != 0)
console.error("Didn't succeed in deleting residue badges");
}