refactor: decouple test runner from CLI tool

Use `npm run test` to run tests. The CLI no longer supports the `-T/--test` and `--match` flags.
This commit is contained in:
Jeff Williams 2024-12-07 14:23:39 -08:00
parent 0a9b3249a2
commit ac9ea1a172
No known key found for this signature in database
5 changed files with 18 additions and 35 deletions

View File

@ -13,15 +13,16 @@
See the License for the specific language governing permissions and
limitations under the License.
*/
import path from 'node:path';
import { execa } from 'execa';
import { task } from 'hereby';
import { LicenseChecker } from 'js-green-licenses';
import runTests from './packages/jsdoc/test/index.js';
const BIN_DIR = 'node_modules/.bin';
const JSDOC_BIN = 'packages/jsdoc/jsdoc.js';
const NODE_BIN = process.execPath;
const sourceGlob = ['*.cjs', '*.js', 'packages/**/*/*.cjs', 'packages/**/*.js'];
@ -107,10 +108,7 @@ export const lint = task({
export const test = task({
name: 'test',
run: async () => {
await execa(NODE_BIN, [JSDOC_BIN, '-T'], {
stdout: process.stdout,
stderr: process.stderr,
});
await runTests();
},
});

View File

@ -13,6 +13,7 @@
See the License for the specific language governing permissions and
limitations under the License.
*/
import querystring from 'node:querystring';
import { cast } from '@jsdoc/util';
@ -68,10 +69,6 @@ export const flags = {
boolean: true,
description: 'Print help information and exit.',
},
match: {
description: 'Run only tests whose names contain this value.',
requiresArg: true,
},
package: {
alias: 'P',
description: 'The path to the `package.json` file to use.',
@ -104,11 +101,6 @@ export const flags = {
description: 'The template package to use.',
requiresArg: true,
},
test: {
alias: 'T',
boolean: true,
description: 'Run all tests and exit.',
},
verbose: {
boolean: true,
description: 'Log detailed information to the console.',

View File

@ -18,11 +18,8 @@ import fs from 'node:fs';
import { fileURLToPath } from 'node:url';
import Engine from '@jsdoc/cli';
import { Dictionary } from '@jsdoc/tag';
import stripBom from 'strip-bom';
import test from './test/index.js';
function createEngine() {
const packageJsonPath = fileURLToPath(new URL('package.json', import.meta.url));
// Allow this to throw; if we can't read our own package file, something is really wrong.
@ -67,16 +64,6 @@ export function logFinish() {
}
}
export async function runTests() {
const { env } = engine;
let result;
env.tags = Dictionary.fromConfig(env);
result = await test(env);
return result.overallStatus === 'failed' ? 1 : 0;
}
export function runCommand() {
let cmd;
const { options } = engine.env;
@ -89,8 +76,6 @@ export function runCommand() {
} else if (options.help) {
// TODO: Can we just pass the function directly?
cmd = () => engine.printHelp();
} else if (options.test) {
cmd = runTests;
} else if (options.version) {
cmd = () => engine.printVersion();
} else {

View File

@ -13,9 +13,13 @@
See the License for the specific language governing permissions and
limitations under the License.
*/
import { config, Env } from '@jsdoc/core';
import { Dictionary } from '@jsdoc/tag';
import Jasmine from 'jasmine';
import ConsoleReporter from 'jasmine-console-reporter';
const DEFAULT_CONFIG = config.defaultConfig;
const SCHEMA_SPEC = 'packages/jsdoc/test/specs/validate.js';
const SPEC_FILES = [
`!${SCHEMA_SPEC}`,
@ -25,9 +29,9 @@ const SPEC_FILES = [
SCHEMA_SPEC,
];
export default function test(env) {
export default function test() {
const env = new Env();
const jasmine = new Jasmine();
const matcher = env.options.matcher;
const reporter = new ConsoleReporter({
beep: false,
verbosity: {
@ -52,11 +56,14 @@ export default function test(env) {
stopSpecOnExpectationFailure: false,
});
// Make dependencies available to all tests.
env.conf = DEFAULT_CONFIG;
env.tags = Dictionary.fromConfig(env);
// Make JSDoc environment available to all tests.
if (!global.jsdoc) {
global.jsdoc = {};
}
// TODO: remove `global.jsdoc.deps`
global.jsdoc.deps = global.jsdoc.env = env;
return jasmine.execute(SPEC_FILES, matcher);
return jasmine.execute(SPEC_FILES);
}

View File

@ -13,6 +13,7 @@
See the License for the specific language governing permissions and
limitations under the License.
*/
import path from 'node:path';
import { Doclet } from '@jsdoc/doclet';
@ -26,7 +27,7 @@ describe('@overview tag', () => {
let srcParser;
const sourceFiles = env.sourceFiles.slice();
const sourcePaths = env.opts._.slice();
const sourcePaths = env.opts._?.slice();
beforeEach(() => {
env.opts._ = [path.normalize(`${__dirname}/../../fixtures`)];