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.
64 lines
1.7 KiB
TypeScript
64 lines
1.7 KiB
TypeScript
import { describe } from 'vitest';
|
|
import type { SanityCheckOptions } from '@/infrastructure/RuntimeSanity/Common/SanityCheckOptions';
|
|
import { validateRuntimeSanity } from '@/infrastructure/RuntimeSanity/SanityChecks';
|
|
import { isBoolean } from '@/TypeHelpers';
|
|
|
|
describe('SanityChecks', () => {
|
|
describe('validateRuntimeSanity', () => {
|
|
describe('does not throw on current environment', () => {
|
|
// arrange
|
|
const testOptions = generateTestOptions();
|
|
testOptions.forEach((options) => {
|
|
it(`options: ${JSON.stringify(options)}`, () => {
|
|
// act
|
|
const act = () => validateRuntimeSanity(options);
|
|
|
|
// assert
|
|
expect(act).to.not.throw();
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
function generateTestOptions(): SanityCheckOptions[] {
|
|
const defaultOptions: SanityCheckOptions = {
|
|
validateEnvironmentVariables: true,
|
|
validateWindowVariables: true,
|
|
};
|
|
return generateBooleanPermutations(defaultOptions);
|
|
}
|
|
|
|
function generateBooleanPermutations<T>(object: T | undefined): T[] {
|
|
if (!object) {
|
|
return [];
|
|
}
|
|
|
|
const keys = Object.keys(object) as (keyof T)[];
|
|
|
|
if (keys.length === 0) {
|
|
return [object];
|
|
}
|
|
|
|
const currentKey = keys[0];
|
|
const currentValue = object[currentKey];
|
|
|
|
if (!isBoolean(currentValue)) {
|
|
return generateBooleanPermutations({
|
|
...object,
|
|
[currentKey]: currentValue,
|
|
});
|
|
}
|
|
|
|
const remainingKeys = Object.fromEntries(
|
|
keys.slice(1).map((key) => [key, object[key]]),
|
|
) as unknown as T | undefined;
|
|
|
|
const subPermutations = generateBooleanPermutations(remainingKeys);
|
|
|
|
return [
|
|
...subPermutations.map((p) => ({ ...p, [currentKey]: true })),
|
|
...subPermutations.map((p) => ({ ...p, [currentKey]: false })),
|
|
];
|
|
}
|