From 220521034c2055488a1e7d8349b15ae0aa5461b7 Mon Sep 17 00:00:00 2001 From: Nicolas Thouvenin Date: Fri, 31 May 2024 17:54:13 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/src/fusible.js | 62 +++++++++++++++++------------ packages/core/test/knownPipeline.js | 2 +- 2 files changed, 38 insertions(+), 26 deletions(-) diff --git a/packages/core/src/fusible.js b/packages/core/src/fusible.js index 0180af88..39748722 100644 --- a/packages/core/src/fusible.js +++ b/packages/core/src/fusible.js @@ -1,4 +1,4 @@ -import { access, constants, writeFile, unlink } from 'fs/promises'; +import { access, constants, writeFile, unlink } from 'fs'; import { resolve, normalize } from 'path'; import { tmpdir } from 'os'; import generate from 'nanoid/async/generate'; @@ -14,36 +14,48 @@ export const createFusible = async () => { return fusible; }; -export const checkFusible = async (fusible) => { +export const checkFusible = (fusible) => new Promise((next) => { if (!fusible) { - return false; + return next(false); } const fusibleFile = resolve(normalize(location), fusible + extension); - try { - await access(fusibleFile, constants.R_OK); - return true; - } catch { - return false; - } -}; + return access(fusibleFile, constants.R_OK, (err) => { + if (err) { + return next(false); + } + return next(true); + }); +}); -export const enableFusible = async (fusible) => { +export const enableFusible = (fusible) => new Promise((next, cancel) => { const fusibleFile = resolve(normalize(location), fusible + extension); - const check = await checkFusible(fusible); - if (!check) { - const fileContent = checksum(fusible); - await writeFile(fusibleFile, fileContent); - } - return true; -}; - -export const disableFusible = async (fusible) => { + checkFusible(fusible).then((check) => { + if (!check) { + const fileContent = checksum(fusible); + writeFile(fusibleFile, fileContent, (err) => { + if (err) { + return cancel(err); + } + return next(true); + }); + } + return next(true); + }); +}); + +export const disableFusible = (fusible) => new Promise((next, cancel) => { const fusibleFile = resolve(normalize(location), fusible + extension); - const check = await checkFusible(fusible); - if (check) { - await unlink(fusibleFile); - } + checkFusible(fusible).then((check) => { + if (check) { + unlink(fusibleFile, (err) => { + if (err) { + return cancel(err); + } + return next(true); + }); + } + }); return true; -}; +}); diff --git a/packages/core/test/knownPipeline.js b/packages/core/test/knownPipeline.js index 36b1de28..63ddbee1 100644 --- a/packages/core/test/knownPipeline.js +++ b/packages/core/test/knownPipeline.js @@ -373,7 +373,7 @@ describe(' through server(s)', () => { }); res.on('end', () => { assert.equal(output.join(''), 'a'); - assert(check < 5); + assert(check < (input.length / 2)); done(); }); });