cli
cli copied to clipboard
Custom matcher for paths on different OS
User story
As a developer I want to have a good signal to noise ration and want to write my tests with as less boilerplate as possible. Paths are environment specific and cause boilerplate to get properly tested. Therefor I need a custom matcher for paths.
Existing helper: os-agnostic-paths
Bad example:
expect(osAgnosticPath(process.cwd())).toEqual(
expect.stringContaining(
osAgnosticPath('project-root/other-folder'),
),
);
Suggested matcher:
-
expect(myPath).toContainPath('...')
-
expect(myPath).toEndWithPath('...')
Good example:
// windows 'C:\Documnets\my-projects\project-root'
// linux '/home/my-projects/project-root'
expect(process.cwd()).toContainPath('project-root/other-folder');
expect(process.cwd()).toEndsWithPath('project-root/other-folder/src');
Acceptance criteria
I want to be able to use the custom matcher in the following libs:
- [ ] vitest
Internal logic:
- [ ] it handles path differences of all OS I want to be able to have different matcher present:
- [ ]
toContainPath('...')
- [ ]
toEndWithPath('...')
- [ ] the existing code is using the helper, e.g. nx-plugin tests for persist.outputDir