From c3e7aa13f228f8fee861e0909f7e5dabee5c440e Mon Sep 17 00:00:00 2001 From: Wesley Luyten Date: Thu, 28 Mar 2024 11:11:39 -0500 Subject: [PATCH] fix: add more test coverage + fix customDomain (#213) * test: add more test coverage * test: more withNextVideo * test: provider transformers * test: add more test cov * test: ignore some less risk files --- ...e.googleapis.com_muxdemofiles_mux.mp4.json | 2 +- src/components/video.tsx | 5 +- src/handlers/api-request.ts | 2 + src/providers/mux/transformer.ts | 5 +- src/utils/logger.ts | 2 + src/utils/s3.ts | 2 + tests/components/alert.test.tsx | 24 +++++++ tests/components/utils.test.tsx | 24 +++++++ tests/components/video-loader.test.ts | 25 +++++++ tests/components/video.test.tsx | 60 +++++++++++++++- tests/providers/amazon-s3/transformer.test.ts | 28 ++++++++ tests/providers/backblaze/transformer.test.ts | 28 ++++++++ tests/providers/mux/transformer.test.ts | 31 +++++++++ .../providers/vercel-blob/transformer.test.ts | 27 ++++++++ tests/utils/provider.test.ts | 69 +++++++++++++++++++ tests/with-next-video.test.ts | 37 ++++++++++ 16 files changed, 366 insertions(+), 5 deletions(-) create mode 100644 tests/components/alert.test.tsx create mode 100644 tests/components/utils.test.tsx create mode 100644 tests/components/video-loader.test.ts create mode 100644 tests/providers/amazon-s3/transformer.test.ts create mode 100644 tests/providers/backblaze/transformer.test.ts create mode 100644 tests/providers/mux/transformer.test.ts create mode 100644 tests/providers/vercel-blob/transformer.test.ts create mode 100644 tests/utils/provider.test.ts diff --git a/examples/default-provider/videos/storage.googleapis.com_muxdemofiles_mux.mp4.json b/examples/default-provider/videos/storage.googleapis.com_muxdemofiles_mux.mp4.json index 2b1f1af..f275c44 100644 --- a/examples/default-provider/videos/storage.googleapis.com_muxdemofiles_mux.mp4.json +++ b/examples/default-provider/videos/storage.googleapis.com_muxdemofiles_mux.mp4.json @@ -1 +1 @@ -{"status":"ready","originalFilePath":"https://storage.googleapis.com/muxdemofiles/mux.mp4","provider":"mux","providerMetadata":{"mux":{"assetId":"EploFGgmKULMpiyDFwsy5c6lmGcg8dkObaVvnPMcdkQ","playbackId":"jxEf6XiJs6JY017pSzpv8Hd6tTbdAOecHTq4FiFAn564"}},"createdAt":1710979438730,"updatedAt":1710979441038,"sources":[{"src":"https://stream.mux.com/.m3u8","type":"application/x-mpegURL"}],"poster":"https://image.mux.com//thumbnail.webp","blurDataURL":"data:image/webp;base64,UklGRlAAAABXRUJQVlA4IEQAAACwAQCdASoQAAkAAQAcJZwAAueBHFYwAP7+sPJ01xp5AM+XuhDsRQ67ZYXXhHDkrqsIkUGjQSCMuENc5y3Qg0o9pZgAAA=="} +{"status":"ready","originalFilePath":"https://storage.googleapis.com/muxdemofiles/mux.mp4","provider":"mux","providerMetadata":{"mux":{"assetId":"EploFGgmKULMpiyDFwsy5c6lmGcg8dkObaVvnPMcdkQ","playbackId":"jxEf6XiJs6JY017pSzpv8Hd6tTbdAOecHTq4FiFAn564"}},"createdAt":1710979438730,"updatedAt":1710979441038,"sources":[{"src":"https://stream.mux.com/jxEf6XiJs6JY017pSzpv8Hd6tTbdAOecHTq4FiFAn564.m3u8","type":"application/x-mpegURL"}],"poster":"https://image.mux.com//thumbnail.webp","blurDataURL":"data:image/webp;base64,UklGRlAAAABXRUJQVlA4IEQAAACwAQCdASoQAAkAAQAcJZwAAueBHFYwAP7+sPJ01xp5AM+XuhDsRQ67ZYXXhHDkrqsIkUGjQSCMuENc5y3Qg0o9pZgAAA=="} diff --git a/src/components/video.tsx b/src/components/video.tsx index 9a2c649..1832ac6 100644 --- a/src/components/video.tsx +++ b/src/components/video.tsx @@ -11,9 +11,10 @@ import type { DefaultPlayerProps } from './players/default-player.js'; import type { Asset } from '../assets.js'; import type { VideoLoaderProps, VideoProps, VideoPropsInternal } from './types.js'; -const DEV_MODE = process.env.NODE_ENV === 'development'; - const NextVideo = forwardRef((props: VideoProps, forwardedRef) => { + // Keep in component so we can emulate the DEV_MODE. + const DEV_MODE = process.env.NODE_ENV === 'development'; + let { as: VideoPlayer = DefaultPlayer, loader = defaultLoader, diff --git a/src/handlers/api-request.ts b/src/handlers/api-request.ts index e9c8cf8..02bb745 100644 --- a/src/handlers/api-request.ts +++ b/src/handlers/api-request.ts @@ -1,3 +1,4 @@ +/* c8 ignore start */ import * as providers from '../providers/providers.js'; import { camelCase } from '../utils/utils.js'; import type { Asset } from '../assets.js'; @@ -10,3 +11,4 @@ export async function uploadRequestedFile(asset: Asset, config: HandlerConfig) { } } } +/* c8 ignore stop */ diff --git a/src/providers/mux/transformer.ts b/src/providers/mux/transformer.ts index 5824541..cf23270 100644 --- a/src/providers/mux/transformer.ts +++ b/src/providers/mux/transformer.ts @@ -26,7 +26,10 @@ export function transform(asset: Asset, props?: Props) { const transformedAsset: Asset = { ...asset, - sources: [{ src: `https://stream.mux.com/${playbackId}.m3u8`, type: 'application/x-mpegURL' }], + sources: [{ + src: `https://stream.${props?.customDomain ?? MUX_VIDEO_DOMAIN}/${playbackId}.m3u8`, + type: 'application/x-mpegURL' + }], poster: getPosterURLFromPlaybackId(playbackId, { thumbnailTime, diff --git a/src/utils/logger.ts b/src/utils/logger.ts index e6939cc..e6f2146 100644 --- a/src/utils/logger.ts +++ b/src/utils/logger.ts @@ -1,3 +1,4 @@ +/* c8 ignore start */ import chalk from 'chalk'; type logType = 'log' | 'error'; @@ -47,3 +48,4 @@ export default { space, label, }; +/* c8 ignore stop */ diff --git a/src/utils/s3.ts b/src/utils/s3.ts index 605a591..88b5a87 100644 --- a/src/utils/s3.ts +++ b/src/utils/s3.ts @@ -1,3 +1,4 @@ +/* c8 ignore start */ import { S3Client, PutBucketCorsCommand, @@ -62,3 +63,4 @@ export function putBucketCors(s3: S3Client, bucketName: string) { }, })); } +/* c8 ignore stop */ diff --git a/tests/components/alert.test.tsx b/tests/components/alert.test.tsx new file mode 100644 index 0000000..3d3e877 --- /dev/null +++ b/tests/components/alert.test.tsx @@ -0,0 +1,24 @@ +import assert from 'node:assert'; +import { test } from 'node:test'; +import { setTimeout } from 'node:timers/promises'; +import { create } from 'react-test-renderer'; +import React from 'react'; +import { Alert } from '../../src/components/alert.js'; + +test('renders an error alert', async () => { + const wrapper = create(