Merge pull request #15477 from keymanapp/fix/web/tests

fix(web): fix problem with tests if KEYMAN_ROOT is not set 🎼

When running mocha without starting it through `build.sh`/`test.sh` the tests failed if the `KEYMAN_ROOT` environment variable was not set. Things were almost correct, but the undefined `KEYMAN_ROOT` variable added an extra `undefined` subdirectory. This change fixes this problem by setting `KEYMAN_ROOT` relative to the current file. This gets removed by `pathToFileURL` which also adds the absolute path to the current directory since we pass a relative path as argument.
This commit is contained in:
Eberhard Beilharz 2026-01-26 11:30:22 +01:00 committed by GitHub
commit bfa6dfa412
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -5,7 +5,11 @@
import fs from 'node:fs';
import { pathToFileURL } from 'node:url';
const KEYMAN_ROOT = process.env['KEYMAN_ROOT'];
import { fileURLToPath } from 'node:url';
import { dirname } from 'node:path';
const __dirname = dirname(fileURLToPath(import.meta.url));
const KEYMAN_ROOT = process.env['KEYMAN_ROOT'] ?? (__dirname + '/../../../../../../');
export const coreurl = pathToFileURL(`${KEYMAN_ROOT}/web/build/engine/obj/core-adapter/import/core`).toString();
export function loadKeyboardBlob(filename: string) {