Skip to content

Commit

Permalink
🎨 [Format] All helpers folder files
Browse files Browse the repository at this point in the history
  • Loading branch information
beefchimi committed Jul 30, 2024
1 parent 8378f86 commit d816f74
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 5 deletions.
9 changes: 8 additions & 1 deletion pkg/helpers/fetch-audio-buffer.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
async function fetchRequest(path: string, options?: RequestInit) {
const audioRequest = new Request(path, options);

// eslint-disable-next-line ts/return-await
return await fetch(audioRequest).then((response) => {
if (!response.ok) throw new Error(`Network status: ${response.status}`);
if (!response.ok) {
throw new Error(`Network status: ${response.status}`);
}

return response;
});
}
Expand All @@ -12,7 +16,10 @@ export async function fetchAudioBuffer(
context: AudioContext,
options?: RequestInit,
) {
// eslint-disable-next-line ts/return-await
return await fetchRequest(path, options)
// eslint-disable-next-line ts/return-await
.then(async (response) => await response.arrayBuffer())
// eslint-disable-next-line ts/return-await
.then(async (arrayBuffer) => await context.decodeAudioData(arrayBuffer));
}
3 changes: 2 additions & 1 deletion pkg/helpers/tests/fetch-audio-buffer.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {describe, it, expect} from 'vitest';
import {describe, expect, it} from 'vitest';
import {mockData} from '@earwurm/mocks';

import {fetchAudioBuffer} from '../fetch-audio-buffer';
Expand All @@ -13,6 +13,7 @@ describe('fetchAudioBuffer()', () => {
// `Failed to parse URL from ${mockPath}`
// However, we now get back a `[object Request]`,
await expect(
// eslint-disable-next-line ts/return-await
async () => await fetchAudioBuffer(mockPath, mockContext),
).rejects.toThrowError();
});
Expand Down
2 changes: 1 addition & 1 deletion pkg/helpers/tests/linear-ramp.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {describe, it, expect, vi} from 'vitest';
import {describe, expect, it, vi} from 'vitest';

import {linearRamp} from '../linear-ramp';

Expand Down
2 changes: 1 addition & 1 deletion pkg/helpers/tests/scratch-buffer.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {describe, it, expect} from 'vitest';
import {describe, expect, it} from 'vitest';

import {scratchBuffer} from '../scratch-buffer';

Expand Down
2 changes: 1 addition & 1 deletion pkg/helpers/tests/unlock-audio-context.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {afterEach, describe, it, expect, vi} from 'vitest';
import {afterEach, describe, expect, it, vi} from 'vitest';
import {audioBufferSourceNodeEndedEvent} from '@earwurm/mocks';

import {unlockAudioContext} from '../unlock-audio-context';
Expand Down

0 comments on commit d816f74

Please sign in to comment.