Files
privacy.sexy/tests/unit/infrastructure/Metadata/ViteAppMetadata.spec.ts
undergroundwires 75c9b51bf2 Migrate to electron-vite and electron-builder
- Switch from deprecated Vue CLI plugin to `electron-vite` (see
  nklayman/vue-cli-plugin-electron-builder#1982)
- Update main/preload scripts to use `index.cjs` filenames to support
  `"type": "module"`, resolving crash issue (#233). This crash was
  related to Electron not supporting ESM (see electron/asar#249,
  electron/electron#21457).
- This commit completes migration to Vite from Vue CLI (#230).

Structure changes:

- Introduce separate folders for Electron's main and preload processes.
- Move TypeHelpers to `src/` to mark tit as accessible by the rest of
  the code.

Config changes:

- Make `vite.config.ts` reusable by Electron configuration.
- On electron-builder, use `--publish` flag instead of `-p` for clarity.

Tests:

- Add log for preload script loading verification.
- Implement runtime environment sanity checks.
- Enhance logging in `check-desktop-runtime-errors`.
2023-08-24 20:01:53 +02:00

66 lines
2.2 KiB
TypeScript

import {
describe, beforeEach, afterEach, expect,
} from 'vitest';
import { ViteAppMetadata } from '@/infrastructure/Metadata/Vite/ViteAppMetadata';
import { VITE_ENVIRONMENT_KEYS } from '@/infrastructure/Metadata/Vite/ViteEnvironmentKeys';
import { PropertyKeys } from '@/TypeHelpers';
describe('ViteAppMetadata', () => {
describe('reads values from import.meta.env', () => {
let originalMetaEnv;
beforeEach(() => {
originalMetaEnv = { ...import.meta.env };
});
afterEach(() => {
Object.assign(import.meta.env, originalMetaEnv);
});
interface ITestCase {
readonly getActualValue: (sut: ViteAppMetadata) => string;
readonly environmentVariable: typeof VITE_ENVIRONMENT_KEYS[
keyof typeof VITE_ENVIRONMENT_KEYS];
readonly expected: string;
}
const testCases: { [K in PropertyKeys<ViteAppMetadata>]: ITestCase } = {
name: {
environmentVariable: VITE_ENVIRONMENT_KEYS.NAME,
expected: 'expected-name',
getActualValue: (sut) => sut.name,
},
version: {
environmentVariable: VITE_ENVIRONMENT_KEYS.VERSION,
expected: 'expected-version',
getActualValue: (sut) => sut.version,
},
repositoryUrl: {
environmentVariable: VITE_ENVIRONMENT_KEYS.REPOSITORY_URL,
expected: 'expected-slogan',
getActualValue: (sut) => sut.repositoryUrl,
},
slogan: {
environmentVariable: VITE_ENVIRONMENT_KEYS.SLOGAN,
expected: 'expected-repositoryUrl',
getActualValue: (sut) => sut.slogan,
},
homepageUrl: {
environmentVariable: VITE_ENVIRONMENT_KEYS.HOMEPAGE_URL,
expected: 'expected-homepageUrl',
getActualValue: (sut) => sut.homepageUrl,
},
};
Object.values(testCases).forEach(({ environmentVariable, expected, getActualValue }) => {
it(`should correctly get the value of ${environmentVariable}`, () => {
// arrange
import.meta.env[environmentVariable] = expected;
// act
const sut = new ViteAppMetadata();
const actualValue = getActualValue(sut);
// assert
expect(actualValue).toBe(expected);
});
});
});
});