Skip to content

Commit

Permalink
Drop Bluebird from devDependencies
Browse files Browse the repository at this point in the history
Change-type: patch
  • Loading branch information
thgreasi committed Jan 2, 2025
1 parent e83b4ef commit e4b5c71
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 54 deletions.
14 changes: 0 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,9 @@
"license": "Apache-2.0",
"devDependencies": {
"@balena/lint": "^6.2.1",
"@types/bluebird": "^3.5.38",
"@types/mocha": "^10.0.1",
"@types/node": "^20.0.0",
"@types/tmp": "^0.2.3",
"bluebird": "^3.7.2",
"jsdoc-to-markdown": "^8.0.0",
"mocha": "^10.2.0",
"tmp": "^0.2.1",
Expand Down
71 changes: 33 additions & 38 deletions tests/e2e.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { deepEqual } from 'assert';
import { promisifyAll } from 'bluebird';
import { FileDisk, withOpenFile } from 'file-disk';
import * as Fs from 'fs';
import { promisify } from 'util';
import * as Path from 'path';
import * as tmp from 'tmp';

Expand Down Expand Up @@ -113,36 +113,23 @@ function testWithFileCopy(
}
function testFilename<T>(
title: string,
fn: (fs: any) => Promise<T>,
fn: (fs: typeof Fs) => Promise<T>,
image: { image: string; partition?: number },
) {
testWithFileCopy(title, image.image, async (fileCopy: string) => {
await imagefs.interact(
fileCopy,
image.partition,
async ($fs: typeof Fs) => {
await fn(promisifyAll($fs));
await fn($fs);
},
);
});
}

function promisifyAllFs($fs: typeof Fs) {
const promisifiedFs = promisifyAll($fs);
// @ts-expect-error Had to manually override readFileAsync types since
// promisifyAll breaks the overloaded typings
const result: Omit<typeof promisifiedFs, 'readFileAsync' | 'readdirAsync'> & {
readFileAsync: typeof Fs.promises.readFile;
readdirAsync: typeof Fs.promises.readdir;
} = promisifiedFs;
return result;
}

type PromisifiedFs = ReturnType<typeof promisifyAllFs>;

function testFileDisk<T>(
title: string,
fn: (fs: PromisifiedFs) => Promise<T>,
fn: (fs: typeof Fs) => Promise<T>,
image: { image: string; partition?: number },
) {
testWithFileCopy(
Expand All @@ -155,7 +142,7 @@ function testFileDisk<T>(
disk,
image.partition,
async ($fs: typeof Fs) => {
await fn(promisifyAllFs($fs));
await fn($fs);
},
);
});
Expand All @@ -166,10 +153,10 @@ function testFileDisk<T>(
function testBoth<T>(
title: string,
fn:
| ((fs: PromisifiedFs) => Promise<T>)
| ((fs: typeof Fs) => Promise<T>)
| {
callback: (fs: PromisifiedFs) => Promise<T>;
promises: (fs: PromisifiedFs) => Promise<T>;
callback: (fs: typeof Fs) => Promise<T>;
promises: (fs: typeof Fs) => Promise<T>;
},
image: { image: string; partition?: number },
) {
Expand Down Expand Up @@ -229,8 +216,8 @@ const overlaysContents = [
testBoth(
'should list files from a fat partition in a raspberrypi image',
{
callback: async ($fs: any) => {
const contents = await $fs.readdirAsync('/overlays');
callback: async ($fs) => {
const contents = await promisify($fs.readdir)('/overlays');
deepEqual(contents, overlaysContents);
},
promises: async ($fs) => {
Expand All @@ -247,8 +234,8 @@ testBoth(
testBoth(
'should list files from an ext4 partition in a raspberrypi image',
{
callback: async ($fs: any) => {
const contents = await $fs.readdirAsync('/');
callback: async ($fs) => {
const contents = await promisify($fs.readdir)('/');
deepEqual(contents, ['lost+found', '1']);
},
promises: async ($fs) => {
Expand Down Expand Up @@ -282,7 +269,7 @@ testBoth(
'should read a config.json from a raspberrypi using readFile',
{
callback: async ($fs) => {
const contents = await $fs.readFileAsync('/config.json');
const contents = await promisify($fs.readFile)('/config.json');
// @ts-expect-error
deepEqual(JSON.parse(contents), FILES.raspberrypi['config.json']);
},
Expand All @@ -300,7 +287,7 @@ testBoth(

testBoth(
'should fail cleanly trying to read a missing file on a raspberrypi',
async ($fs: any) => {
async ($fs) => {
try {
const stream = $fs.createReadStream('/non-existent-file.txt');
await extract(stream);
Expand All @@ -325,7 +312,9 @@ testBoth(
const outputStream = $fs.createWriteStream(output);
inputStream.pipe(outputStream);
await waitStream(outputStream);
const contents = await $fs.readFileAsync(output, { encoding: 'utf8' });
const contents = await promisify($fs.readFile)(output, {
encoding: 'utf8',
});
deepEqual(contents, LOREM_CONTENT);
},
{
Expand All @@ -342,7 +331,9 @@ testBoth(
const outputStream = $fs.createWriteStream(output);
inputStream.pipe(outputStream);
await waitStream(outputStream);
const contents = await $fs.readFileAsync(output, { encoding: 'utf8' });
const contents = await promisify($fs.readFile)(output, {
encoding: 'utf8',
});
deepEqual(contents, LOREM_CONTENT);
},
{
Expand All @@ -356,8 +347,10 @@ testBoth(
{
callback: async ($fs) => {
const output = '/lorem.txt';
await $fs.writeFileAsync(output, LOREM_CONTENT);
const contents = await $fs.readFileAsync(output, { encoding: 'utf8' });
await promisify($fs.writeFile)(output, LOREM_CONTENT);
const contents = await promisify($fs.readFile)(output, {
encoding: 'utf8',
});
deepEqual(contents, LOREM_CONTENT);
},
promises: async ($fs) => {
Expand All @@ -383,7 +376,9 @@ testBoth(
const outputStream = $fs.createWriteStream(output);
inputStream.pipe(outputStream);
await waitStream(outputStream);
const contents = await $fs.readFileAsync(output, { encoding: 'utf8' });
const contents = await promisify($fs.readFile)(output, {
encoding: 'utf8',
});
deepEqual(contents, LOREM_CONTENT);
},
{
Expand All @@ -410,7 +405,7 @@ testBoth(
'should return a node fs like interface for fat partitions',
{
callback: async ($fs) => {
const files = await $fs.readdirAsync('/');
const files = await promisify($fs.readdir)('/');
deepEqual(files, RASPBERRY_FIRST_PARTITION_FILES);
},
promises: async ($fs) => {
Expand All @@ -428,7 +423,7 @@ testBoth(
'should return a node fs like interface for ext partitions',
{
callback: async ($fs) => {
const files = await $fs.readdirAsync('/');
const files = await promisify($fs.readdir)('/');
deepEqual(files, ['lost+found', '1']);
},
promises: async ($fs) => {
Expand All @@ -446,7 +441,7 @@ testBoth(
'should return a node fs like interface for raw ext partitions',
{
callback: async ($fs) => {
const files = await $fs.readdirAsync('/');
const files = await promisify($fs.readdir)('/');
deepEqual(files, ['lost+found', '1']);
},
promises: async ($fs) => {
Expand All @@ -463,7 +458,7 @@ testBoth(
'should return a node fs like interface for raw ext partitions',
{
callback: async ($fs) => {
const files = await $fs.readdirAsync('/');
const files = await promisify($fs.readdir)('/');
deepEqual(files, ['lost+found', '1']);
},
promises: async ($fs) => {
Expand All @@ -480,7 +475,7 @@ testBoth(
'should return a node fs like interface for fat partitions held in gpt typed images',
{
callback: async ($fs) => {
const files = await $fs.readdirAsync('/');
const files = await promisify($fs.readdir)('/');
deepEqual(files, ['fat.file']);
},
promises: async ($fs) => {
Expand All @@ -498,7 +493,7 @@ testBoth(
'should return a node fs like interface for ext partitions held in gpt typed images',
{
callback: async ($fs) => {
const files = await $fs.readdirAsync('/');
const files = await promisify($fs.readdir)('/');
deepEqual(files, ['lost+found', 'ext4.file']);
},
promises: async ($fs) => {
Expand Down

0 comments on commit e4b5c71

Please sign in to comment.