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
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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"eslint-plugin-jest": "^26.0.0",
"eslint-plugin-prettier": "^4.0.0",
"jest": "^28.0.0",
"jest-serializer-ansi-escapes": "^1.0.1",
"prettier": "^2.1.1",
"rimraf": "^3.0.2",
"semantic-release": "^19.0.3",
Expand All @@ -81,7 +82,7 @@
"<rootDir>/testname"
],
"snapshotSerializers": [
"<rootDir>/node_modules/pretty-format/build/plugins/ConvertAnsi"
"jest-serializer-ansi-escapes"
],
"testPathIgnorePatterns": [
"<rootDir>/build/.*",
Expand Down
158 changes: 81 additions & 77 deletions src/file_name_plugin/__tests__/__snapshots__/plugin.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,127 +1,131 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`can select a pattern that matches multiple files 1`] = `

[MOCK - cursorLeft]

pattern › f
[MOCK - cursorSavePosition]
[MOCK - cursorLeft]
"<eraseLine>
<moveCursorToColumn1>
<eraseScreenDown>
<dim> pattern ›</> f
<saveCursorPosition>
<moveCursorToColumn1>


Pattern matches 3 files

› src/foo.js

› src/file-1.js

› src/file-2.js
[MOCK - cursorTo(12, 5)]
[MOCK - cursorRestorePosition]
<dim>›</> <dim>src/</></>f</><dim>oo.js</>

[MOCK - cursorLeft]
<dim>›</> <dim>src/</></>f</><dim>ile-1.js</>

pattern › fi
[MOCK - cursorSavePosition]
[MOCK - cursorLeft]
<dim>›</> <dim>src/</></>f</><dim>ile-2.js</>
<moveCursorToRow6Column13>
<restoreCursorPosition>
<eraseLine>
<moveCursorToColumn1>
<eraseScreenDown>
<dim> pattern ›</> fi
<saveCursorPosition>
<moveCursorToColumn1>


Pattern matches 2 files

src/file-1.js
<dim>›</> <dim>src/</></>fi</><dim>le-1.js</>

› src/file-2.js
[MOCK - cursorTo(13, 5)]
[MOCK - cursorRestorePosition]
<dim>›</> <dim>src/</></>fi</><dim>le-2.js</>
<moveCursorToRow6Column14>
<restoreCursorPosition>
"
`;

exports[`can use arrows to select a specific file 1`] = `

[MOCK - cursorLeft]

pattern › f
[MOCK - cursorSavePosition]
[MOCK - cursorLeft]
"<eraseLine>
<moveCursorToColumn1>
<eraseScreenDown>
<dim> pattern ›</> f
<saveCursorPosition>
<moveCursorToColumn1>


Pattern matches 3 files

› src/foo.js

› src/file-1.js
<dim>›</> <dim>src/</></>f</><dim>oo.js</>

› src/file-2.js
[MOCK - cursorTo(12, 5)]
[MOCK - cursorRestorePosition]
<dim>›</> <dim>src/</></>f</><dim>ile-1.js</>

[MOCK - cursorLeft]

pattern › fi
[MOCK - cursorSavePosition]
[MOCK - cursorLeft]
<dim>›</> <dim>src/</></>f</><dim>ile-2.js</>
<moveCursorToRow6Column13>
<restoreCursorPosition>
<eraseLine>
<moveCursorToColumn1>
<eraseScreenDown>
<dim> pattern ›</> fi
<saveCursorPosition>
<moveCursorToColumn1>


Pattern matches 2 files

› src/file-1.js

› src/file-2.js
[MOCK - cursorTo(13, 5)]
[MOCK - cursorRestorePosition]
<dim>›</> <dim>src/</></>fi</><dim>le-1.js</>

[MOCK - cursorLeft]

pattern › fi
[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>

<restoreCursorPosition>
<eraseLine>
<moveCursorToColumn1>
<eraseScreenDown>
<dim> pattern ›</> fi
<saveCursorPosition>
<moveCursorToColumn1>


Pattern matches 2 files

src/file-1.js
<dim>›</> <black><backgroundYellow>src/file-1.js</></>

› src/file-2.js
[MOCK - cursorTo(13, 5)]
[MOCK - cursorRestorePosition]
<dim>›</> <dim>src/</></>fi</><dim>le-2.js</>
<moveCursorToRow6Column14>
<restoreCursorPosition>
"
`;

exports[`file matching is case insensitive 1`] = `

[MOCK - cursorLeft]

pattern › fI
[MOCK - cursorSavePosition]
[MOCK - cursorLeft]
"<eraseLine>
<moveCursorToColumn1>
<eraseScreenDown>
<dim> pattern ›</> fI
<saveCursorPosition>
<moveCursorToColumn1>


Pattern matches 2 files

src/file-1.js
<dim>›</> <dim>src/</></>fi</><dim>le-1.js</>

› src/file-2.js
[MOCK - cursorTo(13, 5)]
[MOCK - cursorRestorePosition]
<dim>›</> <dim>src/</></>fi</><dim>le-2.js</>
<moveCursorToRow6Column14>
<restoreCursorPosition>
"
`;

exports[`shows the correct initial state 1`] = `
[MOCK - cursorHide]
[MOCK - clear]

Pattern Mode Usage
› Press Esc to exit pattern mode.
› Press Enter to filter by a filenames regex pattern.

"<hideCursor>
<clearTerminal>

[MOCK - cursorShow]
<bold>Pattern Mode Usage</>
<dim>› Press</> Esc <dim>to exit pattern mode.</>
<dim>› Press</> Enter <dim>to filter by a filenames regex pattern.</>

[MOCK - cursorLeft]

pattern ›
[MOCK - cursorSavePosition]
[MOCK - cursorLeft]
<showCursor>
<eraseLine>
<moveCursorToColumn1>
<eraseScreenDown>
<dim> pattern ›</>
<saveCursorPosition>
<moveCursorToColumn1>


Start typing to filter by a filename regex pattern.
[MOCK - cursorTo(11, 5)]
[MOCK - cursorRestorePosition]
<italic><yellow>Start typing to filter by a filename regex pattern.</></>
<moveCursorToRow6Column12>
<restoreCursorPosition>
"
`;
25 changes: 0 additions & 25 deletions src/file_name_plugin/__tests__/plugin.test.ts
Original file line number Diff line number Diff line change
@@ -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.


let pluginTester: typeof import('../../test_utils/pluginTester').default = null;
let FileNamePlugin: typeof import('../plugin').default = null;

jest.unstable_mockModule('ansi-escapes', () => ({
default: {
clearScreen: '[MOCK - clearScreen]',
cursorDown: (count = 1) => `[MOCK - cursorDown(${count})]`,
cursorLeft: '[MOCK - cursorLeft]',
cursorHide: '[MOCK - cursorHide]',
cursorRestorePosition: '[MOCK - cursorRestorePosition]',
cursorSavePosition: '[MOCK - cursorSavePosition]',
cursorShow: '[MOCK - cursorShow]',
cursorTo: (x, y) => `[MOCK - cursorTo(${x}, ${y})]`,
},
}));

jest.doMock('ansi-escapes', () => ({
clearScreen: '[MOCK - clearScreen]',
cursorDown: (count = 1) => `[MOCK - cursorDown(${count})]`,
cursorLeft: '[MOCK - cursorLeft]',
cursorHide: '[MOCK - cursorHide]',
cursorRestorePosition: '[MOCK - cursorRestorePosition]',
cursorSavePosition: '[MOCK - cursorSavePosition]',
cursorShow: '[MOCK - cursorShow]',
cursorTo: (x, y) => `[MOCK - cursorTo(${x}, ${y})]`,
}));

const projects: Config.ProjectConfig[] = [
{
config: {
Expand Down
Loading