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

chore: use jest-serializer-ansi-escapes #161

Merged
merged 3 commits into from
Jul 9, 2022
Merged

chore: use jest-serializer-ansi-escapes #161

merged 3 commits into from
Jul 9, 2022

Conversation

mrazauskas
Copy link
Contributor

Similar to jestjs/jest#12935

jest-serializer-ansi-escapes is a replacement for Jest’s internal pretty-format/ConvertAnsi plugin. It serializes cursor control as well as color and style ANSI escapes.

Currently in tests of jest-watch-typeahead cursor control escapes are snapped by mocking ansi-escapes. This works, but as you can see in the snapshots jest-serializer-ansi-escapes plugin is catching few more missing sequences.

Other difference – the mocking solution depends on ansi-escapes; the plugin is simply serialising vanilla sequences. Hence, using it makes easier to replace ansi-escapes in the future.

[MOCK - cursorSavePosition]
[MOCK - cursorLeft]
<dim>›</> <dim>src/</></>fi</><dim>le-2.js</>
<moveCursorToRow6Column14>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In ansi-escapes position is zero based, but in vanilla escapes it is 1 base and also row argument goes first. That’s why [MOCK - cursorTo(13, 5)] becomes <moveCursorToRow6Column14>

@@ -1,34 +1,9 @@
import { KEYS } from 'jest-watcher';
import type { Config } from '@jest/types';
import { jest } from '@jest/globals';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import is not used anymore.

@@ -4,36 +4,11 @@ import {
JestHookEmitter,
UpdateConfigCallback,
} from 'jest-watcher';
import stripAnsi from 'strip-ansi';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dependency is still used in code. So I left it in package.json.

@SimenB
Copy link
Member

SimenB commented Jul 9, 2022

@mrazauskas thanks! Could you add support for node 12 in engines?

EDIT: never mind, just dropped it

Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks! way better 👍

@SimenB SimenB merged commit a0ac757 into jest-community:main Jul 9, 2022
@SimenB
Copy link
Member

SimenB commented Jul 9, 2022

Seems there's a v2 (#163), should we update?

@github-actions
Copy link

github-actions bot commented Jul 9, 2022

🎉 This PR is included in version 2.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@mrazauskas
Copy link
Contributor Author

Thanks! I will send a PR for v2 bit later. It had improved serialization of reset sequences. I was sticking with v1 here to keep diffs smaller (;

@mrazauskas mrazauskas deleted the chore-use-jest-serializer-ansi-escapes branch July 10, 2022 02:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants