import { deepEqual as equal } from 'node:assert/strict' import { metaltest } from 'metaltest' const test = metaltest('Sort by') export { test } import { sortby } from '../index.js' const data = [ { age: 40, name: "Persone 1", new: true }, { age: 17, name: "Persone 2", new: false }, ] test('sort by name ascending', () => { const result = data.sort(sortby(['name'])) equal(result, [ { age: 40, name: "Persone 1", new: true }, { age: 17, name: "Persone 2", new: false }, ]) }) test('sort by age ascending', () => { const result = data.sort(sortby(['age'])) equal(result, [ { age: 17, name: "Persone 2", new: false }, { age: 40, name: "Persone 1", new: true }, ]) }) test('sort by age descending', () => { const result = data.sort(sortby(['age', 'desc'])) equal(result, [ { age: 40, name: "Persone 1", new: true }, { age: 17, name: "Persone 2", new: false }, ]) }) test('sort by new descending', () => { const result = data.sort(sortby(['new', 'desc'])) equal(result, [ { age: 40, name: "Persone 1", new: true }, { age: 17, name: "Persone 2", new: false }, ]) }) import { runifmain, summaryreporter, errorreporter } from 'metaltest' await runifmain(import.meta, () => test.run(summaryreporter(), errorreporter()))