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`.
This commit is contained in:
@@ -1,60 +1,111 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { parseProjectInformation } from '@/application/Parser/ProjectInformationParser';
|
||||
import { IProjectInformation } from '@/domain/IProjectInformation';
|
||||
import { parseProjectInformation, ProjectInformationFactory } from '@/application/Parser/ProjectInformationParser';
|
||||
import { AppMetadataStub } from '@tests/unit/shared/Stubs/AppMetadataStub';
|
||||
import { PropertyKeys } from '@/TypeHelpers';
|
||||
import { ProjectInformationStub } from '@tests/unit/shared/Stubs/ProjectInformationStub';
|
||||
import { Version } from '@/domain/Version';
|
||||
|
||||
describe('ProjectInformationParser', () => {
|
||||
describe('parseProjectInformation', () => {
|
||||
interface IEnvironmentParsingTestCase {
|
||||
readonly testCaseName: string;
|
||||
readonly setMetadata: (appMetadataStub: AppMetadataStub, value: string) => AppMetadataStub;
|
||||
readonly expectedValue: string;
|
||||
readonly getActualValue: (info: IProjectInformation) => string;
|
||||
}
|
||||
const testCases: readonly IEnvironmentParsingTestCase[] = [
|
||||
{
|
||||
testCaseName: 'version',
|
||||
setMetadata: (metadata, value) => metadata.withVersion(value),
|
||||
expectedValue: '0.11.3',
|
||||
getActualValue: (info) => info.version.toString(),
|
||||
},
|
||||
{
|
||||
testCaseName: 'name',
|
||||
setMetadata: (metadata, value) => metadata.witName(value),
|
||||
expectedValue: 'expected-app-name',
|
||||
getActualValue: (info) => info.name,
|
||||
},
|
||||
{
|
||||
testCaseName: 'homepage',
|
||||
setMetadata: (metadata, value) => metadata.withHomepageUrl(value),
|
||||
expectedValue: 'https://expected.sexy',
|
||||
getActualValue: (info) => info.homepage,
|
||||
},
|
||||
{
|
||||
testCaseName: 'repositoryUrl',
|
||||
setMetadata: (metadata, value) => metadata.withRepositoryUrl(value),
|
||||
expectedValue: 'https://expected-repository.url',
|
||||
getActualValue: (info) => info.repositoryUrl,
|
||||
},
|
||||
{
|
||||
testCaseName: 'slogan',
|
||||
setMetadata: (metadata, value) => metadata.withSlogan(value),
|
||||
expectedValue: 'expected-slogan',
|
||||
getActualValue: (info) => info.slogan,
|
||||
},
|
||||
];
|
||||
for (const {
|
||||
expectedValue, testCaseName, setMetadata, getActualValue,
|
||||
} of testCases) {
|
||||
it(testCaseName, () => {
|
||||
it('returns expected information', () => {
|
||||
// arrange
|
||||
const expectedInformation = new ProjectInformationStub();
|
||||
const factoryMock = () => expectedInformation;
|
||||
// act
|
||||
const actualInformation = parseProjectInformation(new AppMetadataStub(), factoryMock);
|
||||
// assert
|
||||
expect(expectedInformation).to.equal(actualInformation);
|
||||
});
|
||||
describe('default behavior does not throw', () => {
|
||||
it('without metadataFactory', () => {
|
||||
// arrange
|
||||
const metadataFactory = undefined;
|
||||
const informationFactory = new ProjectInformationFactoryStub().getStub();
|
||||
// act
|
||||
const metadata = setMetadata(new AppMetadataStub(), expectedValue);
|
||||
// act
|
||||
const info = parseProjectInformation(metadata);
|
||||
// assert
|
||||
const actual = getActualValue(info);
|
||||
expect(actual).to.be.equal(expectedValue);
|
||||
const act = () => parseProjectInformation(metadataFactory, informationFactory);
|
||||
// expectS
|
||||
expect(act).to.not.throw();
|
||||
});
|
||||
}
|
||||
it('without projectInformationFactory', () => {
|
||||
// arrange
|
||||
const metadataFactory = new AppMetadataStub();
|
||||
const informationFactory = undefined;
|
||||
// act
|
||||
const act = () => parseProjectInformation(metadataFactory, informationFactory);
|
||||
// expect
|
||||
expect(act).to.not.throw();
|
||||
});
|
||||
});
|
||||
describe('parses metadata to project information', () => {
|
||||
interface IMetadataTestCase {
|
||||
readonly setMetadata: (appMetadataStub: AppMetadataStub, value: string) => AppMetadataStub;
|
||||
readonly expectedValue: string;
|
||||
readonly getActualValue: (info: ProjectInformationFactoryStub) => string;
|
||||
}
|
||||
const testCases: { [K in PropertyKeys<ProjectInformationFactoryStub>]: IMetadataTestCase } = {
|
||||
name: {
|
||||
setMetadata: (metadata, value) => metadata.witName(value),
|
||||
expectedValue: 'expected-app-name',
|
||||
getActualValue: (info) => info.name,
|
||||
},
|
||||
version: {
|
||||
setMetadata: (metadata, value) => metadata.withVersion(value),
|
||||
expectedValue: '0.11.3',
|
||||
getActualValue: (info) => info.version.toString(),
|
||||
},
|
||||
slogan: {
|
||||
setMetadata: (metadata, value) => metadata.withSlogan(value),
|
||||
expectedValue: 'expected-slogan',
|
||||
getActualValue: (info) => info.slogan,
|
||||
},
|
||||
repositoryUrl: {
|
||||
setMetadata: (metadata, value) => metadata.withRepositoryUrl(value),
|
||||
expectedValue: 'https://expected-repository.url',
|
||||
getActualValue: (info) => info.repositoryUrl,
|
||||
},
|
||||
homepage: {
|
||||
setMetadata: (metadata, value) => metadata.withHomepageUrl(value),
|
||||
expectedValue: 'https://expected.sexy',
|
||||
getActualValue: (info) => info.homepage,
|
||||
},
|
||||
};
|
||||
Object.entries(testCases).forEach(([propertyName, {
|
||||
expectedValue, setMetadata, getActualValue,
|
||||
}]) => {
|
||||
it(propertyName, () => {
|
||||
// act
|
||||
const metadata = setMetadata(new AppMetadataStub(), expectedValue);
|
||||
const factoryStub = new ProjectInformationFactoryStub();
|
||||
// act
|
||||
parseProjectInformation(metadata, factoryStub.getStub());
|
||||
// assert
|
||||
const actual = getActualValue(factoryStub);
|
||||
expect(actual).to.be.equal(expectedValue);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
class ProjectInformationFactoryStub {
|
||||
public name: string;
|
||||
|
||||
public version: Version;
|
||||
|
||||
public slogan: string;
|
||||
|
||||
public repositoryUrl: string;
|
||||
|
||||
public homepage: string;
|
||||
|
||||
public getStub(): ProjectInformationFactory {
|
||||
return (name, version, slogan, repositoryUrl, homepage) => {
|
||||
this.name = name;
|
||||
this.version = version;
|
||||
this.slogan = slogan;
|
||||
this.repositoryUrl = repositoryUrl;
|
||||
this.homepage = homepage;
|
||||
return new ProjectInformationStub();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user