Skip to content

Commit

Permalink
test: core string utils
Browse files Browse the repository at this point in the history
  • Loading branch information
orochaa committed Sep 12, 2023
1 parent 7bcdc6f commit d3c2d27
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ export default {
'^(\\.{1,2}/.*)\\.js$': '$1',
},
testRegex: ['__tests__/.+(spec|test).ts'],
setupFiles: ['<rootDir>/packages/core/__tests__/setup.ts'],
setupFiles: ['<rootDir>/packages/core/__tests__/setup-tests.ts'],
};
8 changes: 8 additions & 0 deletions packages/core/__tests__/setup-tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* `wrap-ansi` is an ES Module, and `jest` does not fully support it.
*
* Related Jest Issue:
* title: Meta: Native support for ES Modules #9430
* url: https://github.com/jestjs/jest/issues/9430
**/
jest.mock('wrap-ansi', () => (str: string) => str);
4 changes: 0 additions & 4 deletions packages/core/__tests__/setup.ts

This file was deleted.

18 changes: 18 additions & 0 deletions packages/core/__tests__/utils/string.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { diffLines } from '../../src/utils';

describe('String Utils', () => {
it('should return `undefined` if there is no diff line', () => {
const input = 'Lorem Ipsum is simply dummy text\n of the printing \nand typesetting industry.';

expect(diffLines(input, input)).toBeUndefined();
});

it('should return a list with the index of each diff line', () => {
const inputA =
'Lorem Ipsum is simply dummy\n text\n of the \nprinting\n \nand typesetting industry.';
const inputB =
'Lorem Ipsum is simply dummy\n \ntext of the \nprinting\n and\n typesetting industry.';

expect(diffLines(inputA, inputB)).toStrictEqual([1, 2, 4, 5]);
});
});

0 comments on commit d3c2d27

Please sign in to comment.