diff --git a/package.json b/package.json index af8864e..8b58b15 100644 --- a/package.json +++ b/package.json @@ -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", @@ -81,7 +82,7 @@ "/testname" ], "snapshotSerializers": [ - "/node_modules/pretty-format/build/plugins/ConvertAnsi" + "jest-serializer-ansi-escapes" ], "testPathIgnorePatterns": [ "/build/.*", diff --git a/src/file_name_plugin/__tests__/__snapshots__/plugin.test.ts.snap b/src/file_name_plugin/__tests__/__snapshots__/plugin.test.ts.snap index ffdf3c2..e6ba196 100644 --- a/src/file_name_plugin/__tests__/__snapshots__/plugin.test.ts.snap +++ b/src/file_name_plugin/__tests__/__snapshots__/plugin.test.ts.snap @@ -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] +" + + + pattern › f + + Pattern matches 3 files - › src/foo.js - - › src/file-1.js - - › src/file-2.js -[MOCK - cursorTo(12, 5)] -[MOCK - cursorRestorePosition] + src/foo.js -[MOCK - cursorLeft] + src/file-1.js - pattern › fi -[MOCK - cursorSavePosition] -[MOCK - cursorLeft] + src/file-2.js + + + + + + pattern › fi + + Pattern matches 2 files - › src/file-1.js + src/file-1.js - › src/file-2.js -[MOCK - cursorTo(13, 5)] -[MOCK - cursorRestorePosition] + src/file-2.js + + +" `; exports[`can use arrows to select a specific file 1`] = ` - -[MOCK - cursorLeft] - - pattern › f -[MOCK - cursorSavePosition] -[MOCK - cursorLeft] +" + + + pattern › f + + Pattern matches 3 files - › src/foo.js - - › src/file-1.js + src/foo.js - › src/file-2.js -[MOCK - cursorTo(12, 5)] -[MOCK - cursorRestorePosition] + src/file-1.js -[MOCK - cursorLeft] - - pattern › fi -[MOCK - cursorSavePosition] -[MOCK - cursorLeft] + src/file-2.js + + + + + + pattern › fi + + Pattern matches 2 files - › src/file-1.js - - › src/file-2.js -[MOCK - cursorTo(13, 5)] -[MOCK - cursorRestorePosition] + src/file-1.js -[MOCK - cursorLeft] - - pattern › fi -[MOCK - cursorSavePosition] -[MOCK - cursorLeft] + src/file-2.js + + + + + + pattern › fi + + Pattern matches 2 files - › src/file-1.js + src/file-1.js - › src/file-2.js -[MOCK - cursorTo(13, 5)] -[MOCK - cursorRestorePosition] + src/file-2.js + + +" `; exports[`file matching is case insensitive 1`] = ` - -[MOCK - cursorLeft] - - pattern › fI -[MOCK - cursorSavePosition] -[MOCK - cursorLeft] +" + + + pattern › fI + + Pattern matches 2 files - › src/file-1.js + src/file-1.js - › src/file-2.js -[MOCK - cursorTo(13, 5)] -[MOCK - cursorRestorePosition] + src/file-2.js + + +" `; 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. - +" + -[MOCK - cursorShow] +Pattern Mode Usage + › Press Esc to exit pattern mode. + › Press Enter to filter by a filenames regex pattern. -[MOCK - cursorLeft] - pattern › -[MOCK - cursorSavePosition] -[MOCK - cursorLeft] + + + + + pattern › + + - Start typing to filter by a filename regex pattern. -[MOCK - cursorTo(11, 5)] -[MOCK - cursorRestorePosition] + Start typing to filter by a filename regex pattern. + + +" `; diff --git a/src/file_name_plugin/__tests__/plugin.test.ts b/src/file_name_plugin/__tests__/plugin.test.ts index 550eb31..f854d37 100644 --- a/src/file_name_plugin/__tests__/plugin.test.ts +++ b/src/file_name_plugin/__tests__/plugin.test.ts @@ -1,34 +1,9 @@ import { KEYS } from 'jest-watcher'; import type { Config } from '@jest/types'; -import { jest } from '@jest/globals'; 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: { diff --git a/src/test_name_plugin/__tests__/__snapshots__/plugin.test.ts.snap b/src/test_name_plugin/__tests__/__snapshots__/plugin.test.ts.snap index 1e0184a..b3c617e 100644 --- a/src/test_name_plugin/__tests__/__snapshots__/plugin.test.ts.snap +++ b/src/test_name_plugin/__tests__/__snapshots__/plugin.test.ts.snap @@ -1,183 +1,189 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`can select a pattern that matches a describe block 1`] = ` +" + + + pattern › s + + -[MOCK - cursorLeft] - pattern › s -[MOCK - cursorSavePosition] -[MOCK - cursorLeft] + Pattern matches 4 tests from cached test suites + › some description foo 1 - Pattern matches 4 tests from cached test suites + › some description bar 1 - › some description foo 1 + other description foo 2 - › some description bar 1 + other description bar 2 + + + + + + pattern › so + + - › other description foo 2 - › other description bar 2 -[MOCK - cursorTo(12, 5)] -[MOCK - cursorRestorePosition] + Pattern matches 2 tests from cached test suites -[MOCK - cursorLeft] + › some description foo 1 - pattern › so -[MOCK - cursorSavePosition] -[MOCK - cursorLeft] - - - Pattern matches 2 tests from cached test suites - - › some description foo 1 - - › some description bar 1 -[MOCK - cursorTo(13, 5)] -[MOCK - cursorRestorePosition] + › some description bar 1 + + +" `; exports[`can select a pattern that matches multiple tests 1`] = ` +" + + + pattern › f + + -[MOCK - cursorLeft] - - pattern › f -[MOCK - cursorSavePosition] -[MOCK - cursorLeft] + Pattern matches 2 tests from cached test suites - Pattern matches 2 tests from cached test suites + some description foo 1 - › some description foo 1 + other description foo 2 + + + + + + pattern › fo + + - › other description foo 2 -[MOCK - cursorTo(12, 5)] -[MOCK - cursorRestorePosition] -[MOCK - cursorLeft] + Pattern matches 2 tests from cached test suites - pattern › fo -[MOCK - cursorSavePosition] -[MOCK - cursorLeft] + some description foo 1 - - Pattern matches 2 tests from cached test suites - - › some description foo 1 - - › other description foo 2 -[MOCK - cursorTo(13, 5)] -[MOCK - cursorRestorePosition] + other description foo 2 + + +" `; exports[`can use arrows to select a specific test 1`] = ` - -[MOCK - cursorLeft] - - pattern › f -[MOCK - cursorSavePosition] -[MOCK - cursorLeft] +" + + + pattern › f + + - Pattern matches 2 tests from cached test suites + Pattern matches 2 tests from cached test suites - › some description foo 1 + some description foo 1 - › other description foo 2 -[MOCK - cursorTo(12, 5)] -[MOCK - cursorRestorePosition] + other description foo 2 + + + + + + pattern › f + + -[MOCK - cursorLeft] - pattern › f -[MOCK - cursorSavePosition] -[MOCK - cursorLeft] + Pattern matches 2 tests from cached test suites + some description foo 1 - Pattern matches 2 tests from cached test suites + other description foo 2 + + + + + + pattern › f + + - › some description foo 1 - › other description foo 2 -[MOCK - cursorTo(12, 5)] -[MOCK - cursorRestorePosition] + Pattern matches 2 tests from cached test suites -[MOCK - cursorLeft] + some description foo 1 - pattern › f -[MOCK - cursorSavePosition] -[MOCK - cursorLeft] - - - Pattern matches 2 tests from cached test suites - - › some description foo 1 - - › other description foo 2 -[MOCK - cursorTo(12, 5)] -[MOCK - cursorRestorePosition] + other description foo 2 + + +" `; 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 tests regex pattern. +" + +Pattern Mode Usage + › Press Esc to exit pattern mode. + › Press Enter to filter by a tests regex pattern. -[MOCK - cursorShow] -[MOCK - cursorLeft] + + + + + pattern › + + - pattern › -[MOCK - cursorSavePosition] -[MOCK - cursorLeft] - - Start typing to filter by a test name regex pattern. -[MOCK - cursorTo(11, 5)] -[MOCK - cursorRestorePosition] + Start typing to filter by a test name regex pattern. + + +" `; exports[`shows the correct message when there are no cached tests 1`] = ` -[MOCK - cursorHide] -[MOCK - clear] - -Pattern Mode Usage - › Press Esc to exit pattern mode. - › Press Enter to filter by a tests regex pattern. - +" + -[MOCK - cursorShow] +Pattern Mode Usage + › Press Esc to exit pattern mode. + › Press Enter to filter by a tests regex pattern. -[MOCK - cursorLeft] - pattern › -[MOCK - cursorSavePosition] -[MOCK - cursorLeft] + + + + + pattern › + + - Start typing to filter by a test name regex pattern. -[MOCK - cursorTo(11, 5)] -[MOCK - cursorRestorePosition] + Start typing to filter by a test name regex pattern. + + +" `; exports[`test matching is case insensitive 1`] = ` - -[MOCK - cursorLeft] - - pattern › fO -[MOCK - cursorSavePosition] -[MOCK - cursorLeft] +" + + + pattern › fO + + - Pattern matches 2 tests from cached test suites + Pattern matches 2 tests from cached test suites - › some description foo 1 + some description foo 1 - › other description foo 2 -[MOCK - cursorTo(13, 5)] -[MOCK - cursorRestorePosition] + other description foo 2 + + +" `; diff --git a/src/test_name_plugin/__tests__/plugin.test.ts b/src/test_name_plugin/__tests__/plugin.test.ts index a26cae1..67260a8 100644 --- a/src/test_name_plugin/__tests__/plugin.test.ts +++ b/src/test_name_plugin/__tests__/plugin.test.ts @@ -1,33 +1,7 @@ -import { jest } from '@jest/globals'; - let pluginTester: typeof import('../../test_utils/pluginTester').default = null; let TestNamePlugin: typeof import('../plugin').default = null; let KEYS: typeof import('jest-watcher').KEYS = 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 testResults = [ { testResults: [ diff --git a/src/test_utils/pluginTester.ts b/src/test_utils/pluginTester.ts index e26cb84..39f249a 100644 --- a/src/test_utils/pluginTester.ts +++ b/src/test_utils/pluginTester.ts @@ -4,36 +4,11 @@ import { JestHookEmitter, UpdateConfigCallback, } from 'jest-watcher'; -import stripAnsi from 'strip-ansi'; import { jest } from '@jest/globals'; import type FileNamePlugin from '../file_name_plugin/plugin'; import type TestNamePlugin from '../test_name_plugin/plugin'; import type { PluginConfig } from '../types/Config'; -expect.addSnapshotSerializer({ - test: (val) => typeof val === 'string', - print: (val) => stripAnsi(val as string), -}); - -/** - * See https://github.com/facebook/jest/pull/7523 for more details - */ -const CLEAR = '\x1B[2J\x1B[3J\x1B[H'; -expect.addSnapshotSerializer({ - test: (val) => val.includes(CLEAR), - print: (val) => stripAnsi((val as string).replace(CLEAR, '[MOCK - clear]')), -}); - -/** - * See https://github.com/facebook/jest/pull/7523 for more details - */ -const WINDOWS_CLEAR = '\x1B[2J\x1B[0f'; -expect.addSnapshotSerializer({ - test: (val) => val.includes(WINDOWS_CLEAR), - print: (val) => - stripAnsi((val as string).replace(WINDOWS_CLEAR, '[MOCK - clear]')), -}); - type Options = { stdout?: { columns?: number }; config?: PluginConfig; diff --git a/yarn.lock b/yarn.lock index 566a880..57f0441 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4214,6 +4214,11 @@ jest-runtime@^28.1.2: slash "^3.0.0" strip-bom "^4.0.0" +jest-serializer-ansi-escapes@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/jest-serializer-ansi-escapes/-/jest-serializer-ansi-escapes-1.0.1.tgz#4c26adb7e5d4cd382f7adeb32cf5b12a4ac27d96" + integrity sha512-qfDZgNHLXVVFwsAGD8obs1KirQG43K5N0zwDMmaXL8HkS1PcPMZosofp1eykETPPJMY+pQSZkprXPq120WMJtQ== + jest-snapshot@^28.1.2: version "28.1.2" resolved "https://registry.yarnpkg.com/jest-snapshot/-/jest-snapshot-28.1.2.tgz#93d31b87b11b384f5946fe0767541496135f8d52"