From 7edc18d986fd8c9cfda473e9937e4c1a0fc39a11 Mon Sep 17 00:00:00 2001 From: Riley Martine Date: Fri, 3 May 2024 15:37:07 -0600 Subject: [PATCH 1/2] Fix error message for `sl` (steam locomotive) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When running jest in watch mode, with `sl` installed (https://github.com/mtoyoda/sl), it errors out with the following message: ``` ● Test suite failed to run thrown: [Error] ``` This is bad because the error is extremely hard to debug. This change makes it error as follows: ``` ● Test suite failed to run Command failed with ENAMETOOLONG: sl status -amnu /Users/rmartine/dev/ias-backstage/packages/backend spawn ENAMETOOLONG ``` This, at least, points people in the right direction. See also: https://github.com/jestjs/jest/issues/14046 --- packages/jest-changed-files/src/sl.ts | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/packages/jest-changed-files/src/sl.ts b/packages/jest-changed-files/src/sl.ts index 50ee99122757..4230e3485290 100644 --- a/packages/jest-changed-files/src/sl.ts +++ b/packages/jest-changed-files/src/sl.ts @@ -7,7 +7,6 @@ */ import * as path from 'path'; -import {types} from 'util'; import execa = require('execa'); import type {SCMAdapter} from './types'; @@ -34,19 +33,7 @@ const adapter: SCMAdapter = { } args.push(...includePaths); - let result: execa.ExecaReturnValue; - - try { - result = await execa('sl', args, {cwd, env}); - } catch (error) { - if (types.isNativeError(error)) { - const err = error as execa.ExecaError; - // TODO: Should we keep the original `message`? - err.message = err.stderr; - } - - throw error; - } + const result = await execa('sl', args, {cwd, env}); return result.stdout .split('\n') From 0067f961c8936618cc4116a5de13e50640d1d65d Mon Sep 17 00:00:00 2001 From: Riley Martine Date: Mon, 6 May 2024 19:48:45 -0600 Subject: [PATCH 2/2] Make other VCS errors print as well --- CHANGELOG.md | 1 + packages/jest-changed-files/src/git.ts | 15 +-------------- packages/jest-changed-files/src/hg.ts | 15 +-------------- 3 files changed, 3 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 070258d7a0b3..4ef78c06e85d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ - `[babel-plugin-jest-hoist]` Use `denylist` instead of the deprecated `blacklist` for Babel 8 support ([#14109](https://github.com/jestjs/jest/pull/14109)) - `[expect]` Check error instance type for `toThrow/toThrowError` ([#14576](https://github.com/jestjs/jest/pull/14576)) +- `[jest-changed-files]` Print underlying errors when VCS commands fail ([#15052](https://github.com/jestjs/jest/pull/15052)) - `[jest-circus]` [**BREAKING**] Prevent false test failures caused by promise rejections handled asynchronously ([#14315](https://github.com/jestjs/jest/pull/14315)) - `[jest-circus]` Replace recursive `makeTestResults` implementation with iterative one ([#14760](https://github.com/jestjs/jest/pull/14760)) - `[jest-circus]` Omit `expect.hasAssertions()` errors if a test already has errors ([#14866](https://github.com/jestjs/jest/pull/14866)) diff --git a/packages/jest-changed-files/src/git.ts b/packages/jest-changed-files/src/git.ts index 6695d9a885ce..52921819fb63 100644 --- a/packages/jest-changed-files/src/git.ts +++ b/packages/jest-changed-files/src/git.ts @@ -7,7 +7,6 @@ */ import * as path from 'path'; -import {types} from 'util'; import execa = require('execa'); import type {SCMAdapter} from './types'; @@ -15,19 +14,7 @@ const findChangedFilesUsingCommand = async ( args: Array, cwd: string, ): Promise> => { - let result: execa.ExecaReturnValue; - - try { - result = await execa('git', args, {cwd}); - } catch (error) { - if (types.isNativeError(error)) { - const err = error as execa.ExecaError; - // TODO: Should we keep the original `message`? - err.message = err.stderr; - } - - throw error; - } + const result = await execa('git', args, {cwd}); return result.stdout .split('\n') diff --git a/packages/jest-changed-files/src/hg.ts b/packages/jest-changed-files/src/hg.ts index f9e7398d8a2f..4083082d69ad 100644 --- a/packages/jest-changed-files/src/hg.ts +++ b/packages/jest-changed-files/src/hg.ts @@ -7,7 +7,6 @@ */ import * as path from 'path'; -import {types} from 'util'; import execa = require('execa'); import type {SCMAdapter} from './types'; @@ -30,19 +29,7 @@ const adapter: SCMAdapter = { } args.push(...includePaths); - let result: execa.ExecaReturnValue; - - try { - result = await execa('hg', args, {cwd, env}); - } catch (error) { - if (types.isNativeError(error)) { - const err = error as execa.ExecaError; - // TODO: Should we keep the original `message`? - err.message = err.stderr; - } - - throw error; - } + const result = await execa('hg', args, {cwd, env}); return result.stdout .split('\n')