Skip to content

Commit

Permalink
chore: Fix tests (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
matvp91 authored Dec 4, 2024
1 parent a39711c commit 6471cf5
Show file tree
Hide file tree
Showing 14 changed files with 52 additions and 19 deletions.
2 changes: 1 addition & 1 deletion packages/api/src/routes/jobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
pipelineQueue,
transcodeQueue,
} from "bolt";
import { AudioCodec, VideoCodec } from "bolt";
import { AudioCodec, VideoCodec } from "bolt/types";
import { Elysia, t } from "elysia";
import { auth } from "../auth";
import { DeliberateError } from "../errors";
Expand Down
2 changes: 1 addition & 1 deletion packages/artisan/src/lib/default-values.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AudioCodec, VideoCodec } from "bolt";
import { AudioCodec, VideoCodec } from "bolt/types";

const DEFAULT_AUDIO_BITRATE: Record<number, Record<AudioCodec, number>> = {
2: {
Expand Down
2 changes: 1 addition & 1 deletion packages/artisan/src/lib/file-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as fs from "node:fs/promises";
import { getS3SignedUrl } from "./s3";
import type { PartialInput, Stream } from "bolt";
import type { PartialInput, Stream } from "bolt/types";

export async function getBinaryPath(name: string) {
const direct = `${process.cwd()}/bin/${name}`;
Expand Down
3 changes: 2 additions & 1 deletion packages/artisan/src/workers/ffmpeg.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { ffmpeg } from "../lib/ffmpeg";
import { mapInputToPublicUrl } from "../lib/file-helpers";
import { uploadToS3 } from "../lib/s3";
import type { FfmpegData, FfmpegResult, Stream, WorkerCallback } from "bolt";
import type { FfmpegData, FfmpegResult, WorkerCallback } from "bolt";
import type { Stream } from "bolt/types";

export const ffmpegCallback: WorkerCallback<FfmpegData, FfmpegResult> = async ({
job,
Expand Down
2 changes: 1 addition & 1 deletion packages/artisan/src/workers/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import { syncFromS3, syncToS3 } from "../lib/s3";
import type {
PackageData,
PackageResult,
Stream,
WorkerCallback,
WorkerDir,
} from "bolt";
import type { Stream } from "bolt/types";
import type { Job } from "bullmq";

const packagerBin = await getBinaryPath("packager");
Expand Down
5 changes: 1 addition & 4 deletions packages/artisan/src/workers/transcode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,11 @@ import type { MetaStruct } from "../lib/file-helpers";
import type {
FfmpegResult,
FfprobeResult,
Input,
PartialInput,
PartialStream,
Stream,
TranscodeData,
TranscodeResult,
WorkerCallback,
} from "bolt";
import type { Input, PartialInput, PartialStream, Stream } from "bolt/types";
import type { Job } from "bullmq";

enum Step {
Expand Down
15 changes: 15 additions & 0 deletions packages/artisan/test/setup.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
import { mock } from "bun:test";

// We're going to mock bolt entirely as we do not want job runners
// to actually do work during tests.
mock.module("bolt", () => ({
getChildren: () => [],
waitForChildren: () => Promise.resolve(),
outcomeQueue: undefined,
ffmpegQueue: undefined,
ffprobeQueue: undefined,
addToQueue: undefined,
}));

process.env = {
NODE_ENV: "test",
TZ: "UTC",
S3_ENDPOINT: "s3-endpoint",
S3_REGION: "s3-region",
S3_ACCESS_KEY: "s3-access-key",
Expand Down
2 changes: 1 addition & 1 deletion packages/artisan/test/workers/transcode.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import "bun";
import { AudioCodec, VideoCodec } from "bolt";
import { AudioCodec, VideoCodec } from "bolt/types";
import { describe, expect, test } from "bun:test";
import {
getMatches,
Expand Down
5 changes: 4 additions & 1 deletion packages/bolt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
"private": true,
"version": "0.0.0",
"type": "module",
"main": "./src/index.ts",
"exports": {
".": "./src/index.ts",
"./types": "./src/types.ts"
},
"scripts": {
"lint": "tsc && eslint"
},
Expand Down
2 changes: 0 additions & 2 deletions packages/bolt/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
export * from "./types";

export * from "./queue";

export * from "./queue-result";
Expand Down
7 changes: 6 additions & 1 deletion packages/shared/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ import { config } from "dotenv";
import findConfig from "find-config";
import { z } from "zod";

// When we are running tests, we are not going to allow reading env variables
// from the config.env file as they might produce different results when running
// the tests locally.
const isTestEnv = process.env.NODE_ENV === "test";

const configPath = findConfig("config.env");
if (configPath) {
if (configPath && !isTestEnv) {
config({ path: configPath });
}

Expand Down
2 changes: 1 addition & 1 deletion packages/stitcher/src/vast.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DOMParser } from "@xmldom/xmldom";
import { AudioCodec, VideoCodec } from "bolt";
import { AudioCodec, VideoCodec } from "bolt/types";
import * as uuid from "uuid";
import { VASTClient } from "vast-client";
import { api } from "./lib/api-client";
Expand Down
19 changes: 17 additions & 2 deletions packages/stitcher/test/setup.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
import { setSystemTime } from "bun:test";
import { mock, setSystemTime } from "bun:test";

mock.module("redis", () => ({
createClient() {
const items = new Map<string, string>();
return {
connect: () => Promise.resolve(),
set: (key: string, value: string) => {
items.set(key, value);
},
get: (key: string) => {
return items.get(key) ?? null;
},
};
},
}));

// The day my son was born!
setSystemTime(new Date(2021, 4, 2, 10, 12, 5, 250));

process.env = {
NODE_ENV: "test",
TZ: "UTC",
PUBLIC_S3_ENDPOINT: "s3-endpoint",
PUBLIC_STITCHER_ENDPOINT: "stitcher-endpoint",
PUBLIC_API_ENDPOINT: "api-endpoint",
SUPER_SECRET: "secret",
};
3 changes: 1 addition & 2 deletions scripts/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ import { buildClientPackages } from "./devtools/client-packages";

await buildClientPackages();

// TODO: We need a better setup for tests.
// await $`bun run --filter="*" test`;
await $`bun run --filter="*" test`;

0 comments on commit 6471cf5

Please sign in to comment.