Skip to content

Commit

Permalink
setup custom path matcher for vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
BioPhoton committed Oct 22, 2024
1 parent e487162 commit 31af283
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest] # @TODO add windows-latest after we know why it is running forever
os: [ubuntu-latest, macos-latest, windows-latest] # @TODO add windows-latest after we know why it is running forever
name: E2E tests
runs-on: ${{ matrix.os }}
steps:
Expand Down
1 change: 1 addition & 0 deletions projects/nx-verdaccio/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default defineConfig({
],
reporters: ['default'],
setupFiles: [
'../../testing/test-setup/src/lib/extend/path-matcher.ts',
'../../testing/test-setup/src/lib/fs.mock.ts',
'../../testing/test-setup/src/lib/reset.mock.ts',
],
Expand Down
39 changes: 39 additions & 0 deletions testing/test-setup/src/lib/extend/path-matcher.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import {expect} from 'vitest';
import path from 'path';

expect.extend({
toMatchPath(received, expected) {
const normalizedReceived = path.normalize(received);
const normalizedExpected = path.normalize(expected);

const pass = normalizedReceived.includes(normalizedExpected);
if (pass) {
return {
message: () => `expected ${received} not to match path ${expected}`,
pass: true,
};
} else {
return {
message: () => `expected ${received} to match path ${expected}`,
pass: false,
};
}
},
pathToMatch(received, expected) {
const normalizedReceived = path.normalize(received);
const normalizedExpected = path.normalize(expected);

const pass = normalizedReceived.includes(normalizedExpected);
if (pass) {
return {
message: () => `expected ${received} not to contain path ${expected}`,
pass: true,
};
} else {
return {
message: () => `expected ${received} to contain path ${expected}`,
pass: false,
};
}
},
});

0 comments on commit 31af283

Please sign in to comment.