-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Replaced tap with Node test runner.
- Loading branch information
1 parent
ee8e568
commit a732490
Showing
7 changed files
with
84 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,66 @@ | ||
/* eslint-disable @typescript-eslint/no-floating-promises */ | ||
|
||
import { chmodSync, unlinkSync, writeFileSync } from 'node:fs' | ||
import { deepStrictEqual, ifError } from 'node:assert' | ||
import { chmodSync, existsSync, unlinkSync, writeFileSync } from 'node:fs' | ||
import { dirname } from 'node:path' | ||
import t from 'tap' | ||
import { test } from 'node:test' | ||
import { info } from '../src/index.js' | ||
import { FastImageError } from '../src/models.js' | ||
|
||
const fileName = import.meta.url.replace('file://', '') | ||
const imagePath = new URL('fixtures/image.png', import.meta.url).toString().replace('file://', '') | ||
|
||
t.test('fastimage.info', t => { | ||
t.test('when working with local files', t => { | ||
t.test('should return the information of a image', t => { | ||
test('fastimage.info', async () => { | ||
await test('when working with local files', async () => { | ||
await test('should return the information of a image', () => { | ||
info(imagePath, (error, data) => { | ||
t.error(error) | ||
ifError(error) | ||
|
||
t.same(data, { | ||
deepStrictEqual(data, { | ||
width: 150, | ||
height: 150, | ||
type: 'png', | ||
time: data!.time, | ||
analyzed: 409 | ||
}) | ||
|
||
t.end() | ||
}) | ||
}) | ||
|
||
t.test('should return a error when the path is a directory', t => { | ||
await test('should return a error when the path is a directory', () => { | ||
info(dirname(fileName), (error, data) => { | ||
t.error(data) | ||
t.strictSame(error, new FastImageError('Source is a directory.', 'FS_ERROR')) | ||
t.end() | ||
ifError(data) | ||
deepStrictEqual(error, new FastImageError('Source is a directory.', 'FS_ERROR')) | ||
}) | ||
}) | ||
|
||
t.test('should return a error when the path cannot be found', t => { | ||
await test('should return a error when the path cannot be found', () => { | ||
info('/not/existent', (error, data) => { | ||
t.error(data) | ||
t.strictSame(error, new FastImageError('Source not found.', 'FS_ERROR')) | ||
t.end() | ||
ifError(data) | ||
deepStrictEqual(error, new FastImageError('Source not found.', 'FS_ERROR')) | ||
}) | ||
}) | ||
|
||
t.test('should return a error when the path cannot be read', t => { | ||
await test('should return a error when the path cannot be read', () => { | ||
const unreadablePath = imagePath.replace('image.png', 'unreadable.png') | ||
writeFileSync(unreadablePath, 'foo', 'utf8') | ||
chmodSync(unreadablePath, 0) | ||
|
||
if (!existsSync(unreadablePath)) { | ||
writeFileSync(unreadablePath, 'foo', 'utf8') | ||
chmodSync(unreadablePath, 0) | ||
} | ||
|
||
info(unreadablePath, (error, data) => { | ||
t.error(data) | ||
t.strictSame(error, new FastImageError('Source is not readable.', 'FS_ERROR')) | ||
t.end() | ||
ifError(data) | ||
deepStrictEqual(error, new FastImageError('Source is not readable.', 'FS_ERROR')) | ||
|
||
unlinkSync(unreadablePath) | ||
}) | ||
}) | ||
|
||
t.test('should return a error when the path is not a image', t => { | ||
await test('should return a error when the path is not a image', () => { | ||
info(fileName, (error, data) => { | ||
t.error(data) | ||
t.strictSame(error, new FastImageError('Unsupported data.', 'UNSUPPORTED')) | ||
t.end() | ||
ifError(data) | ||
deepStrictEqual(error, new FastImageError('Unsupported data.', 'UNSUPPORTED')) | ||
}) | ||
}) | ||
|
||
t.end() | ||
}) | ||
|
||
t.end() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,48 @@ | ||
/* eslint-disable @typescript-eslint/no-floating-promises */ | ||
|
||
import { deepStrictEqual } from 'node:assert' | ||
import { createReadStream } from 'node:fs' | ||
import t from 'tap' | ||
import { test } from 'node:test' | ||
import { stream } from '../src/index.js' | ||
import { FastImageError } from '../src/models.js' | ||
|
||
const fileName = import.meta.url.replace('file://', '') | ||
const imagePath = new URL('fixtures/image.png', import.meta.url).toString().replace('file://', '') | ||
|
||
t.test('fastimage.stream', t => { | ||
t.test('should emit info event when info are ready', t => { | ||
test('fastimage.stream', async () => { | ||
await test('should emit info event when info are ready', () => { | ||
const input = createReadStream(imagePath, { highWaterMark: 200 }) | ||
|
||
const pipe = input.pipe(stream()) | ||
|
||
pipe.on('info', data => { | ||
t.same(data, { | ||
deepStrictEqual(data, { | ||
width: 150, | ||
height: 150, | ||
type: 'png', | ||
time: data.time, | ||
analyzed: 200 | ||
}) | ||
|
||
t.end() | ||
}) | ||
}) | ||
|
||
t.test('should emit error event in case of errors', t => { | ||
await test('should emit error event in case of errors', () => { | ||
const input = createReadStream(fileName) | ||
|
||
const pipe = input.pipe(stream()) | ||
|
||
pipe.on('error', error => { | ||
t.strictSame(error, new FastImageError('Unsupported data.', 'UNSUPPORTED')) | ||
|
||
t.end() | ||
deepStrictEqual(error, new FastImageError('Unsupported data.', 'UNSUPPORTED')) | ||
}) | ||
}) | ||
|
||
t.test('should accept the threshold option', t => { | ||
await test('should accept the threshold option', () => { | ||
const input = createReadStream(imagePath, { highWaterMark: 1 }) | ||
|
||
const pipe = input.pipe(stream({ threshold: 10 })) | ||
|
||
pipe.on('error', error => { | ||
t.strictSame(error, new FastImageError('Unsupported data.', 'UNSUPPORTED')) | ||
|
||
t.end() | ||
deepStrictEqual(error, new FastImageError('Unsupported data.', 'UNSUPPORTED')) | ||
}) | ||
}) | ||
|
||
t.end() | ||
}) |
Oops, something went wrong.