Skip to content

Commit

Permalink
Test: classic skia canvas instead of Brooooooklyns
Browse files Browse the repository at this point in the history
  • Loading branch information
antoineMoPa committed Nov 8, 2023
1 parent a8d539b commit 094b94a
Show file tree
Hide file tree
Showing 7 changed files with 352 additions and 81 deletions.
2 changes: 1 addition & 1 deletion framefusion.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ImageData } from '@napi-rs/canvas';
import type { ImageData } from 'skia-canvas';
import { BeamcoderExtractor } from './src/backends/beamcoder.js';

export type Frame = {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
},
"dependencies": {
"@antoinemopa/beamcoder": "^0.7.4",
"@napi-rs/canvas": "^0.1.44",
"fs-extra": "^11.1.1",
"skia-canvas": "^1.0.1",
"tmp": "^0.2.1"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/BaseExtractor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ImageData } from '@napi-rs/canvas';
import type { ImageData } from 'skia-canvas';

import type {
ExtractorArgs,
Expand Down
2 changes: 1 addition & 1 deletion src/backends/beamcoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
Frame
} from '@antoinemopa/beamcoder';
import beamcoder from '@antoinemopa/beamcoder';
import { ImageData } from '@napi-rs/canvas';
import { ImageData } from 'skia-canvas';
import { BaseExtractor } from '../BaseExtractor';
import type { Extractor, ExtractorArgs, InterpolateMode } from '../../framefusion';
import { DownloadVideoURL } from '../DownloadVideoURL';
Expand Down
20 changes: 12 additions & 8 deletions test/framefusion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ import {
beforeAll
} from 'vitest';
import { toMatchImageSnapshot } from 'jest-image-snapshot';
import { createCanvas } from '@napi-rs/canvas';
import { Canvas } from 'skia-canvas';
import httpServer from 'http-server';
import { BeamcoderExtractor } from '../src/backends/beamcoder';

const createCanvas = (width, height) => {
return new Canvas(width, height);
};

declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace jest {
Expand Down Expand Up @@ -177,7 +181,7 @@ describe('FrameFusion', () => {
const canvas = createCanvas(imageData.width, imageData.height);
const ctx = canvas.getContext('2d');
ctx.putImageData(imageData, 0, 0);
expect(canvas.toBuffer('image/png')).toMatchImageSnapshot();
expect(await canvas.toBuffer('png')).toMatchImageSnapshot();
}

// Cleanup
Expand Down Expand Up @@ -205,7 +209,7 @@ describe('FrameFusion', () => {
const canvas = createCanvas(imageData.width, imageData.height);
const ctx = canvas.getContext('2d');
ctx.putImageData(imageData, 0, 0);
expect(canvas.toBuffer('image/png')).toMatchImageSnapshot();
expect(await canvas.toBuffer('png')).toMatchImageSnapshot();
}

// Cleanup
Expand Down Expand Up @@ -300,7 +304,7 @@ describe('FrameFusion', () => {
const canvas = createCanvas(imageData.width, imageData.height);
const ctx = canvas.getContext('2d');
ctx.putImageData(imageData, 0, 0);
expect(canvas.toBuffer('image/png')).toMatchImageSnapshot();
expect(await canvas.toBuffer('png')).toMatchImageSnapshot();
}

// Cleanup
Expand Down Expand Up @@ -336,7 +340,7 @@ describe('FrameFusion', () => {
const canvas = createCanvas(imageData.width, imageData.height);
const ctx = canvas.getContext('2d');
ctx.putImageData(imageData, 0, 0);
expect(canvas.toBuffer('image/png')).toMatchImageSnapshot();
expect(await canvas.toBuffer('png')).toMatchImageSnapshot();
}

// Cleanup
Expand All @@ -362,7 +366,7 @@ describe('FrameFusion', () => {
const canvas = createCanvas(imageData.width, imageData.height);
const ctx = canvas.getContext('2d');
ctx.putImageData(imageData, 0, 0);
expect(canvas.toBuffer('image/png')).toMatchImageSnapshot();
expect(await canvas.toBuffer('png')).toMatchImageSnapshot();
}

// Cleanup
Expand Down Expand Up @@ -392,7 +396,7 @@ describe('FrameFusion', () => {
const canvas = createCanvas(imageData.width, imageData.height);
const ctx = canvas.getContext('2d');
ctx.putImageData(imageData, 0, 0);
expect(canvas.toBuffer('image/png')).toMatchImageSnapshot();
expect(await canvas.toBuffer('png')).toMatchImageSnapshot();
}

// Cleanup
Expand All @@ -418,7 +422,7 @@ describe('FrameFusion', () => {
const canvas = createCanvas(imageData.width, imageData.height);
const ctx = canvas.getContext('2d');
ctx.putImageData(imageData, 0, 0);
expect(canvas.toBuffer('image/png')).toMatchImageSnapshot();
expect(await canvas.toBuffer('png')).toMatchImageSnapshot();
}

// Cleanup
Expand Down
3 changes: 1 addition & 2 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ export default defineConfig({
rollupOptions: {
external: [
'node:https',
'@napi-rs/canvas',
/@napi-rs\/canvas.*/,
'skia-canvas',
],
},
sourcemap: true,
Expand Down
Loading

0 comments on commit 094b94a

Please sign in to comment.