cli icon indicating copy to clipboard operation
cli copied to clipboard

Custom matcher for paths on different OS

Open BioPhoton opened this issue 1 year ago • 2 comments

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

BioPhoton avatar Jul 11 '24 13:07 BioPhoton

@BioPhoton Hasn't #876 resolved this issue?

hanna-skryl avatar Jan 23 '25 00:01 hanna-skryl

I am not able to use them ATM :D type issues

BioPhoton avatar Feb 11 '25 17:02 BioPhoton