Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
huming2207 committed Oct 15, 2024
1 parent 09c07a0 commit add2567
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
9 changes: 8 additions & 1 deletion __test__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { promises as fs } from 'fs'

import test from 'ava'

import { to4Bpp, toMonochrome } from '../index'
import { to4Bpp, to4BppWithTextMetadata, toMonochrome } from '../index'

test('Read test1 and convert to 4bpp', async (t) => {
const input = await fs.readFile('./__test__/test1.png')
Expand Down Expand Up @@ -31,3 +31,10 @@ test('Read chickenfeet and convert to monochrome', async (t) => {
t.true(output !== undefined)
await fs.writeFile('./__test__/chickenfeet-mono.png', output)
})

test('Read chickenfeet and convert to 4bpp with tEXt', async (t) => {
const input = await fs.readFile('./__test__/chickenfeet.jpg')
const output = await to4BppWithTextMetadata(input, {"foo": "bar", "test": "567"}, false)
t.true(output !== undefined)
await fs.writeFile('./__test__/chickenfeet-4bpp-with-tEXt.png', output)
})
6 changes: 6 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ export declare function to4Bpp(
format?: string | undefined | null,
signal?: AbortSignal | undefined | null,
): Promise<Buffer>
export declare function to4BppWithTextMetadata(
image: Buffer,
textChunks?: Record<string, string> | undefined | null,
compressed?: boolean | undefined | null,
signal?: AbortSignal | undefined | null,
): Promise<Buffer>
export declare function toMonochrome(
image: Buffer,
format?: string | undefined | null,
Expand Down
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,9 @@ if (!nativeBinding) {
throw new Error(`Failed to load native binding`)
}

const { to4Bpp, toMonochrome, VERSION } = nativeBinding
const { to4Bpp, to4BppWithTextMetadata, toMonochrome, VERSION } = nativeBinding

module.exports.to4Bpp = to4Bpp
module.exports.to4BppWithTextMetadata = to4BppWithTextMetadata
module.exports.toMonochrome = toMonochrome
module.exports.VERSION = VERSION

0 comments on commit add2567

Please sign in to comment.