Skip to content

Commit

Permalink
fix: 🐛 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
touv committed May 31, 2024
1 parent 95de130 commit 2205210
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 26 deletions.
62 changes: 37 additions & 25 deletions packages/core/src/fusible.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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;
};
});

2 changes: 1 addition & 1 deletion packages/core/test/knownPipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
Expand Down

0 comments on commit 2205210

Please sign in to comment.