Skip to content

Commit

Permalink
Fix error message for sl (steam locomotive) (#15052)
Browse files Browse the repository at this point in the history
* Fix error message for `sl` (steam locomotive)

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: #14046
  • Loading branch information
rmartine-ias authored May 8, 2024
1 parent 654dbd6 commit 85bab0e
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 42 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
15 changes: 1 addition & 14 deletions packages/jest-changed-files/src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,14 @@
*/

import * as path from 'path';
import {types} from 'util';
import execa = require('execa');
import type {SCMAdapter} from './types';

const findChangedFilesUsingCommand = async (
args: Array<string>,
cwd: string,
): Promise<Array<string>> => {
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')
Expand Down
15 changes: 1 addition & 14 deletions packages/jest-changed-files/src/hg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/

import * as path from 'path';
import {types} from 'util';
import execa = require('execa');
import type {SCMAdapter} from './types';

Expand All @@ -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')
Expand Down
15 changes: 1 addition & 14 deletions packages/jest-changed-files/src/sl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/

import * as path from 'path';
import {types} from 'util';
import execa = require('execa');
import type {SCMAdapter} from './types';

Expand All @@ -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')
Expand Down

0 comments on commit 85bab0e

Please sign in to comment.