Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abort sl root call if output resembles a steam locomotive #15053

Merged
merged 5 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,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-changed-files]` Abort `sl root` call if output resembles a steam locomotive ([#15053](https://github.com/jestjs/jest/pull/15053))
- `[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
26 changes: 25 additions & 1 deletion packages/jest-changed-files/src/sl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import type {SCMAdapter} from './types';
*/
const env = {...process.env, HGPLAIN: '1'};

// Whether `sl` is a steam locomotive or not
let isSteamLocomotive = false;

const adapter: SCMAdapter = {
findChangedFiles: async (cwd, options) => {
const includePaths = options.includePaths ?? [];
Expand All @@ -42,8 +45,29 @@ const adapter: SCMAdapter = {
},

getRoot: async cwd => {
if (isSteamLocomotive) {
return null;
}

try {
const result = await execa('sl', ['root'], {cwd, env});
const subprocess = execa('sl', ['root'], {cwd, env});

// Check if we're calling sl (steam locomotive) instead of sl (sapling)
// by looking for the escape character in the first chunk of data.
if (subprocess.stdout) {
subprocess.stdout.once('data', (data: Buffer | string) => {
data = Buffer.isBuffer(data) ? data.toString() : data;
if (data.codePointAt(0) === 27) {
subprocess.cancel();
isSteamLocomotive = true;
}
});
}

const result = await subprocess;
if (result.killed && isSteamLocomotive) {
return null;
}

return result.stdout;
} catch {
Expand Down
Loading