From c08845b771410c3a8079a8a9b71758da58fc447c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Belin?= Date: Mon, 29 Jul 2024 10:01:31 +0200 Subject: [PATCH] Code optimization --- test/finder_test.js | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/test/finder_test.js b/test/finder_test.js index 3b7f3c1..e302215 100644 --- a/test/finder_test.js +++ b/test/finder_test.js @@ -29,21 +29,21 @@ describe("Finder", () => { const finder = new Finder({paths: ["res"]}); it("should return the path of the `executable.cmd` file on Windows", async () => { - const executables = await generatorToArray(finder.find("executable")); + const executables = await Array.fromAsync(finder.find("executable")); equal(executables.length, Finder.isWindows ? 1 : 0); if (Finder.isWindows) ok(executables[0].endsWith("\\res\\executable.cmd")); }); it("should return the path of the `executable.sh` file on POSIX", async () => { - const executables = await generatorToArray(finder.find("executable.sh")); + const executables = await Array.fromAsync(finder.find("executable.sh")); equal(executables.length, Finder.isWindows ? 0 : 1); if (!Finder.isWindows) ok(executables[0].endsWith("/res/executable.sh")); }); it("should return an empty array if the searched command is not executable or not found", async () => { - let executables = await generatorToArray(finder.find("not_executable.sh")); + let executables = await Array.fromAsync(finder.find("not_executable.sh")); equal(executables.length, 0); - executables = await generatorToArray(finder.find("foo")); + executables = await Array.fromAsync(finder.find("foo")); equal(executables.length, 0); }); }); @@ -63,14 +63,3 @@ describe("Finder", () => { equal(await finder.isExecutable("res/executable.cmd"), Finder.isWindows)); }); }); - -/** - * Converts the specified generator to an array. - * @param {AsyncGenerator} generator A generator. - * @returns {Promise} The array corresponding to the specified generator. - */ -async function generatorToArray(generator) { - const items = []; - for await (const item of generator) items.push(item); - return items; -}