mirror of
https://github.com/oxc-project/oxc.git
synced 2026-09-14 19:36:11 +08:00
1193c9dbaf
dogfood
53 lines
1.3 KiB
TypeScript
53 lines
1.3 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import { isolatedDeclaration, isolatedDeclarationSync } from "../index";
|
|
|
|
describe("isolated declaration", () => {
|
|
const code = `
|
|
/**
|
|
* jsdoc 1
|
|
*/
|
|
export class A {
|
|
/**
|
|
* jsdoc 2
|
|
*/
|
|
foo = "bar";
|
|
}
|
|
// Do not keep normal comments
|
|
export class B {}
|
|
`;
|
|
|
|
it("matches output", () => {
|
|
const ret = isolatedDeclarationSync("test.ts", code, { sourcemap: true });
|
|
expect(ret).toMatchObject({
|
|
code:
|
|
"/**\n"
|
|
+ "* jsdoc 1\n"
|
|
+ "*/\n"
|
|
+ "export declare class A {\n"
|
|
+ "\t/**\n"
|
|
+ "\t* jsdoc 2\n"
|
|
+ "\t*/\n"
|
|
+ "\tfoo: string;\n"
|
|
+ "}\n"
|
|
+ "export declare class B {}\n",
|
|
map: {
|
|
names: [],
|
|
sources: ["test.ts"],
|
|
sourcesContent: [code],
|
|
version: 3,
|
|
},
|
|
errors: [],
|
|
});
|
|
});
|
|
|
|
it("produces same result as sync", async () => {
|
|
const syncResult = isolatedDeclarationSync("test.ts", code, { sourcemap: true });
|
|
const asyncResult = await isolatedDeclaration("test.ts", code, { sourcemap: true });
|
|
|
|
expect(asyncResult.code).toEqual(syncResult.code);
|
|
expect(asyncResult.errors.length).toBe(syncResult.errors.length);
|
|
expect(asyncResult.map).toMatchObject(syncResult.map!);
|
|
});
|
|
});
|