Skip to content

Commit 70a2768

Browse files
authored
feat(2024): Add Dev bypass to tests ('-nyi') (#1075)
## What does this do? This PR modifies the testing process. It standardizes the URL and Index tests, and adds a bypass when the URL ends in '-nyi'. ## How was it tested? Locally and repeatedly. ## Is there a Github issue this is resolving? No ## Did you update the docs in the API? Please link an associated PR if applicable. No ## Here's a fun image for your troubles I have recently started running *Curse of Strahd* for my D&D5E players. However, my pre-game reading included the original *I6 Ravenloft* module (from D&D 1.0), and *Expedition to Castle Ravenloft* from D&D 3.5. <img width="355" height="633" alt="image" src="https://github.com/user-attachments/assets/96c72c07-0fec-4c24-b8ba-a2c8da612e91" /> My brain is, quite literally, full of vampires at the moment.
1 parent 105f47a commit 70a2768

1 file changed

Lines changed: 60 additions & 4 deletions

File tree

src/2024/tests/tables.test.ts

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ describe('api references', () => {
3333
forEachFileEntry((filename, entry) => {
3434
if (entry.url === undefined) return;
3535

36-
if (entry.index === undefined) {
37-
errors.push(`${filename}: Entry with URL '${entry.url}' should have an index.`);
38-
}
36+
indexAndUrlChecks(filename, entry)?.forEach((error: string) => {
37+
errors.push(error);
38+
});
3939

4040
resources[entry.url as string] = { index: entry.index, name: entry.name };
4141
});
@@ -44,6 +44,18 @@ describe('api references', () => {
4444
recurseIntoObject(topLevelEntry, (subEntry) => {
4545
if (!Object.prototype.hasOwnProperty.call(subEntry, 'url')) return;
4646

47+
indexAndUrlChecks(filename, subEntry)?.forEach((error: string) => {
48+
errors.push(error);
49+
});
50+
51+
// Do not return errors if flagged as NYI
52+
if((subEntry.url as string).slice(-4) === '-nyi') {
53+
errors.forEach((error: string)=>{
54+
console.warn(error);
55+
})
56+
return;
57+
}
58+
4759
if (resources[subEntry.url as string] === undefined) {
4860
errors.push(`${filename}: URL '${subEntry.url}' not found.`);
4961
} else {
@@ -84,4 +96,48 @@ const recurseIntoObject = (object: Entry, callback: (subEntry: Entry) => void) =
8496
recurseIntoObject(object[property] as Entry, callback);
8597
}
8698
}
87-
};
99+
};
100+
101+
const indexAndUrlChecks = (filename: string, entry: Entry) => {
102+
const errors: string[] = [];
103+
104+
if (entry.index === undefined) {
105+
errors.push(`${filename}: Entry with URL '${entry.url}' should have an index.`);
106+
}
107+
108+
// Check Index for whitespace
109+
if((entry.index as string).indexOf(' ') != -1){
110+
errors.push(`${filename}: Index '${entry.index as string}' contains whitespace`);
111+
}
112+
113+
// Check Index for illegal characters
114+
if((entry.index as string).match(/[^-a-z0-9()]/)){
115+
errors.push(`${filename}: Index '${entry.index as string}' contains illegal characters`);
116+
}
117+
118+
// Check URL for whitespace
119+
if((entry.url as string).indexOf(' ') != -1){
120+
errors.push(`${filename}: URL '${entry.url as string}' contains whitespace`);
121+
}
122+
123+
// Check URL for illegal characters
124+
if((entry.url as string).match(/[^-/a-z0-9()]/)){
125+
errors.push(`${filename}: URL '${entry.url as string}' contains illegal characters`);
126+
}
127+
128+
// Check URL starts correctly
129+
if(!(entry.url as string).startsWith('/api/2024')){
130+
errors.push(`${filename}: URL '${entry.url as string}' is malformed`);
131+
}
132+
133+
// Check Index matches URL
134+
if((entry.url as string).slice(-4) == '-nyi'){
135+
console.warn(`${filename}: URL '${entry.url}' is marked as Not Yet Implemented.`)
136+
} else {
137+
if((entry.index as string) != (entry.url as string).slice(0 - (entry.index as string).length)){
138+
errors.push(`${filename}: Index '${entry.index as string}' does not match URL ${entry.url as string}`);
139+
}
140+
}
141+
142+
return errors;
143+
}

0 commit comments

Comments
 (0)