Skip to content

Commit b896dab

Browse files
committed
wip
1 parent e350aa6 commit b896dab

File tree

1 file changed

+100
-161
lines changed

1 file changed

+100
-161
lines changed

testing/test-setup/src/lib/extend/path.matcher.ts

Lines changed: 100 additions & 161 deletions
Original file line numberDiff line numberDiff line change
@@ -19,165 +19,104 @@ export type CustomAsymmetricPathMatchers = {
1919
};
2020

2121
expect.extend({
22-
toMatchPath(actual: string, expected: string): SyncExpectationResult {
23-
const normalizedReceived = osAgnosticPath(actual);
24-
const normalizedExpected = osAgnosticPath(expected);
25-
26-
const pass = normalizedReceived === normalizedExpected;
27-
return pass
28-
? {
29-
message: () => `expected ${actual} not to match path ${expected}`,
30-
pass: true,
31-
actual,
32-
expected,
33-
}
34-
: {
35-
message: () => `expected ${actual} to match path ${expected}`,
36-
pass: false,
37-
actual,
38-
expected,
39-
};
40-
},
41-
42-
pathToMatch(actual: string, expected: string): SyncExpectationResult {
43-
const normalizedReceived = osAgnosticPath(actual);
44-
const normalizedExpected = osAgnosticPath(expected);
45-
46-
const pass = normalizedReceived === normalizedExpected;
47-
return pass
48-
? {
49-
message: () => `expected ${actual} not to match path ${expected}`,
50-
pass: true,
51-
actual,
52-
expected,
53-
}
54-
: {
55-
message: () => `expected ${actual} to match path ${expected}`,
56-
pass: false,
57-
actual,
58-
expected,
59-
};
60-
},
61-
62-
toStartWithPath(actual: string, expected: string): SyncExpectationResult {
63-
const normalizedReceived = osAgnosticPath(actual);
64-
const normalizedExpected = osAgnosticPath(expected);
65-
66-
const pass = normalizedReceived.startsWith(normalizedExpected);
67-
return pass
68-
? {
69-
message: () =>
70-
`expected ${actual} not to start with path ${expected}`,
71-
pass: true,
72-
actual,
73-
expected,
74-
}
75-
: {
76-
message: () => `expected ${actual} to start with path ${expected}`,
77-
pass: false,
78-
actual,
79-
expected,
80-
};
81-
},
82-
83-
pathToStartWith(actual: string, expected: string): SyncExpectationResult {
84-
const normalizedReceived = osAgnosticPath(actual);
85-
const normalizedExpected = osAgnosticPath(expected);
86-
87-
const pass = normalizedReceived.startsWith(normalizedExpected);
88-
return pass
89-
? {
90-
message: () =>
91-
`expected ${actual} not to start with path ${expected}`,
92-
pass: true,
93-
actual,
94-
expected,
95-
}
96-
: {
97-
message: () => `expected ${actual} to start with path ${expected}`,
98-
pass: false,
99-
actual,
100-
expected,
101-
};
102-
},
103-
104-
toContainPath(actual: string, expected: string): SyncExpectationResult {
105-
const normalizedReceived = osAgnosticPath(actual);
106-
const normalizedExpected = osAgnosticPath(expected);
107-
108-
const pass = normalizedReceived.includes(normalizedExpected);
109-
return pass
110-
? {
111-
message: () => `expected ${actual} not to contain path ${expected}`,
112-
pass: true,
113-
actual,
114-
expected,
115-
}
116-
: {
117-
message: () => `expected ${actual} to contain path ${expected}`,
118-
pass: false,
119-
actual,
120-
expected,
121-
};
122-
},
123-
124-
pathToContain(actual: string, expected: string): SyncExpectationResult {
125-
const normalizedReceived = osAgnosticPath(actual);
126-
const normalizedExpected = osAgnosticPath(expected);
127-
128-
const pass = normalizedReceived.includes(normalizedExpected);
129-
return pass
130-
? {
131-
message: () => `expected ${actual} not to contain path ${expected}`,
132-
pass: true,
133-
actual,
134-
expected,
135-
}
136-
: {
137-
message: () => `expected ${actual} to contain path ${expected}`,
138-
pass: false,
139-
actual,
140-
expected,
141-
};
142-
},
143-
144-
toEndWithPath(actual: string, expected: string): SyncExpectationResult {
145-
const normalizedReceived = osAgnosticPath(actual);
146-
const normalizedExpected = osAgnosticPath(expected);
147-
148-
const pass = normalizedReceived.endsWith(normalizedExpected);
149-
return pass
150-
? {
151-
message: () => `expected ${actual} not to end with path ${expected}`,
152-
pass: true,
153-
actual,
154-
expected,
155-
}
156-
: {
157-
message: () => `expected ${actual} to end with path ${expected}`,
158-
pass: false,
159-
actual,
160-
expected,
161-
};
162-
},
163-
164-
pathToEndWith(actual: string, expected: string): SyncExpectationResult {
165-
const normalizedReceived = osAgnosticPath(actual);
166-
const normalizedExpected = osAgnosticPath(expected);
167-
168-
const pass = normalizedReceived.endsWith(normalizedExpected);
169-
return pass
170-
? {
171-
message: () => `expected ${actual} not to end with path ${expected}`,
172-
pass: true,
173-
actual,
174-
expected,
175-
}
176-
: {
177-
message: () => `expected ${actual} to end with path ${expected}`,
178-
pass: false,
179-
actual,
180-
expected,
181-
};
182-
},
22+
toMatchPath: assertPathMatch,
23+
pathToMatch: assertPathMatch,
24+
toStartWithPath: assertPathStartWith,
25+
pathToStartWith: assertPathStartWith,
26+
toContainPath: assertPathContain,
27+
pathToContain: assertPathContain,
28+
toEndWithPath: assertPathEndWith,
29+
pathToEndWith: assertPathEndWith,
18330
});
31+
32+
function assertPathMatch(
33+
actual: string,
34+
expected: string,
35+
): SyncExpectationResult {
36+
const normalizedReceived = osAgnosticPath(actual);
37+
const normalizedExpected = osAgnosticPath(expected);
38+
39+
const pass = normalizedReceived === normalizedExpected;
40+
return pass
41+
? {
42+
message: () => `expected ${actual} not to match path ${expected}`,
43+
pass: true,
44+
actual,
45+
expected,
46+
}
47+
: {
48+
message: () => `expected ${actual} to match path ${expected}`,
49+
pass: false,
50+
actual,
51+
expected,
52+
};
53+
}
54+
55+
function assertPathStartWith(
56+
actual: string,
57+
expected: string,
58+
): SyncExpectationResult {
59+
const normalizedReceived = osAgnosticPath(actual);
60+
const normalizedExpected = osAgnosticPath(expected);
61+
62+
const pass = normalizedReceived.startsWith(normalizedExpected);
63+
return pass
64+
? {
65+
message: () => `expected ${actual} not to start with path ${expected}`,
66+
pass: true,
67+
actual,
68+
expected,
69+
}
70+
: {
71+
message: () => `expected ${actual} to start with path ${expected}`,
72+
pass: false,
73+
actual,
74+
expected,
75+
};
76+
}
77+
78+
function assertPathContain(
79+
actual: string,
80+
expected: string,
81+
): SyncExpectationResult {
82+
const normalizedReceived = osAgnosticPath(actual);
83+
const normalizedExpected = osAgnosticPath(expected);
84+
85+
const pass = normalizedReceived.includes(normalizedExpected);
86+
return pass
87+
? {
88+
message: () => `expected ${actual} not to contain path ${expected}`,
89+
pass: true,
90+
actual,
91+
expected,
92+
}
93+
: {
94+
message: () => `expected ${actual} to contain path ${expected}`,
95+
pass: false,
96+
actual,
97+
expected,
98+
};
99+
}
100+
101+
function assertPathEndWith(
102+
actual: string,
103+
expected: string,
104+
): SyncExpectationResult {
105+
const normalizedReceived = osAgnosticPath(actual);
106+
const normalizedExpected = osAgnosticPath(expected);
107+
108+
const pass = normalizedReceived.endsWith(normalizedExpected);
109+
return pass
110+
? {
111+
message: () => `expected ${actual} not to end with path ${expected}`,
112+
pass: true,
113+
actual,
114+
expected,
115+
}
116+
: {
117+
message: () => `expected ${actual} to end with path ${expected}`,
118+
pass: false,
119+
actual,
120+
expected,
121+
};
122+
}

0 commit comments

Comments
 (0)