Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@oclif/test

Package Overview
Dependencies
Maintainers
3
Versions
157
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@oclif/test - npm Package Compare versions

Comparing version 3.2.15 to 4.0.1-beta.0

139

lib/index.d.ts

@@ -1,117 +0,24 @@

/// <reference types="sinon" />
import * as fancyTest from 'fancy-test';
import { loadConfig } from './load-config';
export declare const test: fancyTest.FancyTypes.Base<fancyTest.FancyTypes.Context, {
skip: {
output: unknown;
args: [];
};
} & {
only: {
output: unknown;
args: [];
};
} & {
retries: {
output: unknown;
args: any[];
};
} & {
catch: {
output: {
error: Error;
};
args: [arg: string | RegExp | ((err: Error) => any), opts?: {
raiseIfNotThrown?: boolean | undefined;
} | undefined];
};
} & {
env: {
output: unknown;
args: [env: {
[k: string]: string | null | undefined;
}, opts?: fancyTest.FancyTypes.EnvOptions | undefined];
};
} & {
stub: {
output: {
sandbox: import("sinon").SinonSandbox;
};
args: [object: any, path: any, fn: (stub: import("sinon").SinonStub<any[], any>) => import("sinon").SinonStub<any[], any>];
};
} & {
stdin: {
output: unknown;
args: [input: string, delay?: number | undefined];
};
} & {
stderr: {
output: {
readonly stderr: string;
};
args: [opts?: {
print?: boolean | undefined;
stripColor?: boolean | undefined;
} | undefined];
};
} & {
stdout: {
output: {
readonly stdout: string;
};
args: [opts?: {
print?: boolean | undefined;
stripColor?: boolean | undefined;
} | undefined];
};
} & {
nock: {
output: {
nock: number;
};
args: [host: string, options: fancyTest.FancyTypes.NockOptions | fancyTest.FancyTypes.NockCallback, cb?: fancyTest.FancyTypes.NockCallback | undefined];
};
} & {
timeout: {
output: {
timeout: number;
};
args: [timeout?: number | undefined];
};
} & {
loadConfig: {
output: {
config: import("@oclif/core/lib/interfaces").Config;
};
args: [opts?: loadConfig.Options | undefined];
};
} & {
command: {
output: {
config: import("@oclif/core/lib/interfaces").Config;
expectation: string;
returned: unknown;
};
args: [args: string | string[], opts?: loadConfig.Options | undefined];
};
} & {
exit: {
output: {
error: import("@oclif/core/lib/errors").CLIError;
};
args: [code?: number | undefined];
};
} & {
hook: {
output: {
config: import("@oclif/core/lib/interfaces").Config;
expectation: string;
returned: unknown;
};
args: [event: string, hookOpts?: Record<string, unknown> | undefined, options?: loadConfig.Options | undefined];
};
import { Errors, Interfaces } from '@oclif/core';
type CaptureOptions = {
print?: boolean;
stripAnsi?: boolean;
};
export declare function captureOutput<T>(fn: () => Promise<unknown>, opts?: CaptureOptions): Promise<{
error?: Error & Partial<Errors.CLIError>;
result?: T;
stderr: string;
stdout: string;
}>;
export default test;
export { command } from './command';
export { Config } from '@oclif/core';
export { FancyTypes, expect } from 'fancy-test';
export declare function runCommand<T>(args: string | string[], loadOpts?: Interfaces.LoadOptions, captureOpts?: CaptureOptions): Promise<{
error?: Error & Partial<Errors.CLIError>;
result?: T;
stderr: string;
stdout: string;
}>;
export declare function runHook<T>(hook: string, options: Record<string, unknown>, loadOpts?: Interfaces.LoadOptions, recordOpts?: CaptureOptions): Promise<{
error?: Error & Partial<Errors.CLIError>;
result?: T;
stderr: string;
stdout: string;
}>;
export {};

151

lib/index.js
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -29,9 +6,49 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

Object.defineProperty(exports, "__esModule", { value: true });
exports.expect = exports.FancyTypes = exports.Config = exports.command = exports.test = void 0;
const fancyTest = __importStar(require("fancy-test"));
exports.runHook = exports.runCommand = exports.captureOutput = void 0;
const core_1 = require("@oclif/core");
const ansis_1 = __importDefault(require("ansis"));
const debug_1 = __importDefault(require("debug"));
const node_path_1 = require("node:path");
const command_1 = require("./command");
const exit_1 = __importDefault(require("./exit"));
const hook_1 = __importDefault(require("./hook"));
const load_config_1 = require("./load-config");
const debug = (0, debug_1.default)('oclif-test');
const RECORD_OPTIONS = {
print: false,
stripAnsi: true,
};
const originals = {
stderr: process.stderr.write,
stdout: process.stdout.write,
};
const output = {
stderr: [],
stdout: [],
};
function mockedStdout(str, encoding, cb) {
output.stdout.push(str);
if (!RECORD_OPTIONS.print)
return true;
if (typeof encoding === 'string') {
return originals.stdout.bind(process.stdout)(str, encoding, cb);
}
return originals.stdout.bind(process.stdout)(str, cb);
}
function mockedStderr(str, encoding, cb) {
output.stderr.push(str);
if (!RECORD_OPTIONS.print)
return true;
if (typeof encoding === 'string') {
return originals.stdout.bind(process.stderr)(str, encoding, cb);
}
return originals.stdout.bind(process.stderr)(str, cb);
}
const restore = () => {
process.stderr.write = originals.stderr;
process.stdout.write = originals.stdout;
};
const reset = () => {
output.stderr = [];
output.stdout = [];
};
const toString = (str) => RECORD_OPTIONS.stripAnsi ? ansis_1.default.strip(str.toString()) : str.toString();
const getStderr = () => output.stderr.map((b) => toString(b)).join('');
const getStdout = () => output.stdout.map((b) => toString(b)).join('');
function traverseFilePathUntil(filename, predicate) {

@@ -44,22 +61,58 @@ let current = filename;

}
/* eslint-disable unicorn/prefer-module */
load_config_1.loadConfig.root =
process.env.OCLIF_TEST_ROOT ??
function findRoot() {
return (process.env.OCLIF_TEST_ROOT ??
// eslint-disable-next-line unicorn/prefer-module
Object.values(require.cache).find((m) => m?.children.includes(module))?.filename ??
traverseFilePathUntil(require.main?.path ?? module.path, (p) => !(p.includes('node_modules') || p.includes('.pnpm') || p.includes('.yarn')));
/* eslint-enable unicorn/prefer-module */
// Using a named export to import fancy causes this issue: https://github.com/oclif/test/issues/516
exports.test = fancyTest.fancy
.register('loadConfig', load_config_1.loadConfig)
.register('command', command_1.command)
.register('exit', exit_1.default)
.register('hook', hook_1.default)
.env({ NODE_ENV: 'test' });
exports.default = exports.test;
var command_2 = require("./command");
Object.defineProperty(exports, "command", { enumerable: true, get: function () { return command_2.command; } });
var core_1 = require("@oclif/core");
Object.defineProperty(exports, "Config", { enumerable: true, get: function () { return core_1.Config; } });
var fancy_test_1 = require("fancy-test");
Object.defineProperty(exports, "FancyTypes", { enumerable: true, get: function () { return fancy_test_1.FancyTypes; } });
Object.defineProperty(exports, "expect", { enumerable: true, get: function () { return fancy_test_1.expect; } });
traverseFilePathUntil(
// eslint-disable-next-line unicorn/prefer-module
require.main?.path ?? module.path, (p) => !(p.includes('node_modules') || p.includes('.pnpm') || p.includes('.yarn'))));
}
function makeLoadOptions(loadOpts) {
return loadOpts ?? { root: findRoot() };
}
async function captureOutput(fn, opts) {
RECORD_OPTIONS.print = opts?.print ?? false;
RECORD_OPTIONS.stripAnsi = opts?.stripAnsi ?? true;
process.stderr.write = mockedStderr;
process.stdout.write = mockedStdout;
try {
const result = await fn();
return {
result: result,
stderr: getStderr(),
stdout: getStdout(),
};
}
catch (error) {
return {
...(error instanceof core_1.Errors.CLIError && { error }),
...(error instanceof Error && { error }),
stderr: getStderr(),
stdout: getStdout(),
};
}
finally {
restore();
reset();
}
}
exports.captureOutput = captureOutput;
async function runCommand(args, loadOpts, captureOpts) {
const loadOptions = makeLoadOptions(loadOpts);
const argsArray = (Array.isArray(args) ? args : [args]).join(' ').split(' ');
const [id, ...rest] = argsArray;
const finalArgs = id === '.' ? rest : argsArray;
debug('loadOpts: %O', loadOpts);
debug('args: %O', finalArgs);
return captureOutput(async () => (0, core_1.run)(finalArgs, loadOptions), captureOpts);
}
exports.runCommand = runCommand;
async function runHook(hook, options, loadOpts, recordOpts) {
const loadOptions = makeLoadOptions(loadOpts);
debug('loadOpts: %O', loadOpts);
return captureOutput(async () => {
const config = await core_1.Config.load(loadOptions);
return config.runHook(hook, options);
}, recordOpts);
}
exports.runHook = runHook;
{
"name": "@oclif/test",
"description": "test helpers for oclif components",
"version": "3.2.15",
"version": "4.0.1-beta.0",
"author": "Salesforce",
"bugs": "https://github.com/oclif/test/issues",
"dependencies": {
"@oclif/core": "^3.26.6",
"chai": "^4.4.1",
"fancy-test": "^3.0.15"
"ansis": "^3.2.0",
"debug": "^4.3.4"
},
"peerDependencies": {
"@oclif/core": "^4.0.0-beta.6"
},
"devDependencies": {
"@commitlint/config-conventional": "^18.6.3",
"@oclif/core": "^4.0.0-beta.6",
"@oclif/prettier-config": "^0.2.1",
"@types/cli-progress": "^3.11.5",
"@types/chai": "^4.3.16",
"@types/debug": "^4.1.12",
"@types/mocha": "^10",
"@types/node": "^18",
"chai": "^5.1.1",
"commitlint": "^18.6.1",

@@ -26,6 +31,5 @@ "eslint": "^8.57.0",

"mocha": "^10",
"nock": "^13.5.4",
"prettier": "^3.2.5",
"shx": "^0.3.3",
"ts-node": "^10.9.2",
"tsx": "^4.10.2",
"typescript": "^5.4.5"

@@ -32,0 +36,0 @@ },

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc