Skip to content

Commit 8875da5

Browse files
committed
refactor: Consolidate cleanup in last test
1 parent 3cec019 commit 8875da5

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

internal/shrinkwrap-extractor/test/lib/convertToShrinkwrap.js

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -214,41 +214,43 @@ test("Error handling - invalid workspace directory", async (t) => {
214214
test("Error handling - invalid package-lock.json files", async (t) => {
215215
const __dirname = import.meta.dirname;
216216

217-
// Test malformed JSON
217+
// Setup symlinks for all invalid fixtures
218218
const malformedDir = path.join(__dirname, "..", "fixture", "invalid", "malformed");
219-
const malformedSymlink = await setupFixtureSymlink(malformedDir);
220-
t.after(async () => await unlink(malformedSymlink).catch(() => {}));
219+
const noPackagesDir = path.join(__dirname, "..", "fixture", "invalid", "no-packages");
220+
const invalidPackagesDir = path.join(__dirname, "..", "fixture", "invalid", "invalid-packages");
221+
const v2Dir = path.join(__dirname, "..", "fixture", "invalid", "v2");
222+
223+
const symlinks = [
224+
await setupFixtureSymlink(malformedDir),
225+
await setupFixtureSymlink(noPackagesDir),
226+
await setupFixtureSymlink(invalidPackagesDir),
227+
await setupFixtureSymlink(v2Dir)
228+
];
229+
230+
// Cleanup all symlinks after test
231+
t.after(async () => {
232+
await Promise.all(symlinks.map((link) => unlink(link).catch(() => {})));
233+
});
221234

235+
// Test malformed JSON
222236
await assert.rejects(
223237
convertPackageLockToShrinkwrap(malformedDir, "@ui5/cli"),
224238
/Unexpected token/
225239
);
226240

227241
// Test missing packages field
228-
const noPackagesDir = path.join(__dirname, "..", "fixture", "invalid", "no-packages");
229-
const noPackagesSymlink = await setupFixtureSymlink(noPackagesDir);
230-
t.after(async () => await unlink(noPackagesSymlink).catch(() => {}));
231-
232242
await assert.rejects(
233243
convertPackageLockToShrinkwrap(noPackagesDir, "@ui5/cli"),
234244
/Invalid package-lock\.json: missing packages field/
235245
);
236246

237247
// Test invalid packages field
238-
const invalidPackagesDir = path.join(__dirname, "..", "fixture", "invalid", "invalid-packages");
239-
const invalidPackagesSymlink = await setupFixtureSymlink(invalidPackagesDir);
240-
t.after(async () => await unlink(invalidPackagesSymlink).catch(() => {}));
241-
242248
await assert.rejects(
243249
convertPackageLockToShrinkwrap(invalidPackagesDir, "@ui5/cli"),
244250
/Invalid package-lock\.json: packages field must be an object/
245251
);
246252

247253
// Test unsupported lockfile version
248-
const v2Dir = path.join(__dirname, "..", "fixture", "invalid", "v2");
249-
const v2Symlink = await setupFixtureSymlink(v2Dir);
250-
t.after(async () => await unlink(v2Symlink).catch(() => {}));
251-
252254
await assert.rejects(
253255
convertPackageLockToShrinkwrap(v2Dir, "@ui5/cli"),
254256
/Unsupported lockfile version: 2\. Only lockfile version 3 is supported/

0 commit comments

Comments
 (0)