Skip to content

Commit

Permalink
Makefile: github/workflows/frontend: Add i18n-check to CI
Browse files Browse the repository at this point in the history
Fixes tests so they are not run twice #2125

Running it inside the tests makes the translation files be written
when the tests run, causing the tests to run twice.

Running it as a pre-commit hook is a bit slow (3.0s), because
it looks at all the files that have changed, and then writes all
the translation files again.

So instead we run it in CI so it catches the issues.

Signed-off-by: René Dudfield <renedudfield@microsoft.com>
  • Loading branch information
illume committed Jul 15, 2024
1 parent 973e684 commit 32c4a21
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 17 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ jobs:
run: |
make frontend-test
- name: Run frontend-i18n-check
run: |
make frontend-i18n-check
build:
name: build
runs-on: ${{ matrix.os }}
Expand Down
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ frontend-fixlint:
frontend-tsc:
cd frontend && npm run tsc

.PHONY: frontend-i18n-check
frontend-i18n-check:
@echo "Checking translations. If this fails use: 'npm run i18n'"
cd frontend && npm run i18n -- --fail-on-update

frontend-test:
cd frontend && npm run test -- --coverage

Expand Down
17 changes: 0 additions & 17 deletions frontend/src/i18n/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { execSync } from 'child_process';
import { error } from 'console';
import fs from 'fs';
import * as glob from 'glob';

const path = require('node:path');
const allowlist = require('./allowlist.json');

const frontendDir = path.join(__dirname, '..', '..');

/*
* Description:
* This test will check for duplicate keys in the translation files and will fail if any are found.
Expand Down Expand Up @@ -120,17 +117,3 @@ describe('Test for non-intentional repeating translation keys', () => {
expect(result).toBe(true);
});
});

function getTranslationChanges() {
// Get uncommitted changes in the tracked translation files.
return execSync(
`git status -uno --porcelain ${frontendDir}/src/i18n/locales/*/*.json`
).toString();
}

describe('Forgotten translations', () => {
test('Check uncommitted translations', async () => {
execSync('npm run i18n', { cwd: frontendDir });
expect(getTranslationChanges()).toBe('');
});
});

0 comments on commit 32c4a21

Please sign in to comment.