Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
BioPhoton committed Dec 22, 2024
1 parent e350aa6 commit b896dab
Showing 1 changed file with 100 additions and 161 deletions.
261 changes: 100 additions & 161 deletions testing/test-setup/src/lib/extend/path.matcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,165 +19,104 @@ export type CustomAsymmetricPathMatchers = {
};

expect.extend({
toMatchPath(actual: string, expected: string): SyncExpectationResult {
const normalizedReceived = osAgnosticPath(actual);
const normalizedExpected = osAgnosticPath(expected);

const pass = normalizedReceived === normalizedExpected;
return pass
? {
message: () => `expected ${actual} not to match path ${expected}`,
pass: true,
actual,
expected,
}
: {
message: () => `expected ${actual} to match path ${expected}`,
pass: false,
actual,
expected,
};
},

pathToMatch(actual: string, expected: string): SyncExpectationResult {
const normalizedReceived = osAgnosticPath(actual);
const normalizedExpected = osAgnosticPath(expected);

const pass = normalizedReceived === normalizedExpected;
return pass
? {
message: () => `expected ${actual} not to match path ${expected}`,
pass: true,
actual,
expected,
}
: {
message: () => `expected ${actual} to match path ${expected}`,
pass: false,
actual,
expected,
};
},

toStartWithPath(actual: string, expected: string): SyncExpectationResult {
const normalizedReceived = osAgnosticPath(actual);
const normalizedExpected = osAgnosticPath(expected);

const pass = normalizedReceived.startsWith(normalizedExpected);
return pass
? {
message: () =>
`expected ${actual} not to start with path ${expected}`,
pass: true,
actual,
expected,
}
: {
message: () => `expected ${actual} to start with path ${expected}`,
pass: false,
actual,
expected,
};
},

pathToStartWith(actual: string, expected: string): SyncExpectationResult {
const normalizedReceived = osAgnosticPath(actual);
const normalizedExpected = osAgnosticPath(expected);

const pass = normalizedReceived.startsWith(normalizedExpected);
return pass
? {
message: () =>
`expected ${actual} not to start with path ${expected}`,
pass: true,
actual,
expected,
}
: {
message: () => `expected ${actual} to start with path ${expected}`,
pass: false,
actual,
expected,
};
},

toContainPath(actual: string, expected: string): SyncExpectationResult {
const normalizedReceived = osAgnosticPath(actual);
const normalizedExpected = osAgnosticPath(expected);

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

pathToContain(actual: string, expected: string): SyncExpectationResult {
const normalizedReceived = osAgnosticPath(actual);
const normalizedExpected = osAgnosticPath(expected);

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

toEndWithPath(actual: string, expected: string): SyncExpectationResult {
const normalizedReceived = osAgnosticPath(actual);
const normalizedExpected = osAgnosticPath(expected);

const pass = normalizedReceived.endsWith(normalizedExpected);
return pass
? {
message: () => `expected ${actual} not to end with path ${expected}`,
pass: true,
actual,
expected,
}
: {
message: () => `expected ${actual} to end with path ${expected}`,
pass: false,
actual,
expected,
};
},

pathToEndWith(actual: string, expected: string): SyncExpectationResult {
const normalizedReceived = osAgnosticPath(actual);
const normalizedExpected = osAgnosticPath(expected);

const pass = normalizedReceived.endsWith(normalizedExpected);
return pass
? {
message: () => `expected ${actual} not to end with path ${expected}`,
pass: true,
actual,
expected,
}
: {
message: () => `expected ${actual} to end with path ${expected}`,
pass: false,
actual,
expected,
};
},
toMatchPath: assertPathMatch,
pathToMatch: assertPathMatch,
toStartWithPath: assertPathStartWith,
pathToStartWith: assertPathStartWith,
toContainPath: assertPathContain,
pathToContain: assertPathContain,
toEndWithPath: assertPathEndWith,
pathToEndWith: assertPathEndWith,
});

function assertPathMatch(
actual: string,
expected: string,
): SyncExpectationResult {
const normalizedReceived = osAgnosticPath(actual);
const normalizedExpected = osAgnosticPath(expected);

const pass = normalizedReceived === normalizedExpected;
return pass
? {
message: () => `expected ${actual} not to match path ${expected}`,
pass: true,
actual,
expected,
}
: {
message: () => `expected ${actual} to match path ${expected}`,
pass: false,
actual,
expected,
};
}

function assertPathStartWith(
actual: string,
expected: string,
): SyncExpectationResult {
const normalizedReceived = osAgnosticPath(actual);
const normalizedExpected = osAgnosticPath(expected);

const pass = normalizedReceived.startsWith(normalizedExpected);
return pass
? {
message: () => `expected ${actual} not to start with path ${expected}`,
pass: true,
actual,
expected,
}
: {
message: () => `expected ${actual} to start with path ${expected}`,
pass: false,
actual,
expected,
};
}

function assertPathContain(
actual: string,
expected: string,
): SyncExpectationResult {
const normalizedReceived = osAgnosticPath(actual);
const normalizedExpected = osAgnosticPath(expected);

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

function assertPathEndWith(
actual: string,
expected: string,
): SyncExpectationResult {
const normalizedReceived = osAgnosticPath(actual);
const normalizedExpected = osAgnosticPath(expected);

const pass = normalizedReceived.endsWith(normalizedExpected);
return pass
? {
message: () => `expected ${actual} not to end with path ${expected}`,
pass: true,
actual,
expected,
}
: {
message: () => `expected ${actual} to end with path ${expected}`,
pass: false,
actual,
expected,
};
}

0 comments on commit b896dab

Please sign in to comment.