Something went wrong. Try again.
Monorepo for the nibling.run platform
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768import { test } from 'node:test';import assert from 'node:assert/strict';import { applyOverlay, blobCid, diffAgainstBase } from '../src/index.ts';
test('diffAgainstBase without a base returns the whole tree sorted by path', () => { const current = new Map([ ['src/main.ts', 'cid-main'], ['index.html', 'cid-index'], ]); assert.deepEqual( [...diffAgainstBase(undefined, current)], [ ['index.html', 'cid-index'], ['src/main.ts', 'cid-main'], ], );});
test('diffAgainstBase with a base returns changed and added paths, and null for removed ones', () => { const base = new Map([ ['README.md', 'cid-readme'], ['index.html', 'cid-index'], ['old.js', 'cid-old'], ]); const current = new Map([ ['README.md', 'cid-readme'], ['index.html', 'cid-index-2'], ['src/new.ts', 'cid-new'], ]); assert.deepEqual( [...diffAgainstBase(base, current)], [ ['index.html', 'cid-index-2'], ['old.js', null], ['src/new.ts', 'cid-new'], ], );});
test('applyOverlay replaces, adds, and deletes base paths', () => { const base = new Map([ ['README.md', 'readme'], ['index.html', 'v1'], ['old.js', 'old'], ]); const overlay = new Map<string, string | null>([ ['index.html', 'v2'], ['old.js', null], ['a.txt', 'a'], ]); assert.deepEqual( [...applyOverlay(base, overlay)], [ ['README.md', 'readme'], ['a.txt', 'a'], ['index.html', 'v2'], ], );});
test('blobCid matches the raw sha-256 CIDs a PDS assigns', async () => { assert.equal(await blobCid(new Uint8Array()), 'bafkreihdwdcefgh4dqkjv67uzcmw7ojee6xedzdetojuzjevtenxquvyku'); assert.equal( await blobCid(new TextEncoder().encode('<h1>hi</h1>')), 'bafkreihh7o3pxp2m4kkjcpvwfnj76a5hkrtett64bwbe3hr2fncucubpp4', );});