@oclif/test 4.0.1-beta.1 → 4.0.1-dev.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.ts CHANGED
@@ -9,7 +9,7 @@ export declare function captureOutput<T>(fn: () => Promise<unknown>, opts?: Capt
9
9
  stderr: string;
10
10
  stdout: string;
11
11
  }>;
12
- export declare function runCommand<T>(args: string | string[], loadOpts?: Interfaces.LoadOptions, captureOpts?: CaptureOptions): Promise<{
12
+ export declare function runCommand<T>(args: string[], loadOpts?: Interfaces.LoadOptions, captureOpts?: CaptureOptions): Promise<{
13
13
  error?: Error & Partial<Errors.CLIError>;
14
14
  result?: T;
15
15
  stderr: string;
package/lib/index.js CHANGED
@@ -8,13 +8,12 @@ const core_1 = require("@oclif/core");
8
8
  const ansis_1 = __importDefault(require("ansis"));
9
9
  const debug_1 = __importDefault(require("debug"));
10
10
  const node_path_1 = require("node:path");
11
- const debug = (0, debug_1.default)('oclif-test');
11
+ const debug = (0, debug_1.default)('test');
12
12
  const RECORD_OPTIONS = {
13
13
  print: false,
14
14
  stripAnsi: true,
15
15
  };
16
16
  const originals = {
17
- NODE_ENV: process.env.NODE_ENV,
18
17
  stderr: process.stderr.write,
19
18
  stdout: process.stdout.write,
20
19
  };
@@ -43,7 +42,6 @@ function mockedStderr(str, encoding, cb) {
43
42
  const restore = () => {
44
43
  process.stderr.write = originals.stderr;
45
44
  process.stdout.write = originals.stdout;
46
- process.env.NODE_ENV = originals.NODE_ENV;
47
45
  };
48
46
  const reset = () => {
49
47
  output.stderr = [];
@@ -59,23 +57,18 @@ function traverseFilePathUntil(filename, predicate) {
59
57
  }
60
58
  return current;
61
59
  }
62
- function findRoot() {
63
- return (process.env.OCLIF_TEST_ROOT ??
64
- // eslint-disable-next-line unicorn/prefer-module
65
- Object.values(require.cache).find((m) => m?.children.includes(module))?.filename ??
66
- traverseFilePathUntil(
67
- // eslint-disable-next-line unicorn/prefer-module
68
- require.main?.path ?? module.path, (p) => !(p.includes('node_modules') || p.includes('.pnpm') || p.includes('.yarn'))));
69
- }
70
60
  function makeLoadOptions(loadOpts) {
71
- return loadOpts ?? { root: findRoot() };
61
+ return (loadOpts ?? {
62
+ root: traverseFilePathUntil(
63
+ // eslint-disable-next-line unicorn/prefer-module
64
+ require.main?.path ?? module.path, (p) => !(p.includes('node_modules') || p.includes('.pnpm') || p.includes('.yarn'))),
65
+ });
72
66
  }
73
67
  async function captureOutput(fn, opts) {
74
68
  RECORD_OPTIONS.print = opts?.print ?? false;
75
69
  RECORD_OPTIONS.stripAnsi = opts?.stripAnsi ?? true;
76
70
  process.stderr.write = mockedStderr;
77
71
  process.stdout.write = mockedStdout;
78
- process.env.NODE_ENV = 'test';
79
72
  try {
80
73
  const result = await fn();
81
74
  return {
@@ -100,17 +93,13 @@ async function captureOutput(fn, opts) {
100
93
  exports.captureOutput = captureOutput;
101
94
  async function runCommand(args, loadOpts, captureOpts) {
102
95
  const loadOptions = makeLoadOptions(loadOpts);
103
- const argsArray = (Array.isArray(args) ? args : [args]).join(' ').split(' ');
104
- const [id, ...rest] = argsArray;
105
- const finalArgs = id === '.' ? rest : argsArray;
106
- debug('loadOpts: %O', loadOptions);
107
- debug('args: %O', finalArgs);
108
- return captureOutput(async () => (0, core_1.run)(finalArgs, loadOptions), captureOpts);
96
+ debug('loadOpts: %O', loadOpts);
97
+ return captureOutput(async () => (0, core_1.run)(args, loadOptions), captureOpts);
109
98
  }
110
99
  exports.runCommand = runCommand;
111
100
  async function runHook(hook, options, loadOpts, recordOpts) {
112
101
  const loadOptions = makeLoadOptions(loadOpts);
113
- debug('loadOpts: %O', loadOptions);
102
+ debug('loadOpts: %O', loadOpts);
114
103
  return captureOutput(async () => {
115
104
  const config = await core_1.Config.load(loadOptions);
116
105
  return config.runHook(hook, options);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@oclif/test",
3
3
  "description": "test helpers for oclif components",
4
- "version": "4.0.1-beta.1",
4
+ "version": "4.0.1-dev.0",
5
5
  "author": "Salesforce",
6
6
  "bugs": "https://github.com/oclif/test/issues",
7
7
  "dependencies": {
@@ -15,11 +15,9 @@
15
15
  "@commitlint/config-conventional": "^18.6.3",
16
16
  "@oclif/core": "^4.0.0-beta.6",
17
17
  "@oclif/prettier-config": "^0.2.1",
18
- "@types/chai": "^4.3.16",
19
18
  "@types/debug": "^4.1.12",
20
19
  "@types/mocha": "^10",
21
20
  "@types/node": "^18",
22
- "chai": "^5.1.1",
23
21
  "commitlint": "^18.6.1",
24
22
  "eslint": "^8.57.0",
25
23
  "eslint-config-oclif": "^5.2.0",
@@ -30,7 +28,7 @@
30
28
  "mocha": "^10",
31
29
  "prettier": "^3.2.5",
32
30
  "shx": "^0.3.3",
33
- "tsx": "^4.10.2",
31
+ "ts-node": "^10.9.2",
34
32
  "typescript": "^5.4.5"
35
33
  },
36
34
  "engines": {