init
This commit is contained in:
commit
932d4ad420
46 changed files with 5800 additions and 0 deletions
55
tests/lib/file.test.ts
Normal file
55
tests/lib/file.test.ts
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
import * as fs from "fs"
|
||||
import { describe, it, expect } from "vitest"
|
||||
import { preprocessTODO, parseTodoFile } from "../../lib/file"
|
||||
|
||||
|
||||
describe("parseTodoFile", () => {
|
||||
it("parses full TODO file end-to-end", async () => {
|
||||
const todo = await parseTodoFile("tests/_mocks/todo-basic.txt")
|
||||
|
||||
expect(todo.sprints.length).toBe(2)
|
||||
|
||||
expect(todo.issues.length).toBe(2)
|
||||
|
||||
// expect(todo.issues[0].title).toBe("Add streaming parser")
|
||||
expect(todo.sprints[0].name).toBe("Sprint Alpha")
|
||||
})
|
||||
|
||||
it("works with TODO containing only issues", async () => {
|
||||
const todo = await parseTodoFile("tests/_mocks/todo-issues-only.txt")
|
||||
expect(todo.sprints.length).toBe(0)
|
||||
// expect(todo.issues.length).toBe(1) - skipping for now
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
describe("preprocessTODO", () => {
|
||||
it("wraps TODO into MIME and puts sprints first", () => {
|
||||
const raw = fs.readFileSync("tests/_mocks/todo-basic.txt", "utf-8")
|
||||
const mime = preprocessTODO(raw)
|
||||
|
||||
expect(mime).toContain("MIME-Version: 1.0")
|
||||
expect(mime).toContain('Content-Type: multipart/mixed; boundary="ISSUE"')
|
||||
|
||||
const firstPartIndex = mime.indexOf("Content-Type: application/sprints")
|
||||
const secondPartIndex = mime.indexOf("Content-Type: application/issue")
|
||||
|
||||
expect(firstPartIndex).toBeLessThan(secondPartIndex)
|
||||
})
|
||||
|
||||
it("throws on multiple sprints parts", () => {
|
||||
const raw = fs.readFileSync("tests/_mocks/todo-multiple-sprints.txt", "utf-8")
|
||||
expect(() => preprocessTODO(raw)).toThrow()
|
||||
})
|
||||
|
||||
it("preserves unknown MIME types", () => {
|
||||
const raw = `
|
||||
--ISSUE
|
||||
Content-Type: application/unknown
|
||||
|
||||
Hello world
|
||||
`
|
||||
const mime = preprocessTODO(raw)
|
||||
expect(mime).toContain("application/unknown")
|
||||
})
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue