|
| 1 | +import { describe, expect, it, vi } from 'vitest'; |
| 2 | +import * as testUtils from '@code-pushup/test-utils'; |
| 3 | + |
| 4 | +describe('path-matcher', () => { |
| 5 | + const osAgnosticPathSpy = vi.spyOn(testUtils, 'osAgnosticPath'); |
| 6 | + |
| 7 | + it('should provide "toMatchPath" as expect matcher', () => { |
| 8 | + const actual = String.raw`tmp\path\to\file.txt`; |
| 9 | + const expected = 'tmp/path/to/file.txt'; |
| 10 | + |
| 11 | + expect(actual).toMatchPath(expected); |
| 12 | + |
| 13 | + expect(osAgnosticPathSpy).toHaveBeenCalledTimes(2); |
| 14 | + expect(osAgnosticPathSpy).toHaveBeenCalledWith(actual); |
| 15 | + expect(osAgnosticPathSpy).toHaveBeenCalledWith(expected); |
| 16 | + }); |
| 17 | + |
| 18 | + it('should provide "pathToMatch" as expect matcher', () => { |
| 19 | + const actual = String.raw`tmp\path\to\file.txt`; |
| 20 | + const expected = 'tmp/path/to/file.txt'; |
| 21 | + |
| 22 | + expect({ path: actual }).toStrictEqual({ |
| 23 | + path: expect.pathToMatch(expected), |
| 24 | + }); |
| 25 | + |
| 26 | + expect(osAgnosticPathSpy).toHaveBeenCalledTimes(2); |
| 27 | + expect(osAgnosticPathSpy).toHaveBeenCalledWith(actual); |
| 28 | + expect(osAgnosticPathSpy).toHaveBeenCalledWith(expected); |
| 29 | + }); |
| 30 | + |
| 31 | + it('should provide "toStartWithPath" as expect matcher', () => { |
| 32 | + const actual = String.raw`tmp\path\to\file.txt`; |
| 33 | + const expected = 'tmp/path/to'; |
| 34 | + |
| 35 | + expect(actual).toStartWithPath(expected); |
| 36 | + |
| 37 | + expect(osAgnosticPathSpy).toHaveBeenCalledTimes(2); |
| 38 | + expect(osAgnosticPathSpy).toHaveBeenCalledWith(actual); |
| 39 | + expect(osAgnosticPathSpy).toHaveBeenCalledWith(expected); |
| 40 | + }); |
| 41 | + |
| 42 | + it('should provide "pathToStartWith" as expect matcher', () => { |
| 43 | + const actual = String.raw`tmp\path\to\file.txt`; |
| 44 | + const expected = 'tmp/path/to'; |
| 45 | + |
| 46 | + expect({ path: actual }).toStrictEqual({ |
| 47 | + path: expect.pathToStartWith(expected), |
| 48 | + }); |
| 49 | + |
| 50 | + expect(osAgnosticPathSpy).toHaveBeenCalledTimes(2); |
| 51 | + expect(osAgnosticPathSpy).toHaveBeenCalledWith(actual); |
| 52 | + expect(osAgnosticPathSpy).toHaveBeenCalledWith(expected); |
| 53 | + }); |
| 54 | + |
| 55 | + it('should provide "toContainPath" as expect matcher', () => { |
| 56 | + const actual = String.raw`tmp\path\to\file.txt`; |
| 57 | + const expected = 'path/to'; |
| 58 | + |
| 59 | + expect(actual).toContainPath(expected); |
| 60 | + |
| 61 | + expect(osAgnosticPathSpy).toHaveBeenCalledTimes(2); |
| 62 | + expect(osAgnosticPathSpy).toHaveBeenCalledWith(actual); |
| 63 | + expect(osAgnosticPathSpy).toHaveBeenCalledWith(expected); |
| 64 | + }); |
| 65 | + |
| 66 | + it('should provide "pathToContain" as expect matcher', () => { |
| 67 | + const actual = String.raw`tmp\path\to\file.txt`; |
| 68 | + const expected = 'path/to'; |
| 69 | + |
| 70 | + expect({ path: actual }).toStrictEqual({ |
| 71 | + path: expect.pathToContain(expected), |
| 72 | + }); |
| 73 | + |
| 74 | + expect(osAgnosticPathSpy).toHaveBeenCalledTimes(2); |
| 75 | + expect(osAgnosticPathSpy).toHaveBeenCalledWith(actual); |
| 76 | + expect(osAgnosticPathSpy).toHaveBeenCalledWith(expected); |
| 77 | + }); |
| 78 | + |
| 79 | + it('should provide "toEndWithPath" as expect matcher', () => { |
| 80 | + const actual = String.raw`tmp\path\to\file.txt`; |
| 81 | + const expected = 'path/to/file.txt'; |
| 82 | + |
| 83 | + expect(actual).toEndWithPath(expected); |
| 84 | + |
| 85 | + expect(osAgnosticPathSpy).toHaveBeenCalledTimes(2); |
| 86 | + expect(osAgnosticPathSpy).toHaveBeenCalledWith(actual); |
| 87 | + expect(osAgnosticPathSpy).toHaveBeenCalledWith(expected); |
| 88 | + }); |
| 89 | + |
| 90 | + it('should provide "pathToEndWith" as expect matcher', () => { |
| 91 | + const actual = String.raw`tmp\path\to\file.txt`; |
| 92 | + const expected = 'path/to/file.txt'; |
| 93 | + |
| 94 | + expect({ path: actual }).toStrictEqual({ |
| 95 | + path: expect.pathToEndWith(expected), |
| 96 | + }); |
| 97 | + |
| 98 | + expect(osAgnosticPathSpy).toHaveBeenCalledTimes(2); |
| 99 | + expect(osAgnosticPathSpy).toHaveBeenCalledWith(actual); |
| 100 | + expect(osAgnosticPathSpy).toHaveBeenCalledWith(expected); |
| 101 | + }); |
| 102 | +}); |
0 commit comments