Skip to content

Commit

Permalink
feat: add test
Browse files Browse the repository at this point in the history
  • Loading branch information
ZEROM22 committed Dec 17, 2024
1 parent ad532eb commit b6fcfc3
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/typedoc-signature/fixtures/000/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
function f() {}
55 changes: 55 additions & 0 deletions packages/typedoc-signature/fixtures/000/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import {
type Entity,
DeclarationEntity,
} from "@onlyoffice/library-declaration/next.ts"
import {
EntityToken,
KeywordToken,
type Signature,
TextToken,
type Token,
TypeToken,
} from "@onlyoffice/signature"

export const name = "transforms an empty project"

export const collection: Entity[] = []

let e0: Entity
let s: Signature = []
let t: Token

e0 = new DeclarationEntity()
e0.id = 2

t = new KeywordToken()
t.text = "function"
s.push(t)

t = new TextToken()
t.text = " "
s.push(t)

t = new EntityToken()
t.text = "f"
s.push(t)

t = new TextToken()
t.text = "("
s.push(t)

t = new TextToken()
t.text = ")"
s.push(t)

t = new TextToken()
t.text = ": "
s.push(t)

t = new TypeToken()
t.text = "void"
s.push(t)

e0.declaration.signature.verbose = s

collection.push(e0)
3 changes: 3 additions & 0 deletions packages/typedoc-signature/fixtures/000/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"files": ["main.ts"]
}
93 changes: 93 additions & 0 deletions packages/typedoc-signature/lib/main.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import {readdir} from "node:fs/promises"
import path from "node:path"
import {pipeline} from "node:stream"
import {promisify} from "node:util"
import {type Entity, GroupEntity} from "@onlyoffice/library-declaration/next.ts"
import {Transformer} from "@onlyoffice/typedoc-transformer"
import {Transport} from "@onlyoffice/typedoc-transport"
import {Application, type JSONOutput as J, type TypeDocOptions} from "typedoc"
import {test} from "uvu"
import {equal as eq} from "uvu/assert"
import {Console} from "./console.ts"
import {compute} from "./main.ts"

const pipe = promisify(pipeline)

test.before(() => {
Console.shared.mute()
})

test.after(() => {
Console.shared.unmute()
})

for (const f of await readdir("fixtures")) {
const t = await setupTest(f)

test(`${f}: ${t.name}`, async () => {
const o = await setupReflection(f, t.options)

const a = t.collection
const e = await process(o)

// TODO: handling cases where the equality test has not been met
for (const x of a) {
for (const y of e) {
if (x instanceof GroupEntity || y instanceof GroupEntity) {
continue // TODO
}
if (y.id === x.id) {
eq(x.declaration.signature.verbose, y.declaration.signature.verbose)
}
}
}
})
}

test.run()

interface Test {
name: string
options: Partial<TypeDocOptions>
collection: Entity[]
}

async function setupTest(n: string): Promise<Test> {
const m = await import(`../fixtures/${n}/test.ts`)
const t: Test = {name: m.name, options: {}, collection: m.collection}
if (m.options) {
t.options = m.options
}
return t
}

async function setupReflection(n: string, opts: Partial<TypeDocOptions>): Promise<J.ProjectReflection> {
const d = path.join("fixtures", n)
const e = path.join(d, "main.ts")
const c = path.join(d, "tsconfig.json")

const a = await Application.bootstrapWithPlugins({
entryPoints: [e],
logLevel: "None",
name: path.basename(d),
tsconfig: c,
...opts,
})

const p = await a.convert()
if (!p) {
throw new Error("Project is missing")
}

return a.serializer.projectToObject(p, d)
}

export async function process(o: J.ProjectReflection): Promise<Entity[]> {
const tp = new Transport(o)
const tf = new Transformer(tp)

await pipe(tp.toReadable(), tf, tp.toWritable())

compute(tp)
return tp.entities
}
4 changes: 4 additions & 0 deletions packages/typedoc-signature/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@
"test": "pnpm test:types && pnpm test:unit"
},
"dependencies": {
"@onlyoffice/console": "workspace:^",
"@onlyoffice/library-declaration": "workspace:^",
"@onlyoffice/signature": "workspace:^",
"@onlyoffice/typedoc-transformer": "workspace:^",
"@onlyoffice/typedoc-transport": "workspace:^",
"@onlyoffice/typedoc-util-is-reflection": "workspace:^",
"@onlyoffice/typedoc-util-is-type": "workspace:^",
"typedoc": "0.26.11",
"typescript": "5.4.5"
},
Expand Down

0 comments on commit b6fcfc3

Please sign in to comment.