Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"prepare": "husky",
"build": "tsc",
"prepublishOnly": "npm run build",
"test": "xo && tsc --noEmit && c8 ava"
"test": "xo && tsc --noEmit && c8 node --import=tsx/esm --test"
},
"files": [
"distribution/main.js",
Expand All @@ -40,7 +40,6 @@
"@commitlint/config-conventional": "^20.0.0",
"@sindresorhus/tsconfig": "^8.0.1",
"@types/node": "^24.5.2",
"ava": "^6.4.1",
"c8": "^10.1.3",
"husky": "^9.1.7",
"lint-staged": "^16.2.1",
Expand All @@ -56,15 +55,6 @@
"lint-staged": {
"*.ts": "xo --fix"
},
"ava": {
"extensions": {
"ts": "module"
},
"nodeArguments": [
"--import=tsx/esm"
],
"workerThreads": false
},
"c8": {
"reporter": [
"text",
Expand Down
46 changes: 25 additions & 21 deletions test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import test from 'ava';
import test from 'node:test';
import assert from 'node:assert/strict';
import {
_, assign, middleware, parallel, passthrough, pipe,
} from './main.js';
Expand All @@ -8,91 +9,94 @@ const addAge = middleware(async () => ({age: 30}));
const addHobby = middleware(() => ({hobby: 'Coding'}));
const addScore = middleware(() => ({score: 1000}));

test('should transform data in a pipeline', async t => {
void test('should transform data in a pipeline', async () => {
const pipeline = pipe(addAge, addHobby, addScore);

const result = await pipeline(await getUser());

t.deepEqual(result, {
assert.deepEqual(result, {
name: 'John Smith', age: 30, hobby: 'Coding', score: 1000,
});
});

test('should transform data in a standalone pipeline', async t => {
void test('should transform data in a standalone pipeline', async () => {
const pipeline = pipe(getUser, addAge, addHobby, addScore);

const result = await pipeline(_);

t.deepEqual(result, {
assert.deepEqual(result, {
name: 'John Smith', age: 30, hobby: 'Coding', score: 1000,
});
});

test('should transform data in a compound pipeline', async t => {
void test('should transform data in a compound pipeline', async () => {
const pipeline = pipe(addAge, pipe(addHobby, addScore));

const result = await pipeline(await getUser());

t.deepEqual(result, {
assert.deepEqual(result, {
name: 'John Smith', age: 30, hobby: 'Coding', score: 1000,
});
});

test('should transform data in a compound standalone pipeline', async t => {
void test('should transform data in a compound standalone pipeline', async () => {
const pipeline = pipe(getUser, pipe(addAge, addHobby), addScore);

const result = await pipeline(_);

t.deepEqual(result, {
assert.deepEqual(result, {
name: 'John Smith', age: 30, hobby: 'Coding', score: 1000,
});
});

test('should transform data in parallel', async t => {
void test('should transform data in parallel', async () => {
const pipeline = parallel(addAge, getUser);

const result = await pipeline({name: 'Jane Smith'});

t.deepEqual(result, [{name: 'Jane Smith', age: 30}, {name: 'John Smith'}]);
assert.deepEqual(result, [{name: 'Jane Smith', age: 30}, {name: 'John Smith'}]);
});

test('should transform data in a parallel pipeline', async t => {
void test('should transform data in a parallel pipeline', async () => {
const pipeline = pipe(getUser, parallel(addAge, addHobby));

const result = await pipeline(_);

t.deepEqual(result, [
assert.deepEqual(result, [
{name: 'John Smith', age: 30},
{name: 'John Smith', hobby: 'Coding'},
]);
});

test('should transform data in a compound parallel pipeline', async t => {
void test('should transform data in a compound parallel pipeline', async () => {
const addAgeAndHobby = pipe(addAge, addHobby);

const pipeline = pipe(getUser, parallel(addAgeAndHobby, addAgeAndHobby));

const result = await pipeline(_);

t.deepEqual(result, [
assert.deepEqual(result, [
{name: 'John Smith', hobby: 'Coding', age: 30},
{name: 'John Smith', hobby: 'Coding', age: 30},
]);
});

test('should assign the return of parallel', async t => {
void test('should assign the return of parallel', async () => {
const pipeline = assign(parallel(addAge, addHobby));

const result = await pipeline({name: 'John Smith'});

t.deepEqual(result, {name: 'John Smith', age: 30, hobby: 'Coding'});
assert.deepEqual(result, {name: 'John Smith', age: 30, hobby: 'Coding'});
});

test('should passthought the transformed data', async t => {
const pipeline = passthrough(() => t.pass());
void test('should passthought the transformed data', async () => {
let captured;
const pipeline = passthrough(input => {
captured = input;
});

const result = await pipeline({name: 'John Smith'});

t.deepEqual(result, {name: 'John Smith'});
t.plan(2);
assert.deepEqual(captured, {name: 'John Smith'});
assert.deepEqual(result, {name: 'John Smith'});
});