From ef0c9f5dedd85e84e20a0efd953e0ec6df3d2257 Mon Sep 17 00:00:00 2001 From: Mats Larsen Date: Mon, 28 Oct 2024 18:59:56 +0900 Subject: [PATCH] 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. --- cypress/tsconfig.json | 3 ++- static/tests/motd.ts | 18 ++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/cypress/tsconfig.json b/cypress/tsconfig.json index eebecfbe9..2dba58837 100644 --- a/cypress/tsconfig.json +++ b/cypress/tsconfig.json @@ -8,6 +8,7 @@ /* Code generation */ "typeRoots": ["../node_modules/@types"], /* https://github.com/cypress-io/cypress/issues/26203#issuecomment-1571861397 */ - "sourceMap": false + "sourceMap": false, + "types": ["cypress"] } } diff --git a/static/tests/motd.ts b/static/tests/motd.ts index 79ed3452f..b5352df6b 100644 --- a/static/tests/motd.ts +++ b/static/tests/motd.ts @@ -33,15 +33,17 @@ import {Ad} from '../motd.interfaces.js'; class MotdTests implements ITestable { public readonly description: string = 'motd'; - private static assertAd(ad: Ad, subLang, expected: boolean, message: string) { - isValidAd(ad, subLang).should.deep.equal(expected, message); + private static assertAd(ad: Ad, subLang: string, expected: boolean, message: string) { + if (isValidAd(ad, subLang) !== expected) { + throw new Error(message); + } } - private static assertAdWithDateNow(dateNow: number, ad: Ad, subLang, expected: boolean, message: string) { - const dateNowStub = cy.spy(Date, 'now'); - dateNowStub.alwaysReturned(dateNow); + private static assertAdWithDateNow(dateNow: number, ad: Ad, subLang: string, expected: boolean, message: string) { + const originalDateNow = Date.now; + Date.now = () => dateNow; MotdTests.assertAd(ad, subLang, expected, message); - dateNowStub.restore(); + Date.now = originalDateNow; } public async run() { @@ -50,7 +52,7 @@ class MotdTests implements ITestable { filter: [], html: '', }, - null, + 'fakeLang', true, 'Keep ad if sublang is not set', ); @@ -60,7 +62,7 @@ class MotdTests implements ITestable { filter: ['fakeLang'], html: '', }, - true, + 'langForTest', false, 'Keep ad if sublang is not set even if filtering for lang', );