Don't use sinon/chai code for frontend tests

Using these imply that sinon and chai will be built for the final bundle that the user downloads. This is not a good thing, because it bloats our bundle.
This commit is contained in:
Mats Larsen
2024-10-28 18:59:56 +09:00
parent 5e27a95042
commit ef0c9f5ded
2 changed files with 12 additions and 9 deletions

View File

@@ -8,6 +8,7 @@
/* Code generation */ /* Code generation */
"typeRoots": ["../node_modules/@types"], "typeRoots": ["../node_modules/@types"],
/* https://github.com/cypress-io/cypress/issues/26203#issuecomment-1571861397 */ /* https://github.com/cypress-io/cypress/issues/26203#issuecomment-1571861397 */
"sourceMap": false "sourceMap": false,
"types": ["cypress"]
} }
} }

View File

@@ -33,15 +33,17 @@ import {Ad} from '../motd.interfaces.js';
class MotdTests implements ITestable { class MotdTests implements ITestable {
public readonly description: string = 'motd'; public readonly description: string = 'motd';
private static assertAd(ad: Ad, subLang, expected: boolean, message: string) { private static assertAd(ad: Ad, subLang: string, expected: boolean, message: string) {
isValidAd(ad, subLang).should.deep.equal(expected, message); if (isValidAd(ad, subLang) !== expected) {
throw new Error(message);
}
} }
private static assertAdWithDateNow(dateNow: number, ad: Ad, subLang, expected: boolean, message: string) { private static assertAdWithDateNow(dateNow: number, ad: Ad, subLang: string, expected: boolean, message: string) {
const dateNowStub = cy.spy(Date, 'now'); const originalDateNow = Date.now;
dateNowStub.alwaysReturned(dateNow); Date.now = () => dateNow;
MotdTests.assertAd(ad, subLang, expected, message); MotdTests.assertAd(ad, subLang, expected, message);
dateNowStub.restore(); Date.now = originalDateNow;
} }
public async run() { public async run() {
@@ -50,7 +52,7 @@ class MotdTests implements ITestable {
filter: [], filter: [],
html: '', html: '',
}, },
null, 'fakeLang',
true, true,
'Keep ad if sublang is not set', 'Keep ad if sublang is not set',
); );
@@ -60,7 +62,7 @@ class MotdTests implements ITestable {
filter: ['fakeLang'], filter: ['fakeLang'],
html: '', html: '',
}, },
true, 'langForTest',
false, false,
'Keep ad if sublang is not set even if filtering for lang', 'Keep ad if sublang is not set even if filtering for lang',
); );