Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion dotcom-rendering/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ const rulesToEnforce = {

export default defineConfig([
...guardian.configs.recommended,
...guardian.configs.jest,
...guardian.configs.jest.map((config) => ({
...config,
// Don't apply Jest globals to Node test files
ignores: [...(config.ignores ?? []), '**/*.node.test.ts'],
})),
...guardian.configs.react,
...guardian.configs.storybook,
// eslint-plugin-prettier/recommended should be the last item in the configuration array so that eslint-config-prettier has the opportunity to override other configs
Expand Down
1 change: 1 addition & 0 deletions dotcom-rendering/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module.exports = {
'^.+\\.(mjs|js|ts|tsx)$': ['@swc/jest', swcConfig],
},
testMatch: ['**/*.test.+(ts|tsx|js)'],
testPathIgnorePatterns: ['\\.node\\.test\\.'],
setupFilesAfterEnv: ['<rootDir>/scripts/jest/setup.ts'],
moduleNameMapper: {
'^svgs/(.*)$': '<rootDir>/__mocks__/svgMock.tsx',
Expand Down
1 change: 1 addition & 0 deletions dotcom-rendering/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"lint:stats": "pnpm lint --format node_modules/eslint-stats/byError.js",
"tsc": "tsc",
"test": "IMAGE_DIGEST=sha256:12345 jest --maxWorkers=50%",
"test:node": "IMAGE_DIGEST=sha256:12345 node --import=tsx --test \"src/**/*.node.test.ts\"",
"test:watch": "IMAGE_DIGEST=sha256:12345 jest --watch --maxWorkers=25%",
"test:ci": "IMAGE_DIGEST=sha256:12345 jest --runInBand",
"playwright:open": "playwright test --ui",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { it } from 'node:test';
import { parse } from 'valibot';
import { euParliament } from '../../../fixtures/manual/electionTrackers/euParliament';
import { ukGeneralExitPoll } from '../../../fixtures/manual/electionTrackers/ukGeneralExitPoll';
Expand All @@ -7,26 +8,26 @@ import { usCongressEmpty } from '../../../fixtures/manual/electionTrackers/usCon
import { usPresidential } from '../../../fixtures/manual/electionTrackers/usPresidential';
import { ElectionComponents } from './electionComponent';

it('validates US Congress data', () => {
void it('validates US Congress data', () => {
parse(ElectionComponents, usCongressEmpty);
});

it('validates UK General data', () => {
void it('validates UK General data', () => {
parse(ElectionComponents, ukGeneralFinal);
});

it('validates UK General Exit Poll data', () => {
void it('validates UK General Exit Poll data', () => {
parse(ElectionComponents, ukGeneralExitPoll);
});

it('validates UK Local data', () => {
void it('validates UK Local data', () => {
parse(ElectionComponents, ukLocal);
});

it('validates US Presidential data', () => {
void it('validates US Presidential data', () => {
parse(ElectionComponents, usPresidential);
});

it('validates EU Parliament data', () => {
void it('validates EU Parliament data', () => {
parse(ElectionComponents, euParliament);
});
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import { liveMatch, resultMatch } from '../fixtures/manual/cricketMatch';
import { parseCricketMatch } from './cricketMatch';

describe('parseCricketMatchV2', () => {
it('parses a winner result cricket match correctly', () => {
void describe('parseCricketMatchV2', () => {
void it('parses a winner result cricket match correctly', () => {
const result = parseCricketMatch(resultMatch).getOrThrow(
'Expected parsing cricket match to succeed',
);

expect(result.kind).toEqual('Result');
expect(result.result).toEqual({
assert.equal(result.kind, 'Result');
assert.deepEqual(result.result, {
type: 'home-win',
description: 'England win by 115 runs',
winner: {
Expand All @@ -17,32 +19,35 @@ describe('parseCricketMatchV2', () => {
margin: 115,
},
});
expect(result.matchDate).toEqual(new Date('2026-06-17T10:00:00.000Z'));
assert.deepEqual(
result.matchDate,
new Date('2026-06-17T10:00:00.000Z'),
);
});

it('parses a cricket match in pre-match status', () => {
void it('parses a cricket match in pre-match status', () => {
const result = parseCricketMatch({
...liveMatch,
result: 'pre-match',
fullResult: undefined,
}).getOrThrow('Expected parsing cricket match to succeed');

expect(result.kind).toEqual('Fixture');
expect(result.result).toEqual(undefined);
assert.equal(result.kind, 'Fixture');
assert.equal(result.result, undefined);
});

it('parses a cricket match in in-play status', () => {
void it('parses a cricket match in in-play status', () => {
const result = parseCricketMatch({
...liveMatch,
result: 'in-play',
fullResult: undefined,
}).getOrThrow('Expected parsing cricket match to succeed');

expect(result.kind).toEqual('Live');
expect(result.result).toEqual(undefined);
assert.equal(result.kind, 'Live');
assert.equal(result.result, undefined);
});

it('parses an abandoned cricket match correctly', () => {
void it('parses an abandoned cricket match correctly', () => {
const result = parseCricketMatch({
...liveMatch,
fullResult: {
Expand All @@ -52,14 +57,13 @@ describe('parseCricketMatchV2', () => {
},
}).getOrThrow('Expected parsing cricket match to succeed');

expect(result.result).toEqual({
assert.deepEqual(result.result, {
type: 'abandoned',
description: 'Match abandoned due to rain',
winner: undefined,
});
});

it('parses a cricket match with no winner', () => {
void it('parses a cricket match with no winner', () => {
const result = parseCricketMatch({
...liveMatch,
fullResult: {
Expand All @@ -69,10 +73,9 @@ describe('parseCricketMatchV2', () => {
},
}).getOrThrow('Expected parsing cricket match to succeed');

expect(result.result).toEqual({
assert.deepEqual(result.result, {
type: 'no-result',
description: 'No result',
winner: undefined,
});
});
});
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import { footballData } from '../fixtures/generated/football-live';
import {
emptyMatches,
Expand Down Expand Up @@ -25,25 +27,25 @@ const withMatches = (
})),
}));

describe('footballMatches', () => {
it('should parse match fixtures correctly', () => {
void describe('footballMatches', () => {
void it('should parse match fixtures correctly', () => {
const result = parse(footballData.matchesList).getOrThrow(
'Expected football match parsing to succeed',
);

expect(result.length).toBe(1);
assert.equal(result.length, 1);

const day = result[0];
expect(day?.dateISOString).toBe('2025-04-28T00:00:00.000Z');
expect(day?.competitions.length).toBe(2);
assert.equal(day?.dateISOString, '2025-04-28T00:00:00.000Z');
assert.equal(day?.competitions.length, 2);

const competition = day?.competitions[0];
expect(competition?.name).toBe('Serie A');
expect(competition?.matches[0]?.kind).toBe('Fixture');
expect(competition?.tag).toBe('football/serieafootball');
assert.equal(competition?.name, 'Serie A');
assert.equal(competition?.matches[0]?.kind, 'Fixture');
assert.equal(competition?.tag, 'football/serieafootball');
});

it('should return an error when football days have invalid dates', () => {
void it('should return an error when football days have invalid dates', () => {
const invalidDate: FEMatchByDateAndCompetition[] = emptyMatches.map(
(day) => ({
...day,
Expand All @@ -55,10 +57,10 @@ describe('footballMatches', () => {
'Expected football match parsing to fail',
);

expect(result.kind).toBe('FootballDayInvalidDate');
assert.equal(result.kind, 'FootballDayInvalidDate');
});

it('should return an error when football matches have an invalid date', () => {
void it('should return an error when football matches have an invalid date', () => {
const invalidMatchResult: FEMatchByDateAndCompetition[] = withMatches([
matchFixture,
{ ...matchResult, date: '' },
Expand All @@ -85,24 +87,24 @@ describe('footballMatches', () => {
'Expected football match parsing to fail',
);

expect(resultOne.kind).toBe('FootballMatchInvalidDate');
expect(resultTwo.kind).toBe('FootballMatchInvalidDate');
assert.equal(resultOne.kind, 'FootballMatchInvalidDate');
assert.equal(resultTwo.kind, 'FootballMatchInvalidDate');

if (resultThree.kind !== 'InvalidMatchDay') {
throw new Error('Expected an invalid match day error');
}

expect(resultThree.errors[0]!.kind).toBe('FootballMatchInvalidDate');
assert.equal(resultThree.errors[0]!.kind, 'FootballMatchInvalidDate');
});

it('should return an error when it receives a live match', () => {
void it('should return an error when it receives a live match', () => {
const result = parse(withMatches([liveMatch])).getErrorOrThrow(
'Expected football match parsing to fail',
);

expect(result.kind).toBe('UnexpectedLiveMatch');
assert.equal(result.kind, 'UnexpectedLiveMatch');
});
it('should return a clean team name', () => {
void it('should return a clean team name', () => {
const matchesListWithTeamName = (teamName: string): FEResult => {
return {
...matchResult,
Expand Down Expand Up @@ -136,10 +138,10 @@ describe('footballMatches', () => {
throw new Error('Expected Result');
}

expect(match.homeTeam.name).toBe(cleanName);
assert.equal(match.homeTeam.name, cleanName);
}
});
it('should replace known live match status with our status', () => {
void it('should replace known live match status with our status', () => {
const matchDay = parse(
withMatches([matchDayLiveSecondHalf]),
).getOrThrow('Expected football live match parsing to succeed');
Expand All @@ -149,9 +151,9 @@ describe('footballMatches', () => {
throw new Error('Expected live match');
}

expect(match.status).toBe('2nd');
assert.equal(match.status, '2nd');
});
it('should replace unknown live match status with first two characters', () => {
void it('should replace unknown live match status with first two characters', () => {
const matchDayLiveUnknownStatus = {
...matchDayLiveSecondHalf,
matchStatus: 'Something odd',
Expand All @@ -166,6 +168,6 @@ describe('footballMatches', () => {
throw new Error('Expected live match');
}

expect(match.status).toBe('So');
assert.equal(match.status, 'So');
});
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import { addTrackingCodesToUrl } from './acquisitions';

describe('acquisitions', () => {
it('should addTrackingCodesToUrl', () => {
void describe('acquisitions', () => {
void it('should addTrackingCodesToUrl', () => {
const result = addTrackingCodesToUrl({
base: `https://support.theguardian.com/contribute`,
componentType: 'ACQUISITIONS_HEADER',
Expand All @@ -15,7 +17,8 @@ describe('acquisitions', () => {
referrerUrl: 'https://theguardian.com/uk',
});

expect(result).toEqual(
assert.equal(
result,
'https://support.theguardian.com/contribute?REFPVID=abcdefg&INTCMP=header_support&acquisitionData=%7B%22source%22%3A%22GUARDIAN_WEB%22%2C%22componentId%22%3A%22header_support%22%2C%22componentType%22%3A%22ACQUISITIONS_HEADER%22%2C%22campaignCode%22%3A%22header_support%22%2C%22abTest%22%3A%7B%22name%22%3A%22testName%22%2C%22variant%22%3A%22variantName%22%7D%2C%22referrerPageviewId%22%3A%22abcdefg%22%2C%22referrerUrl%22%3A%22https%3A%2F%2Ftheguardian.com%2Fuk%22%7D',
);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import { buildAdTargeting } from './ad-targeting';

const sharedAdTargeting = {
Expand All @@ -12,7 +14,7 @@ const sharedAdTargeting = {
url: '/money/2017/mar/10/ministers-to-criminalise-use-of-ticket-tout-harvesting-software',
};

describe('buildAdTargeting', () => {
void describe('buildAdTargeting', () => {
const expectedAdTargeting = {
adUnit: '/59666047/theguardian.com/money/article/ng',
customParams: {
Expand All @@ -38,8 +40,8 @@ describe('buildAdTargeting', () => {
},
};

it('builds adTargeting correctly', () => {
expect(
void it('builds adTargeting correctly', () => {
assert.deepEqual(
buildAdTargeting({
isAdFreeUser: false,
isSensitive: false,
Expand All @@ -48,6 +50,7 @@ describe('buildAdTargeting', () => {
sharedAdTargeting,
adUnit: '/59666047/theguardian.com/money/article/ng',
}),
).toEqual(expectedAdTargeting);
expectedAdTargeting,
);
});
});
Loading
Loading