diff --git a/src/file_name_plugin/__tests__/plugin.test.js b/src/file_name_plugin/__tests__/plugin.test.js index 8d2d56e..c2aa15c 100644 --- a/src/file_name_plugin/__tests__/plugin.test.js +++ b/src/file_name_plugin/__tests__/plugin.test.js @@ -165,6 +165,6 @@ it("selected file doesn't include trimming dots", async () => { expect(updateConfigAndRun).toHaveBeenCalledWith({ mode: 'watch', - testPathPattern: 'ing\\.js', + testPathPattern: 'ong_name_gonna_need_trimming\\.js', }); }); diff --git a/src/lib/__tests__/__snapshots__/utils.test.js.snap b/src/lib/__tests__/__snapshots__/utils.test.js.snap index b169b61..117f697 100644 --- a/src/lib/__tests__/__snapshots__/utils.test.js.snap +++ b/src/lib/__tests__/__snapshots__/utils.test.js.snap @@ -35,3 +35,11 @@ exports[`formatTestNameByPattern formats when testname="the test name", pattern= exports[`formatTestNameByPattern formats when testname="the test name", pattern="the", and width="25" 1`] = `"the test name"`; exports[`formatTestNameByPattern formats when testname="the test name", pattern="the", and width="30" 1`] = `"the test name"`; + +exports[`trimAndFormatPath formats when testpath="/project/src/exactly/sep_and_basename.js", pad="6", and columns="29" 1`] = `".../sep_and_basename.js"`; + +exports[`trimAndFormatPath formats when testpath="/project/src/gonna/fit/all.js", pad="6", and columns="80" 1`] = `"src/gonna/fit/all.js"`; + +exports[`trimAndFormatPath formats when testpath="/project/src/long_name_gonna_need_trimming.js", pad="6", and columns="40" 1`] = `"...ong_name_gonna_need_trimming.js"`; + +exports[`trimAndFormatPath formats when testpath="/project/src/trimmed_dir/foo.js", pad="6", and columns="20" 1`] = `"..._dir/foo.js"`; diff --git a/src/lib/__tests__/utils.test.js b/src/lib/__tests__/utils.test.js index 425aa11..d939f8b 100644 --- a/src/lib/__tests__/utils.test.js +++ b/src/lib/__tests__/utils.test.js @@ -1,4 +1,3 @@ -import stripAnsi from 'strip-ansi'; import { trimAndFormatPath, formatTestNameByPattern } from '../utils'; jest.mock('chalk', () => { @@ -6,12 +5,21 @@ jest.mock('chalk', () => { return new chalk.constructor({ enabled: true, level: 1 }); }); -test('trimAndFormatPath', () => { - expect( - stripAnsi( - trimAndFormatPath(2, { cwd: '/hello/there' }, '/hello/there/to/you', 80), - ), - ).toEqual('to/you'); +describe('trimAndFormatPath', () => { + test.each` + testPath | pad | columns + ${'/project/src/gonna/fit/all.js'} | ${6} | ${80} + ${'/project/src/trimmed_dir/foo.js'} | ${6} | ${20} + ${'/project/src/exactly/sep_and_basename.js'} | ${6} | ${29} + ${'/project/src/long_name_gonna_need_trimming.js'} | ${6} | ${40} + `( + 'formats when testpath="$testPath", pad="$pad", and columns="$columns"', + ({ testPath, pad, columns }) => { + expect( + trimAndFormatPath(pad, { rootDir: '/project' }, testPath, columns), + ).toMatchSnapshot(); + }, + ); }); describe('formatTestNameByPattern', () => { diff --git a/src/lib/utils.js b/src/lib/utils.js index c0e6e19..d86b715 100644 --- a/src/lib/utils.js +++ b/src/lib/utils.js @@ -54,14 +54,7 @@ export const trimAndFormatPath = ( ); } // can't fit dirname, but can fit trimmed basename - return slash( - chalk.bold( - `${TRIMMING_DOTS}${basename.slice( - basename.length - maxLength - 4, - basename.length, - )}`, - ), - ); + return slash(chalk.bold(`${TRIMMING_DOTS}${basename.slice(-maxLength + 3)}`)); }; export const getTerminalWidth = (