From 0c04e1a9ed2bbe7873bfd5a4ee9d6b747b0fd1f1 Mon Sep 17 00:00:00 2001 From: Oliver Eyton-Williams Date: Thu, 23 Oct 2025 12:02:40 +0200 Subject: [PATCH] test: use expect for clearer errors (#62965) --- curriculum/package.json | 3 +-- curriculum/src/test/test-challenges.js | 33 ++++++++++---------------- pnpm-lock.yaml | 9 +++---- 3 files changed, 16 insertions(+), 29 deletions(-) diff --git a/curriculum/package.json b/curriculum/package.json index 1d6e0377092..53a44e9c781 100644 --- a/curriculum/package.json +++ b/curriculum/package.json @@ -41,13 +41,12 @@ "devDependencies": { "@babel/core": "7.23.7", "@babel/register": "7.23.7", - "@types/polka": "^0.5.7", "@total-typescript/ts-reset": "^0.6.1", "@types/debug": "^4.1.12", "@types/js-yaml": "4.0.5", + "@types/polka": "^0.5.7", "@types/string-similarity": "^4.0.2", "@vitest/ui": "^3.2.4", - "chai": "4.4.1", "glob": "8.1.0", "joi": "17.12.2", "joi-objectid": "3.0.1", diff --git a/curriculum/src/test/test-challenges.js b/curriculum/src/test/test-challenges.js index 22f1bda1c1f..050e700661c 100644 --- a/curriculum/src/test/test-challenges.js +++ b/curriculum/src/test/test-challenges.js @@ -1,5 +1,4 @@ import { describe, it, beforeAll, expect } from 'vitest'; -import { assert, AssertionError } from 'chai'; import jsdom from 'jsdom'; import lodash from 'lodash'; @@ -151,33 +150,28 @@ function populateTestsForLang({ lang, challenges, meta }) { const index = meta[dashedBlockName]?.challengeOrder?.findIndex( ({ id }) => id === challenge.id ); - - if (index < 0) { - throw new AssertionError( - `Cannot find ID "${challenge.id}" in meta.json file for block "${dashedBlockName}"` - ); - } + expect( + index, + `Cannot find ID "${challenge.id}" in meta.json file for block "${dashedBlockName}"` + ).toBeGreaterThanOrEqual(0); }); it('Common checks', function () { const result = validateChallenge(challenge); - if (result.error) { - throw new AssertionError(result.error); - } + expect(result.error).toBeUndefined(); const { id, block, dashedName } = challenge; - assert.exists( - dashedName, - `Missing dashedName for challenge ${id} in ${block}.` - ); + + expect(dashedName).toBeDefined(); + const pathAndTitle = `${block}/${dashedName}`; const idVerificationMessage = mongoIds.check(id, block); - assert.isNull(idVerificationMessage, idVerificationMessage); + expect(idVerificationMessage).toBeNull(); const dupeTitleCheck = challengeTitles.check(dashedName, block); - assert.isTrue( + expect( dupeTitleCheck, `All challenges within a block must have a unique dashed name. ${dashedName} (at ${pathAndTitle}) is already assigned` - ); + ).toBeTruthy(); }); const { challengeType } = challenge; @@ -231,10 +225,7 @@ function populateTestsForLang({ lang, challenges, meta }) { } } console.error = oldConsoleError; - assert( - fails, - 'Test suite does not fail on the initial contents' - ); + expect(fails, 'Test suite should fail on the initial contents'); }, timePerTest * tests.length + 20000 ); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 09b011de58f..b9f757c822d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -730,9 +730,6 @@ importers: '@vitest/ui': specifier: ^3.2.4 version: 3.2.4(vitest@3.2.4) - chai: - specifier: 4.4.1 - version: 4.4.1 glob: specifier: 8.1.0 version: 8.1.0 @@ -777,7 +774,7 @@ importers: version: 4.0.4 vitest: specifier: ^3.2.4 - version: 3.2.4(@types/node@20.12.8)(@vitest/ui@3.2.4)(jiti@2.6.1)(jsdom@16.7.0)(msw@2.8.7(@types/node@20.12.8)(typescript@5.8.2))(terser@5.28.1)(tsx@4.19.1)(yaml@2.8.0) + version: 3.2.4(@types/debug@4.1.12)(@types/node@20.12.8)(@vitest/ui@3.2.4)(jiti@2.6.1)(jsdom@16.7.0)(msw@2.8.7(@types/node@20.12.8)(typescript@5.8.2))(terser@5.28.1)(tsx@4.19.1)(yaml@2.8.0) shared: devDependencies: @@ -20163,7 +20160,7 @@ snapshots: sirv: 3.0.2 tinyglobby: 0.2.14 tinyrainbow: 2.0.0 - vitest: 3.2.4(@types/node@20.12.8)(@vitest/ui@3.2.4)(jiti@2.6.1)(jsdom@26.1.0)(msw@2.8.7(@types/node@20.12.8)(typescript@5.7.3))(terser@5.28.1)(tsx@4.19.1)(yaml@2.8.0) + vitest: 3.2.4(@types/debug@4.1.12)(@types/node@20.12.8)(@vitest/ui@3.2.4)(jiti@2.6.1)(jsdom@16.7.0)(msw@2.8.7(@types/node@20.12.8)(typescript@5.8.2))(terser@5.28.1)(tsx@4.19.1)(yaml@2.8.0) '@vitest/utils@3.2.4': dependencies: @@ -31143,7 +31140,7 @@ snapshots: - debug - typescript - vitest@3.2.4(@types/node@20.12.8)(@vitest/ui@3.2.4)(jiti@2.6.1)(jsdom@16.7.0)(msw@2.8.7(@types/node@20.12.8)(typescript@5.8.2))(terser@5.28.1)(tsx@4.19.1)(yaml@2.8.0): + vitest@3.2.4(@types/debug@4.1.12)(@types/node@20.12.8)(@vitest/ui@3.2.4)(jiti@2.6.1)(jsdom@16.7.0)(msw@2.8.7(@types/node@20.12.8)(typescript@5.8.2))(terser@5.28.1)(tsx@4.19.1)(yaml@2.8.0): dependencies: '@types/chai': 5.2.2 '@vitest/expect': 3.2.4