-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
54 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export default function diff( | ||
oldNode: Node, | ||
reader: ReadableStreamDefaultReader<Uint8Array>, | ||
reader: ReadableStreamDefaultReader<unknown>, | ||
): Promise<void>; |
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'bun:test'; | ||
import { chromium, type Browser, type Page } from 'playwright'; | ||
import diff from './index'; | ||
import {join} from 'node:path'; | ||
|
||
const transpiler = new Bun.Transpiler({ loader: 'ts', target: 'browser' }); | ||
const content = await transpiler.transform((await Bun.file(join(import.meta.dir, 'index.ts')).text()).replace('export default', '')); | ||
|
||
describe('Diffing Algorithm Test', () => { | ||
let browser: Browser; | ||
let page: Page; | ||
|
||
beforeAll(async () => { | ||
browser = await chromium.launch(); | ||
}); | ||
|
||
beforeEach(async () => { | ||
page = await browser.newPage(); | ||
}) | ||
|
||
afterEach(async () => { | ||
await page.close(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await browser.close(); | ||
}); | ||
|
||
it('should update the DOM correctly', async () => { | ||
await page.setContent('<div id="test">Old Node</div>'); | ||
await page.evaluate(async ([content]) => { | ||
eval(content) | ||
const encoder = new TextEncoder(); | ||
const readable = new ReadableStream({ start: (controller) => { | ||
controller.enqueue(encoder.encode('<div id="test">')); | ||
controller.enqueue(encoder.encode('New Node Content')); | ||
controller.enqueue(encoder.encode("</div>")); | ||
controller.close(); | ||
}}); | ||
const reader = readable.getReader(); | ||
|
||
await diff(document.getElementById('test')!, reader) | ||
}, [content]); | ||
|
||
const newNode = await page.$eval('#test', (node: Node) => node.textContent!.trim()); | ||
expect(newNode).toBe('New Node Content'); | ||
}); | ||
}); |
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