Files
privacy.sexy/tests/integration/infrastructure/Metadata/Vite/ViteAppMetadata.spec.ts
undergroundwires ec98d8417f Migrate Cypress (E2E) tests to Vite and TypeScript
This commit progresses the migration from Vue CLI to Vite (#230).

TypeScript migration:

- Convert JavaScript Cypress tests and configurations to TypeScript.
- Introduce `tsconfig.json` for Cypress, following official
  recommendation.

Test execution:

- Use Cypress CLI to run the tests.
- Rename Cypress commands to reflect official naming conventions.
- Start Vue server prior to Cypress execution, using
  `start-server-and-test` package based on official documentation.
- Remove dependency on Vue CLI plugin ((`@vue/cli-plugin-e2e-cypress`).

Configuration standardization (based on Cypress docs):

- Delete unused `plugins/` directory.
- Move test (spec) files to to the root directory.
- Add official ESLint plugin (`eslint-plugin-cypress`).

Changes for importing `vite.config.ts` into `cypress.config.ts`:

- Add TypeScript import assertations to files importing JSON files.
- Use ESM friendly way instead of `__dirname` to solve `ReferenceError:
  __dirname is not defined in ES module scrope`.

Other changes:

- Simplify comments in placeholder files.
- Create Cypress specific `.gitignore` for enhanced maintainability,
  clarity and scalability.
- Remove redundant `vue.config.cjs`.
2023-08-24 13:45:34 +02:00

48 lines
1.5 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import { ViteAppMetadata } from '@/infrastructure/Metadata/Vite/ViteAppMetadata';
import packageJson from '@/../package.json' assert { type: 'json' };
import { PropertyKeys } from '@tests/shared/TypeHelpers';
describe('ViteAppMetadata', () => {
describe('populates from package.json', () => {
interface ITestCase {
readonly getActualValue: (sut: ViteAppMetadata) => string;
readonly expected: string;
}
const testCases: { readonly [K in PropertyKeys<ViteAppMetadata>]: ITestCase } = {
name: {
expected: packageJson.name,
getActualValue: (sut) => sut.name,
},
version: {
expected: packageJson.version,
getActualValue: (sut) => sut.version,
},
slogan: {
expected: packageJson.slogan,
getActualValue: (sut) => sut.slogan,
},
repositoryUrl: {
expected: packageJson.repository.url,
getActualValue: (sut) => sut.repositoryUrl,
},
homepageUrl: {
expected: packageJson.homepage,
getActualValue: (sut) => sut.homepageUrl,
},
};
Object.entries(testCases).forEach(([propertyName, { expected, getActualValue }]) => {
it(`should correctly get the value of ${propertyName}`, () => {
// arrange
const sut = new ViteAppMetadata();
// act
const actualValue = getActualValue(sut);
// assert
expect(actualValue).toBe(expected);
});
});
});
});