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:
@@ -25,9 +25,10 @@ describe('PlatformTimer', () => {
|
||||
describe('setTimeout', () => {
|
||||
it('calls the global setTimeout with the provided delay', () => {
|
||||
// arrange
|
||||
type Delay = Parameters<typeof setTimeout>[1];
|
||||
const expectedDelay = 55;
|
||||
let actualDelay: number | undefined;
|
||||
global.setTimeout = ((_, delay) => {
|
||||
let actualDelay: Delay | undefined;
|
||||
global.setTimeout = ((_: never, delay: Delay) => {
|
||||
actualDelay = delay;
|
||||
}) as typeof global.setTimeout;
|
||||
// act
|
||||
@@ -37,9 +38,10 @@ describe('PlatformTimer', () => {
|
||||
});
|
||||
it('calls the global setTimeout with the provided callback', () => {
|
||||
// arrange
|
||||
type Callback = Parameters<typeof setTimeout>[0];
|
||||
const expectedCallback = () => { /* NOOP */ };
|
||||
let actualCallback: typeof expectedCallback | undefined;
|
||||
global.setTimeout = ((callback) => {
|
||||
let actualCallback: Callback | undefined;
|
||||
global.setTimeout = ((callback: Callback) => {
|
||||
actualCallback = callback;
|
||||
}) as typeof global.setTimeout;
|
||||
// act
|
||||
@@ -52,8 +54,9 @@ describe('PlatformTimer', () => {
|
||||
describe('clearTimeout', () => {
|
||||
it('should clear timeout', () => {
|
||||
// arrange
|
||||
let actualTimer: ReturnType<typeof PlatformTimer.setTimeout> | undefined;
|
||||
global.clearTimeout = ((timer) => {
|
||||
type Timer = ReturnType<typeof PlatformTimer.setTimeout>;
|
||||
let actualTimer: Timer | undefined;
|
||||
global.clearTimeout = ((timer: Timer) => {
|
||||
actualTimer = timer;
|
||||
}) as typeof global.clearTimeout;
|
||||
const expectedTimer = PlatformTimer.setTimeout(() => { /* NOOP */ }, 1);
|
||||
|
||||
@@ -50,16 +50,33 @@ describe('ApplicationContext', () => {
|
||||
// assert
|
||||
expectEmptyState(sut.state);
|
||||
});
|
||||
it('throws when OS is unknown to application', () => {
|
||||
it('rethrows when application cannot provide collection for supported OS', () => {
|
||||
// arrange
|
||||
const expectedError = 'expected error from application';
|
||||
const applicationStub = new ApplicationStub();
|
||||
const initialOs = OperatingSystem.Android;
|
||||
const targetOs = OperatingSystem.ChromeOS;
|
||||
const context = new ObservableApplicationContextFactory()
|
||||
.withAppContainingCollections(initialOs, targetOs)
|
||||
.withInitialOs(initialOs);
|
||||
// act
|
||||
const sut = context.construct();
|
||||
const { app } = context;
|
||||
app.getCollection = () => { throw new Error(expectedError); };
|
||||
const act = () => sut.changeContext(targetOs);
|
||||
// assert
|
||||
expect(act).to.throw(expectedError);
|
||||
});
|
||||
it('throws when OS state is unknown to application', () => {
|
||||
// arrange
|
||||
const knownOs = OperatingSystem.Android;
|
||||
const unknownOs = OperatingSystem.ChromeOS;
|
||||
const expectedError = `Operating system "${OperatingSystem[unknownOs]}" state is unknown.`;
|
||||
const sut = new ObservableApplicationContextFactory()
|
||||
.withApp(applicationStub)
|
||||
.withAppContainingCollections(knownOs)
|
||||
.withInitialOs(knownOs)
|
||||
.construct();
|
||||
// act
|
||||
applicationStub.getCollection = () => { throw new Error(expectedError); };
|
||||
const act = () => sut.changeContext(OperatingSystem.Android);
|
||||
const act = () => sut.changeContext(unknownOs);
|
||||
// assert
|
||||
expect(act).to.throw(expectedError);
|
||||
});
|
||||
@@ -181,14 +198,28 @@ describe('ApplicationContext', () => {
|
||||
const actual = sut.state.os;
|
||||
expect(actual).to.deep.equal(expected);
|
||||
});
|
||||
it('throws when OS is unknown to application', () => {
|
||||
it('rethrows when application cannot provide collection for supported OS', () => {
|
||||
// arrange
|
||||
const expectedError = 'expected error from application';
|
||||
const applicationStub = new ApplicationStub();
|
||||
applicationStub.getCollection = () => { throw new Error(expectedError); };
|
||||
const knownOperatingSystem = OperatingSystem.macOS;
|
||||
const context = new ObservableApplicationContextFactory()
|
||||
.withAppContainingCollections(knownOperatingSystem)
|
||||
.withInitialOs(knownOperatingSystem);
|
||||
const { app } = context;
|
||||
app.getCollection = () => { throw new Error(expectedError); };
|
||||
// act
|
||||
const act = () => context.construct();
|
||||
// assert
|
||||
expect(act).to.throw(expectedError);
|
||||
});
|
||||
it('throws when OS is not supported', () => {
|
||||
// arrange
|
||||
const unknownInitialOperatingSystem = OperatingSystem.BlackBerry10;
|
||||
const expectedError = `Operating system "${OperatingSystem[unknownInitialOperatingSystem]}" is not supported.`;
|
||||
// act
|
||||
const act = () => new ObservableApplicationContextFactory()
|
||||
.withApp(applicationStub)
|
||||
.withAppContainingCollections(OperatingSystem.Android /* unrelated */)
|
||||
.withInitialOs(unknownInitialOperatingSystem)
|
||||
.construct();
|
||||
// assert
|
||||
expect(act).to.throw(expectedError);
|
||||
@@ -222,24 +253,24 @@ class ObservableApplicationContextFactory {
|
||||
|
||||
private initialOs = ObservableApplicationContextFactory.DefaultOs;
|
||||
|
||||
constructor() {
|
||||
public constructor() {
|
||||
this.withAppContainingCollections(ObservableApplicationContextFactory.DefaultOs);
|
||||
}
|
||||
|
||||
public withAppContainingCollections(
|
||||
...oses: OperatingSystem[]
|
||||
): ObservableApplicationContextFactory {
|
||||
): this {
|
||||
const collectionValues = oses.map((os) => new CategoryCollectionStub().withOs(os));
|
||||
const app = new ApplicationStub().withCollections(...collectionValues);
|
||||
return this.withApp(app);
|
||||
}
|
||||
|
||||
public withApp(app: IApplication): ObservableApplicationContextFactory {
|
||||
public withApp(app: IApplication): this {
|
||||
this.app = app;
|
||||
return this;
|
||||
}
|
||||
|
||||
public withInitialOs(initialOs: OperatingSystem) {
|
||||
public withInitialOs(initialOs: OperatingSystem): this {
|
||||
this.initialOs = initialOs;
|
||||
return this;
|
||||
}
|
||||
@@ -250,6 +281,7 @@ class ObservableApplicationContextFactory {
|
||||
return sut;
|
||||
}
|
||||
}
|
||||
|
||||
function getDuplicates<T>(list: readonly T[]): T[] {
|
||||
return list.filter((item, index) => list.indexOf(item) !== index);
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ describe('CategoryCollectionState', () => {
|
||||
describe('selection', () => {
|
||||
it('initializes with empty scripts', () => {
|
||||
// arrange
|
||||
const expectedScripts = [];
|
||||
const expectedScripts: readonly SelectedScript[] = [];
|
||||
let actualScripts: readonly SelectedScript[] | undefined;
|
||||
const selectionFactoryMock: SelectionFactory = (_, scripts) => {
|
||||
actualScripts = scripts;
|
||||
|
||||
@@ -16,7 +16,7 @@ describe('ApplicationCode', () => {
|
||||
describe('ctor', () => {
|
||||
it('empty when selection is empty', () => {
|
||||
// arrange
|
||||
const selectedScripts = [];
|
||||
const selectedScripts: readonly SelectedScript[] = [];
|
||||
const selection = new ScriptSelectionStub()
|
||||
.withSelectedScripts(selectedScripts);
|
||||
const definition = new ScriptingDefinitionStub();
|
||||
|
||||
@@ -7,6 +7,7 @@ import { ScriptingDefinitionStub } from '@tests/unit/shared/Stubs/ScriptingDefin
|
||||
import { itEachAbsentStringValue } from '@tests/unit/shared/TestCases/AbsentTests';
|
||||
import { expectExists } from '@tests/shared/Assertions/ExpectExists';
|
||||
import { SelectedScriptStub } from '@tests/unit/shared/Stubs/SelectedScriptStub';
|
||||
import type { SelectedScript } from '@/application/Context/State/Selection/Script/SelectedScript';
|
||||
|
||||
describe('UserScriptGenerator', () => {
|
||||
describe('scriptingDefinition', () => {
|
||||
@@ -143,7 +144,7 @@ describe('UserScriptGenerator', () => {
|
||||
it('without script; returns empty', () => {
|
||||
// arrange
|
||||
const sut = new UserScriptGenerator();
|
||||
const selectedScripts = [];
|
||||
const selectedScripts: readonly SelectedScript[] = [];
|
||||
const definition = new ScriptingDefinitionStub();
|
||||
// act
|
||||
const actual = sut.buildCode(selectedScripts, definition);
|
||||
|
||||
@@ -279,7 +279,7 @@ describe('DebouncedScriptSelection', () => {
|
||||
it('throws error when an empty script array is passed', () => {
|
||||
// arrange
|
||||
const expectedError = 'Provided script array is empty. To deselect all scripts, please use the deselectAll() method instead.';
|
||||
const scripts = [];
|
||||
const scripts: readonly Script[] = [];
|
||||
const scriptSelection = new DebouncedScriptSelectionBuilder().build();
|
||||
// act
|
||||
const act = () => scriptSelection.selectOnly(scripts);
|
||||
|
||||
@@ -135,7 +135,7 @@ describe('createTypeValidator', () => {
|
||||
});
|
||||
it('throws error for empty collection', () => {
|
||||
// arrange
|
||||
const emptyArrayValue = [];
|
||||
const emptyArrayValue: unknown[] = [];
|
||||
const valueName = 'empty collection value';
|
||||
const expectedMessage = `'${valueName}' cannot be an empty array.`;
|
||||
const { assertNonEmptyCollection } = createTypeValidator();
|
||||
@@ -251,7 +251,7 @@ describe('createTypeValidator', () => {
|
||||
});
|
||||
|
||||
function createObjectWithProperties(properties: readonly string[]): object {
|
||||
const object = {};
|
||||
const object: Record<string, unknown> = {};
|
||||
properties.forEach((propertyName) => {
|
||||
object[propertyName] = 'arbitrary value';
|
||||
});
|
||||
|
||||
@@ -383,7 +383,7 @@ function createExpressionFactorySpy() {
|
||||
};
|
||||
return {
|
||||
createExpression,
|
||||
getInitParameters: (expression) => createdExpressions.get(expression),
|
||||
getInitParameters: (expression: IExpression) => createdExpressions.get(expression),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import { describe, it, expect } from 'vitest';
|
||||
import { PipeFactory } from '@/application/Parser/Executable/Script/Compiler/Expressions/Pipes/PipeFactory';
|
||||
import { PipeStub } from '@tests/unit/shared/Stubs/PipeStub';
|
||||
import { getAbsentStringTestCases } from '@tests/unit/shared/TestCases/AbsentTests';
|
||||
import type { Pipe } from '@/application/Parser/Executable/Script/Compiler/Expressions/Pipes/Pipe';
|
||||
|
||||
describe('PipeFactory', () => {
|
||||
describe('ctor', () => {
|
||||
@@ -49,7 +50,7 @@ describe('PipeFactory', () => {
|
||||
// arrange
|
||||
const missingName = 'missingName';
|
||||
const expectedError = `Unknown pipe: "${missingName}"`;
|
||||
const pipes = [];
|
||||
const pipes: readonly Pipe[] = [];
|
||||
const sut = new PipeFactory(pipes);
|
||||
// act
|
||||
const act = () => sut.get(missingName);
|
||||
|
||||
@@ -9,20 +9,20 @@ import { getAbsentStringTestCases } from '@tests/unit/shared/TestCases/AbsentTes
|
||||
describe('PipelineCompiler', () => {
|
||||
describe('compile', () => {
|
||||
describe('throws for invalid arguments', () => {
|
||||
interface ITestCase {
|
||||
interface ThrowingPipeScenario {
|
||||
readonly name: string;
|
||||
readonly act: (test: PipelineTestRunner) => PipelineTestRunner;
|
||||
readonly expectedError: string;
|
||||
}
|
||||
const testCases: ITestCase[] = [
|
||||
const testScenarios: ThrowingPipeScenario[] = [
|
||||
...getAbsentStringTestCases({ excludeNull: true, excludeUndefined: true })
|
||||
.map((testCase) => ({
|
||||
.map((testCase): ThrowingPipeScenario => ({
|
||||
name: `"value" is ${testCase.valueName}`,
|
||||
act: (test) => test.withValue(testCase.absentValue),
|
||||
expectedError: 'missing value',
|
||||
})),
|
||||
...getAbsentStringTestCases({ excludeNull: true, excludeUndefined: true })
|
||||
.map((testCase) => ({
|
||||
.map((testCase): ThrowingPipeScenario => ({
|
||||
name: `"pipeline" is ${testCase.valueName}`,
|
||||
act: (test) => test.withPipeline(testCase.absentValue),
|
||||
expectedError: 'missing pipeline',
|
||||
@@ -33,7 +33,7 @@ describe('PipelineCompiler', () => {
|
||||
expectedError: 'pipeline does not start with pipe',
|
||||
},
|
||||
];
|
||||
for (const testCase of testCases) {
|
||||
for (const testCase of testScenarios) {
|
||||
it(testCase.name, () => {
|
||||
// act
|
||||
const runner = new PipelineTestRunner();
|
||||
|
||||
@@ -114,7 +114,7 @@ export class SyntaxParserTestsRunner {
|
||||
}
|
||||
}
|
||||
|
||||
interface ExpectResultTestScenario {
|
||||
export interface ExpectResultTestScenario {
|
||||
readonly name: string;
|
||||
readonly code: string;
|
||||
readonly args: (
|
||||
|
||||
@@ -2,7 +2,7 @@ import { describe } from 'vitest';
|
||||
import { ExpressionPosition } from '@/application/Parser/Executable/Script/Compiler/Expressions/Expression/ExpressionPosition';
|
||||
import { WithParser } from '@/application/Parser/Executable/Script/Compiler/Expressions/SyntaxParsers/WithParser';
|
||||
import { getAbsentStringTestCases } from '@tests/unit/shared/TestCases/AbsentTests';
|
||||
import { SyntaxParserTestsRunner } from './SyntaxParserTestsRunner';
|
||||
import { SyntaxParserTestsRunner, type ExpectResultTestScenario } from './SyntaxParserTestsRunner';
|
||||
|
||||
describe('WithParser', () => {
|
||||
const sut = new WithParser();
|
||||
@@ -120,7 +120,7 @@ describe('WithParser', () => {
|
||||
describe('does not render scope', () => {
|
||||
runner.expectResults(
|
||||
...getAbsentStringTestCases({ excludeNull: true, excludeUndefined: true })
|
||||
.map((testCase) => ({
|
||||
.map((testCase): ExpectResultTestScenario => ({
|
||||
name: `does not render when value is "${testCase.valueName}"`,
|
||||
code: '{{ with $parameter }}dark{{ end }} ',
|
||||
args: (args) => args
|
||||
@@ -138,7 +138,7 @@ describe('WithParser', () => {
|
||||
describe('renders scope', () => {
|
||||
runner.expectResults(
|
||||
...getAbsentStringTestCases({ excludeNull: true, excludeUndefined: true })
|
||||
.map((testCase) => ({
|
||||
.map((testCase): ExpectResultTestScenario => ({
|
||||
name: `does not render when value is "${testCase.valueName}"`,
|
||||
code: '{{ with $parameter }}dark{{ end }} ',
|
||||
args: (args) => args
|
||||
|
||||
@@ -165,11 +165,14 @@ function createScriptLanguageScenarios(): readonly ScriptLanguageScenario[] {
|
||||
[ScriptingLanguage.batchfile]: 8191,
|
||||
[ScriptingLanguage.shellscript]: 1048576,
|
||||
};
|
||||
return Object.entries(maxLengths).map(([language, length]): ScriptLanguageScenario => ({
|
||||
description: `${ScriptingLanguage[language]} (max: ${length})`,
|
||||
language: Number.parseInt(language, 10) as ScriptingLanguage,
|
||||
maxLength: length,
|
||||
}));
|
||||
return Object.entries(maxLengths).map(([language, length]): ScriptLanguageScenario => {
|
||||
const languageValue = Number.parseInt(language, 10) as ScriptingLanguage;
|
||||
return {
|
||||
description: `${ScriptingLanguage[languageValue]} (max: ${length})`,
|
||||
language: languageValue,
|
||||
maxLength: length,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
class TestContext {
|
||||
|
||||
Reference in New Issue
Block a user