Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable console logging for tests #124

Merged
merged 4 commits into from
Apr 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"jsdoc": "^3.6.3",
"jsdoc-api": "^5.0.3",
"mocha": "^5.2.0",
"object-to-spawn-args": "^2.0.0",
"ts-node": "^7.0.1"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion test/expected/namespace_all.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ declare namespace FoobarNS {
* @param [opt_this = 10] - An object.
* @param [opt_2 = 10] - An object.
*/
f<S>(f: FoobarNS.Foo.FCallback, opt_this?: any, opt_2?: number[] | {
f<S>(f: FoobarNS.Foo.FCallback, opt_this?: number, opt_2?: number[] | {
[key: number]: string[];
}): void;
}
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/namespace_all.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ FoobarNS.Foo = function Foo() {
/**
* A generic method.
* @param {FoobarNS.Foo.FCallback} f A function.
* @param [opt_this=10] An object.
* @param {number} [opt_this=10] An object.
* @param {number[]|object<number, string[]>} [opt_2=10] An object.
* @template S
*/
Expand Down
9 changes: 3 additions & 6 deletions test/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
// tslint:disable-next-line
/// <reference path="../typings/jsdoc-api.d.ts" />

import * as fs from 'fs';
import * as path from 'path';
import * as jsdocApi from 'jsdoc-api';
import { expect } from 'chai';
import { renderSync } from './render';

const DEST_DIR = path.resolve(path.join(__dirname, '../_temp'));
const DATA_DIR = path.resolve(path.join(__dirname, '../fixtures'));
Expand All @@ -19,12 +16,12 @@ before(() => {
});

export function compileJsdoc(sourcePath: string) {
jsdocApi.renderSync({
renderSync({
files: sourcePath,
cache: false,
destination: DEST_DIR,
configure: CONFIG_PATH
} as any);
});
}

export function expectJsDoc(fileName: string) {
Expand Down
88 changes: 88 additions & 0 deletions test/lib/jsdoc-api.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import Cache from 'cache-point';
import FileSet from 'file-set';

export namespace JsdocApi {
function explain(options: JsdocOptions): Promise<any[]>;
function explainSync(options: JsdocOptions): any[];
function renderSync(options: JsdocOptions): void;
}

export interface JsdocOptions {
/** One or more filenames to process. Either this or `source` must be supplied. */
files?: string|string[];
/** A string containing source code to process. Either this or `source` must be supplied. */
source?: string;
/** Set to `true` to cache the output - future invocations with the same input will return immediately. */
cache?: boolean;
/** Only display symbols with the given access: "public", "protected", "private" or "undefined", or "all" for all access levels. Default: all except "private". */
access?: string;
/** The path to the configuration file. Default: path/to/jsdoc/conf.json. */
configure?: string;
/** The path to the output folder. Use "console" to dump data to the console. Default: ./out/. */
destination?: string;
/** Assume this encoding when reading all source files. Default: utf8. */
encoding?: string;
/** Display symbols marked with the `@private` tag. Equivalent to "--access all". Default: false. */
private?: boolean;
/** The path to the project's package file. Default: path/to/sourcefiles/package.json */
package?: string;
/** Treat errors as fatal errors, and treat warnings as errors. Default: false. */
pedantic?: boolean;
/** A query string to parse and store in jsdoc.env.opts.query. Example: foo=bar&baz=true. */
query?: string;
/** Recurse into subdirectories when scanning for source files and tutorials. */
recurse?: boolean;
/** The path to the project's README file. Default: path/to/sourcefiles/README.md. */
readme?: string;
/** The path to the template to use. Default: path/to/jsdoc/templates/default. */
template?: string;
/** Directory in which JSDoc should search for tutorials. */
tutorials?: string;
}

export class TempFile {
path: string;
}

/**
* Command base class. The command `receiver` being the `child_process` module.
*/
export abstract class JsdocCommand {
cache?: Cache;
tempFile: TempFile | null;
options: JsdocOptions;
jsdocOptions: JsdocOptions;
jsdocPath: string;
inputFileSet?: FileSet;
output?: any;

constructor (options: JsdocOptions, cache?: Cache);

abstract getOutput(): any;

/**
* Template method returning the jsdoc output. Invoke later (for example via a command-queuing system) or immediately as required.
*
* 1. preExecute
* 2. validate
* 3. getOutput
* 4. postExecute
*
*/
execute(): any;

/**
* Perform pre-execution processing here, e.g. expand input glob patterns.
*/
preExecute(): void;

/**
* Return an Error instance if execution should not proceed.
*/
validate(): null | Error;

/**
* perform post-execution cleanup
*/
postExecute(): void;
}
3 changes: 3 additions & 0 deletions test/lib/jsdoc-api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
exports.JsdocApi = require('jsdoc-api');
exports.JsdocCommand = require('jsdoc-api/lib/jsdoc-command');
exports.TempFile = require('jsdoc-api/lib/temp-file');
28 changes: 28 additions & 0 deletions test/lib/render.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { JsdocCommand, JsdocOptions } from './jsdoc-api';
import { spawnSync } from 'child_process';

const toSpawnArgs = require('object-to-spawn-args') as
(object: object, options?: { quote?: boolean; optionEqualsValue?: boolean }) => string[];

class RenderSync extends JsdocCommand {
getOutput (err?: Error) {
if (err) throw err;

const jsdocArgs = toSpawnArgs(this.jsdocOptions)
.concat(this.options.source ? this.tempFile!.path : this.options.files!);

jsdocArgs.unshift(this.jsdocPath);

spawnSync('node', jsdocArgs, {
cwd: process.cwd(),
env: process.env,
stdio: 'inherit',
encoding: 'utf-8'
});
}
}

export function renderSync(options: JsdocOptions) {
const command = new RenderSync(options);
return command.execute();
}
5 changes: 0 additions & 5 deletions test/typings/jsdoc-api.d.ts

This file was deleted.