Skip to content

Commit f8b3900

Browse files
committed
chore: address review comments
1 parent ea03e83 commit f8b3900

1 file changed

Lines changed: 61 additions & 1 deletion

File tree

‎packages/ts-interface-generator/src/test/jsdocPreference.test.ts‎

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fs from "fs";
22
import path from "path";
33
import ts from "typescript";
44
import log from "loglevel";
5-
import { execSync } from "child_process";
5+
import { execSync, execFileSync } from "child_process";
66
import { generateInterfaces } from "../interfaceGenerationHelper";
77
import {
88
getAllKnownGlobals,
@@ -114,6 +114,66 @@ process.stdout.write(argv.jsdoc);`,
114114
});
115115
});
116116

117+
describe("CLI end-to-end (issue #542)", () => {
118+
const cliEntryPoint = path.resolve(
119+
__dirname,
120+
"../../dist/generateTSInterfaces.js",
121+
);
122+
const testCaseDir = path.resolve(
123+
__dirname,
124+
"testcases/tsconfig-path-relative",
125+
);
126+
const genFile = path.join(testCaseDir, "MyControl.gen.d.ts");
127+
128+
beforeAll(() => {
129+
if (!fs.existsSync(cliEntryPoint)) {
130+
execSync("npx tsc", { cwd: path.resolve(__dirname, "../..") });
131+
}
132+
});
133+
134+
afterEach(() => {
135+
// Restore original gen files
136+
execSync("git checkout -- .", { cwd: testCaseDir });
137+
});
138+
139+
test("--jsdoc minimal produces output without boilerplate JSDoc", () => {
140+
fs.unlinkSync(genFile);
141+
execFileSync("node", [cliEntryPoint, "--jsdoc", "minimal"], {
142+
cwd: testCaseDir,
143+
});
144+
const output = fs.readFileSync(genFile, "utf-8");
145+
146+
expect(output).toContain("getMyJSEnumVal(): MyJSEnum;");
147+
expect(output).not.toContain("@returns");
148+
expect(output).not.toContain("@param");
149+
expect(output).not.toContain("Gets current value of property");
150+
});
151+
152+
test("--jsdoc none produces output without any method-level JSDoc", () => {
153+
fs.unlinkSync(genFile);
154+
execFileSync("node", [cliEntryPoint, "--jsdoc", "none"], {
155+
cwd: testCaseDir,
156+
});
157+
const output = fs.readFileSync(genFile, "utf-8");
158+
159+
expect(output).toContain("getMyJSEnumVal(): MyJSEnum;");
160+
expect(output).not.toContain("@returns");
161+
expect(output).not.toContain("@param");
162+
});
163+
164+
test("--jsdoc verbose produces output with full boilerplate JSDoc", () => {
165+
fs.unlinkSync(genFile);
166+
execFileSync("node", [cliEntryPoint, "--jsdoc", "verbose"], {
167+
cwd: testCaseDir,
168+
});
169+
const output = fs.readFileSync(genFile, "utf-8");
170+
171+
expect(output).toContain("@returns");
172+
expect(output).toContain("@param");
173+
expect(output).toContain('Gets current value of property "myJSEnumVal"');
174+
});
175+
});
176+
117177
describe("JSDoc preference modes", () => {
118178
beforeAll(() => {
119179
jest.spyOn(log, "warn").mockImplementation(() => {});

0 commit comments

Comments
 (0)