Bump to TypeScript 5.5 and enable noImplicitAny
This commit upgrades TypeScript from 5.4 to 5.5 and enables the
`noImplicitAny` option for stricter type checking. It refactors code to
comply with `noImplicitAny` and adapts to new TypeScript features and
limitations.
Key changes:
- Migrate from TypeScript 5.4 to 5.5
- Enable `noImplicitAny` for stricter type checking
- Refactor code to comply with new TypeScript features and limitations
Other supporting changes:
- Refactor progress bar handling for type safety
- Drop 'I' prefix from interfaces to align with new code convention
- Update TypeScript target from `ES2017` and `ES2018`.
This allows named capturing groups. Otherwise, new TypeScript compiler
does not compile the project and shows the following error:
```
...
TimestampedFilenameGenerator.spec.ts:105:23 - error TS1503: Named capturing groups are only available when targeting 'ES2018' or later
const pattern = /^(?<timestamp>\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2})-(?<scriptName>[^.]+?)(?:\.(?<extension>[^.]+))?$/;// timestamp-scriptName.extension
...
```
- Refactor usage of `electron-progressbar` for type safety and
less complexity.
This commit is contained in:
@@ -37,9 +37,9 @@ describe('TimestampedFilenameGenerator', () => {
|
||||
// act
|
||||
const filename = generateFilenamePartsForTesting({ date });
|
||||
// assert
|
||||
expect(filename.timestamp).to.equal(expectedTimestamp, formatAssertionMessage[
|
||||
`Generated filename: ${filename.generatedFilename}`
|
||||
]);
|
||||
expect(filename.timestamp).to.equal(expectedTimestamp, formatAssertionMessage([
|
||||
`Generated filename: ${filename.generatedFilename}`,
|
||||
]));
|
||||
});
|
||||
describe('extension', () => {
|
||||
it('uses correct extension', () => {
|
||||
@@ -48,9 +48,9 @@ describe('TimestampedFilenameGenerator', () => {
|
||||
// act
|
||||
const filename = generateFilenamePartsForTesting({ extension: expectedExtension });
|
||||
// assert
|
||||
expect(filename.extension).to.equal(expectedExtension, formatAssertionMessage[
|
||||
`Generated filename: ${filename.generatedFilename}`
|
||||
]);
|
||||
expect(filename.extension).to.equal(expectedExtension, formatAssertionMessage([
|
||||
`Generated filename: ${filename.generatedFilename}`,
|
||||
]));
|
||||
});
|
||||
describe('handles absent extension', () => {
|
||||
itEachAbsentStringValue((absentExtension) => {
|
||||
@@ -59,9 +59,9 @@ describe('TimestampedFilenameGenerator', () => {
|
||||
// act
|
||||
const filename = generateFilenamePartsForTesting({ extension: absentExtension });
|
||||
// assert
|
||||
expect(filename.extension).to.equal(expectedExtension, formatAssertionMessage[
|
||||
`Generated file name: ${filename.generatedFilename}`
|
||||
]);
|
||||
expect(filename.extension).to.equal(expectedExtension, formatAssertionMessage([
|
||||
`Generated file name: ${filename.generatedFilename}`,
|
||||
]));
|
||||
}, { excludeNull: true });
|
||||
});
|
||||
it('errors on dot-starting extension', () => {
|
||||
|
||||
@@ -17,7 +17,8 @@ describe('OsSpecificTerminalLaunchCommandFactory', () => {
|
||||
[OperatingSystem.Linux]: LinuxVisibleTerminalCommand,
|
||||
[OperatingSystem.macOS]: MacOsVisibleTerminalCommand,
|
||||
};
|
||||
AllSupportedOperatingSystems.forEach((operatingSystem) => {
|
||||
AllSupportedOperatingSystems.forEach((operatingSystemValue) => {
|
||||
const operatingSystem = operatingSystemValue as SupportedOperatingSystem;
|
||||
it(`${OperatingSystem[operatingSystem]}`, () => {
|
||||
// arrange
|
||||
const expectedDefinitionType = testScenarios[operatingSystem];
|
||||
|
||||
@@ -8,7 +8,7 @@ import { ViteEnvironmentVariables } from '@/infrastructure/EnvironmentVariables/
|
||||
|
||||
describe('ViteEnvironmentVariables', () => {
|
||||
describe('reads values from import.meta.env', () => {
|
||||
let originalMetaEnv;
|
||||
let originalMetaEnv: ImportMetaEnv;
|
||||
beforeEach(() => {
|
||||
originalMetaEnv = { ...import.meta.env };
|
||||
});
|
||||
@@ -16,14 +16,15 @@ describe('ViteEnvironmentVariables', () => {
|
||||
Object.assign(import.meta.env, originalMetaEnv);
|
||||
});
|
||||
|
||||
interface ITestCase<T> {
|
||||
interface EnvironmentVariableTestScenario<T> {
|
||||
readonly getActualValue: (sut: IEnvironmentVariables) => T;
|
||||
readonly environmentVariable: typeof VITE_ENVIRONMENT_KEYS[
|
||||
keyof typeof VITE_ENVIRONMENT_KEYS];
|
||||
readonly expected: T;
|
||||
}
|
||||
const testCases: {
|
||||
readonly [K in PropertyKeys<IEnvironmentVariables>]: ITestCase<string | boolean>;
|
||||
readonly [K in PropertyKeys<IEnvironmentVariables>]:
|
||||
EnvironmentVariableTestScenario<string | boolean>;
|
||||
} = {
|
||||
name: {
|
||||
environmentVariable: VITE_ENVIRONMENT_KEYS.NAME,
|
||||
|
||||
@@ -119,14 +119,15 @@ describe('ConditionBasedOsDetector', () => {
|
||||
});
|
||||
|
||||
describe('user agent checks', () => {
|
||||
const testScenarios: ReadonlyArray<{
|
||||
interface UserAgentTestScenario {
|
||||
readonly description: string;
|
||||
readonly buildEnvironment: (environment: BrowserEnvironmentStub) => BrowserEnvironmentStub;
|
||||
readonly buildCondition: (condition: BrowserConditionStub) => BrowserConditionStub;
|
||||
readonly detects: boolean;
|
||||
}> = [
|
||||
}
|
||||
const testScenarios: ReadonlyArray<UserAgentTestScenario> = [
|
||||
...getAbsentStringTestCases({ excludeUndefined: true, excludeNull: true })
|
||||
.map((testCase) => ({
|
||||
.map((testCase): UserAgentTestScenario => ({
|
||||
description: `does not detect when user agent is empty (${testCase.valueName})`,
|
||||
buildEnvironment: (environment) => environment.withUserAgent(testCase.absentValue),
|
||||
buildCondition: (condition) => condition,
|
||||
|
||||
@@ -77,7 +77,8 @@ describe('WindowVariablesValidator', () => {
|
||||
});
|
||||
|
||||
describe('does not throw when a property is valid', () => {
|
||||
const testScenarios: Record<PropertyKeys<Required<WindowVariables>>, ReadonlyArray<{
|
||||
type WindowVariable = PropertyKeys<Required<WindowVariables>>;
|
||||
const testScenarios: Record<WindowVariable, ReadonlyArray<{
|
||||
readonly description: string;
|
||||
readonly validValue: unknown;
|
||||
}>> = {
|
||||
@@ -117,8 +118,10 @@ describe('WindowVariablesValidator', () => {
|
||||
validValueScenarios.forEach(({ description, validValue }) => {
|
||||
it(description, () => {
|
||||
// arrange
|
||||
const input = new WindowVariablesStub();
|
||||
input[propertyKey] = validValue;
|
||||
const input: WindowVariables = {
|
||||
...new WindowVariablesStub(),
|
||||
[propertyKey]: validValue,
|
||||
};
|
||||
const context = new ValidateWindowVariablesTestSetup()
|
||||
.withWindowVariables(input);
|
||||
// act
|
||||
@@ -173,8 +176,10 @@ describe('WindowVariablesValidator', () => {
|
||||
name: propertyKey as keyof WindowVariables,
|
||||
value: invalidValue,
|
||||
});
|
||||
const input = new WindowVariablesStub();
|
||||
input[propertyKey] = invalidValue;
|
||||
const input: WindowVariables = {
|
||||
...new WindowVariablesStub(),
|
||||
[propertyKey]: invalidValue,
|
||||
};
|
||||
const context = new ValidateWindowVariablesTestSetup()
|
||||
.withWindowVariables(input);
|
||||
// act
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { validateRuntimeSanity } from '@/infrastructure/RuntimeSanity/SanityChecks';
|
||||
import type { ISanityCheckOptions } from '@/infrastructure/RuntimeSanity/Common/ISanityCheckOptions';
|
||||
import type { SanityCheckOptions } from '@/infrastructure/RuntimeSanity/Common/SanityCheckOptions';
|
||||
import { SanityCheckOptionsStub } from '@tests/unit/shared/Stubs/SanityCheckOptionsStub';
|
||||
import type { ISanityValidator } from '@/infrastructure/RuntimeSanity/Common/ISanityValidator';
|
||||
import type { SanityValidator } from '@/infrastructure/RuntimeSanity/Common/SanityValidator';
|
||||
import { SanityValidatorStub } from '@tests/unit/shared/Stubs/SanityValidatorStub';
|
||||
import { itEachAbsentCollectionValue } from '@tests/unit/shared/TestCases/AbsentTests';
|
||||
import { collectExceptionMessage } from '@tests/unit/shared/ExceptionCollector';
|
||||
@@ -11,7 +11,7 @@ describe('SanityChecks', () => {
|
||||
describe('validateRuntimeSanity', () => {
|
||||
describe('parameter validation', () => {
|
||||
describe('throws when validators are empty', () => {
|
||||
itEachAbsentCollectionValue<ISanityValidator>((absentCollection) => {
|
||||
itEachAbsentCollectionValue<SanityValidator>((absentCollection) => {
|
||||
// arrange
|
||||
const expectedError = 'missing validators';
|
||||
const validators = absentCollection;
|
||||
@@ -138,9 +138,9 @@ describe('SanityChecks', () => {
|
||||
});
|
||||
|
||||
class TestContext {
|
||||
private options: ISanityCheckOptions = new SanityCheckOptionsStub();
|
||||
private options: SanityCheckOptions = new SanityCheckOptionsStub();
|
||||
|
||||
private validators: ISanityValidator[] = [new SanityValidatorStub()];
|
||||
private validators: SanityValidator[] = [new SanityValidatorStub()];
|
||||
|
||||
public withOptionsSetup(
|
||||
setup: (stub: SanityCheckOptionsStub) => SanityCheckOptionsStub,
|
||||
@@ -148,12 +148,12 @@ class TestContext {
|
||||
return this.withOptions(setup(new SanityCheckOptionsStub()));
|
||||
}
|
||||
|
||||
public withOptions(options: ISanityCheckOptions): this {
|
||||
public withOptions(options: SanityCheckOptions): this {
|
||||
this.options = options;
|
||||
return this;
|
||||
}
|
||||
|
||||
public withValidators(validators: ISanityValidator[]): this {
|
||||
public withValidators(validators: SanityValidator[]): this {
|
||||
this.validators = validators;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
import type { PropertyKeys } from '@/TypeHelpers';
|
||||
import type { FactoryFunction, FactoryValidator } from '@/infrastructure/RuntimeSanity/Common/FactoryValidator';
|
||||
import type { ISanityCheckOptions } from '@/infrastructure/RuntimeSanity/Common/ISanityCheckOptions';
|
||||
import type { SanityCheckOptions } from '@/infrastructure/RuntimeSanity/Common/SanityCheckOptions';
|
||||
import { SanityCheckOptionsStub } from '@tests/unit/shared/Stubs/SanityCheckOptionsStub';
|
||||
|
||||
interface ITestOptions<T> {
|
||||
createValidator: (factory?: FactoryFunction<T>) => FactoryValidator<T>;
|
||||
enablingOptionProperty: PropertyKeys<ISanityCheckOptions>;
|
||||
factoryFunctionStub: FactoryFunction<T>;
|
||||
expectedValidatorName: string;
|
||||
interface TestOptions<T> {
|
||||
readonly createValidator: (factory?: FactoryFunction<T>) => FactoryValidator<T>;
|
||||
readonly enablingOptionProperty: PropertyKeys<SanityCheckOptions>;
|
||||
readonly factoryFunctionStub: FactoryFunction<T>;
|
||||
readonly expectedValidatorName: string;
|
||||
}
|
||||
|
||||
export function runFactoryValidatorTests<T>(
|
||||
testOptions: ITestOptions<T>,
|
||||
testOptions: TestOptions<T>,
|
||||
) {
|
||||
describe('shouldValidate', () => {
|
||||
it('returns true when option is true', () => {
|
||||
// arrange
|
||||
const expectedValue = true;
|
||||
const options: ISanityCheckOptions = {
|
||||
const options: SanityCheckOptions = {
|
||||
...new SanityCheckOptionsStub(),
|
||||
[testOptions.enablingOptionProperty]: true,
|
||||
};
|
||||
@@ -31,7 +31,7 @@ export function runFactoryValidatorTests<T>(
|
||||
it('returns false when option is false', () => {
|
||||
// arrange
|
||||
const expectedValue = false;
|
||||
const options: ISanityCheckOptions = {
|
||||
const options: SanityCheckOptions = {
|
||||
...new SanityCheckOptionsStub(),
|
||||
[testOptions.enablingOptionProperty]: false,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user