@oclif/test 4.0.9 → 4.1.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/README.md CHANGED
@@ -14,6 +14,8 @@ See the [V4 Migration Guide](./MIGRATION.md) if you are migrating from v3 or old
14
14
 
15
15
  `@oclif/test` provides a handful of utilities that make it easy to test your [oclif](https://oclif.io) CLI.
16
16
 
17
+ **NOTE for jest users** - in order for these utilities to capture all output to the terminal, you must set `verbose: true` in your jest config to prevent jest from supressing any output. See https://jestjs.io/docs/configuration#verbose-boolean for more
18
+
17
19
  ### `captureOutput`
18
20
 
19
21
  `captureOutput` allows you to get the stdout, stderr, return value, and error of the callback you provide it. This makes it possible to assert that certain strings were printed to stdout and stderr or that the callback failed with the expected error or succeeded with the expected result.
@@ -22,6 +24,7 @@ See the [V4 Migration Guide](./MIGRATION.md) if you are migrating from v3 or old
22
24
 
23
25
  - `print` - Print everything that goes to stdout and stderr.
24
26
  - `stripAnsi` - Strip ansi codes from everything that goes to stdout and stderr. Defaults to true.
27
+ - `testNodeEnv` - Sets the `NODE_ENV` value when capturing output. Defaults to `'test'`.
25
28
 
26
29
  See the [tests](./test/capture-output.test.ts) for example usage.
27
30
 
package/lib/index.d.ts CHANGED
@@ -2,6 +2,7 @@ import { Errors, Interfaces } from '@oclif/core';
2
2
  type CaptureOptions = {
3
3
  print?: boolean;
4
4
  stripAnsi?: boolean;
5
+ testNodeEnv?: string;
5
6
  };
6
7
  type CaptureResult<T> = {
7
8
  error?: Error & Partial<Errors.CLIError>;
package/lib/index.js CHANGED
@@ -21,7 +21,7 @@ function traverseFilePathUntil(filename, predicate) {
21
21
  function findRoot() {
22
22
  return (process.env.OCLIF_TEST_ROOT ??
23
23
  // eslint-disable-next-line unicorn/prefer-module
24
- Object.values(require.cache).find((m) => m?.children.includes(module))?.filename ??
24
+ Object.values(require.cache).find((m) => m?.children?.includes(module))?.filename ??
25
25
  traverseFilePathUntil(
26
26
  // eslint-disable-next-line unicorn/prefer-module
27
27
  require.main?.path ?? module.path, (p) => !(p.includes('node_modules') || p.includes('.pnpm') || p.includes('.yarn'))));
@@ -59,6 +59,7 @@ function splitString(str) {
59
59
  async function captureOutput(fn, opts) {
60
60
  const print = opts?.print ?? false;
61
61
  const stripAnsi = opts?.stripAnsi ?? true;
62
+ const testNodeEnv = opts?.testNodeEnv || 'test';
62
63
  const originals = {
63
64
  NODE_ENV: process.env.NODE_ENV,
64
65
  stderr: process.stderr.write,
@@ -86,7 +87,7 @@ async function captureOutput(fn, opts) {
86
87
  };
87
88
  process.stdout.write = mock('stdout');
88
89
  process.stderr.write = mock('stderr');
89
- process.env.NODE_ENV = 'test';
90
+ process.env.NODE_ENV = testNodeEnv;
90
91
  try {
91
92
  const result = await fn();
92
93
  return {
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.9",
4
+ "version": "4.1.0",
5
5
  "author": "Salesforce",
6
6
  "bugs": "https://github.com/oclif/test/issues",
7
7
  "dependencies": {
@@ -13,25 +13,25 @@
13
13
  },
14
14
  "devDependencies": {
15
15
  "@commitlint/config-conventional": "^18.6.3",
16
- "@oclif/core": "^4.0.17",
16
+ "@oclif/core": "^4.0.28",
17
17
  "@oclif/prettier-config": "^0.2.1",
18
- "@types/chai": "^4.3.17",
18
+ "@types/chai": "^4.3.20",
19
19
  "@types/debug": "^4.1.12",
20
20
  "@types/mocha": "^10",
21
21
  "@types/node": "^18",
22
22
  "chai": "^5.1.1",
23
23
  "commitlint": "^18.6.1",
24
- "eslint": "^8.57.0",
24
+ "eslint": "^8.57.1",
25
25
  "eslint-config-oclif": "^5.2.1",
26
- "eslint-config-oclif-typescript": "^3.1.9",
26
+ "eslint-config-oclif-typescript": "^3.1.12",
27
27
  "eslint-config-prettier": "^9.1.0",
28
- "husky": "^9.1.4",
29
- "lint-staged": "^15.2.9",
28
+ "husky": "^9.1.6",
29
+ "lint-staged": "^15.2.10",
30
30
  "mocha": "^10",
31
31
  "prettier": "^3.3.3",
32
32
  "shx": "^0.3.3",
33
- "tsx": "^4.18.0",
34
- "typescript": "^5.5.4"
33
+ "tsx": "^4.19.1",
34
+ "typescript": "^5.6.3"
35
35
  },
36
36
  "engines": {
37
37
  "node": ">=18.0.0"