-
Notifications
You must be signed in to change notification settings - Fork 3
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
1 parent
48ef488
commit 9d805c2
Showing
2 changed files
with
50 additions
and
17 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,25 +1,35 @@ | ||
// test/index.spec.ts | ||
import { env, createExecutionContext, waitOnExecutionContext, SELF } from 'cloudflare:test'; | ||
import { describe, it, expect } from 'vitest'; | ||
import worker from '../src/index'; | ||
import { calcOffsetModification } from '../src/utils'; | ||
import { ModifiedCommentBody, Offset } from '../src/types'; | ||
|
||
// For now, you'll need to do something like this to get a correctly-typed | ||
// `Request` to pass to `worker.fetch()`. | ||
const IncomingRequest = Request<unknown, IncomingRequestCfProperties>; | ||
describe('Commit offset patch', () => { | ||
// https://github.com/OI-wiki/OI-wiki/blob/master/docs/index.md | ||
it('OI-Wiki index unit test', async () => { | ||
const offsets: Offset[] = [ | ||
{ start: 372, end: 439 }, | ||
{ start: 441, end: 586 }, | ||
{ start: 588, end: 744 }, | ||
{ start: 746, end: 810 }, | ||
]; | ||
const diff: ModifiedCommentBody['diff'] = [ | ||
{ tag: 'delete', i1: 20, i2: 298, j1: 20, j2: 20 }, | ||
{ tag: 'replace', i1: 420, i2: 423, j1: 142, j2: 145 }, | ||
{ tag: 'insert', i1: 538, i2: 538, j1: 260, j2: 265 }, | ||
{ tag: 'insert', i1: 586, i2: 586, j1: 313, j2: 321 }, | ||
{ tag: 'delete', i1: 696, i2: 712, j1: 431, j2: 431 }, | ||
{ tag: 'replace', i1: 752, i2: 755, j1: 471, j2: 473 }, | ||
{ tag: 'replace', i1: 770, i2: 773, j1: 488, j2: 490 }, | ||
]; | ||
|
||
describe('Hello World worker', () => { | ||
it('responds with Hello World! (unit style)', async () => { | ||
const request = new IncomingRequest('http://example.com'); | ||
// Create an empty context to pass to `worker.fetch()`. | ||
const ctx = createExecutionContext(); | ||
const response = await worker.fetch(request, env, ctx); | ||
// Wait for all `Promise`s passed to `ctx.waitUntil()` to settle before running test assertions | ||
await waitOnExecutionContext(ctx); | ||
expect(await response.text()).toMatchInlineSnapshot(`"Hello World!"`); | ||
}); | ||
const res = calcOffsetModification(offsets, diff); | ||
|
||
it('responds with Hello World! (integration style)', async () => { | ||
const response = await SELF.fetch('https://example.com'); | ||
expect(await response.text()).toMatchInlineSnapshot(`"Hello World!"`); | ||
expect(res).toEqual([ | ||
{ from: { start: 372, end: 439 }, to: { start: 94, end: 161 } }, | ||
{ from: { start: 441, end: 586 }, to: { start: 163, end: 313 } }, | ||
{ from: { start: 588, end: 744 }, to: { start: 323, end: 463 } }, | ||
{ from: { start: 746, end: 810 }, to: { start: 465, end: 527 } }, | ||
]); | ||
}); | ||
}); |