Upgrade vitest to v1 and fix test definitions
This commit upgrades the `vitest` library to its first major version (v1) resolving issues with previously unexecuted tests due to improperly nested `it` blocks. The migration to v1 uncovered error messages indicating the misuse of `it` blocks, as described in vitest-dev/vitest#4229 and vitest-dev/vitest#4262, prompting a restructuring of test cases for proper execution. Additionally, this commit adjusts singleton test definitions in `DependencyProvider.spec.ts` to better reflect real usage scenarios and correctly implement singleton pattern tests, enhancing test reliability. Changes: - Upgrade `vitest` from v0 to v1. - Correct test definitions by organizing `it` blocks within `describe` blocks. - Fix singleton test definition in `DependencyProvider.spec.ts`.
This commit is contained in:
689
package-lock.json
generated
689
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -82,7 +82,7 @@
|
|||||||
"tslib": "^2.6.2",
|
"tslib": "^2.6.2",
|
||||||
"typescript": "^5.3.3",
|
"typescript": "^5.3.3",
|
||||||
"vite": "^5.1.6",
|
"vite": "^5.1.6",
|
||||||
"vitest": "^0.34.6",
|
"vitest": "^1.3.1",
|
||||||
"vue-tsc": "^1.8.19",
|
"vue-tsc": "^1.8.19",
|
||||||
"yaml-lint": "^1.7.0"
|
"yaml-lint": "^1.7.0"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { describe, it, expect } from 'vitest';
|
|||||||
import { FunctionCallArgumentCollection } from '@/application/Parser/Script/Compiler/Function/Call/Argument/FunctionCallArgumentCollection';
|
import { FunctionCallArgumentCollection } from '@/application/Parser/Script/Compiler/Function/Call/Argument/FunctionCallArgumentCollection';
|
||||||
import { FunctionCallArgumentStub } from '@tests/unit/shared/Stubs/FunctionCallArgumentStub';
|
import { FunctionCallArgumentStub } from '@tests/unit/shared/Stubs/FunctionCallArgumentStub';
|
||||||
import { itEachAbsentStringValue } from '@tests/unit/shared/TestCases/AbsentTests';
|
import { itEachAbsentStringValue } from '@tests/unit/shared/TestCases/AbsentTests';
|
||||||
|
import type { IFunctionCallArgument } from '@/application/Parser/Script/Compiler/Function/Call/Argument/IFunctionCallArgument';
|
||||||
|
|
||||||
describe('FunctionCallArgumentCollection', () => {
|
describe('FunctionCallArgumentCollection', () => {
|
||||||
describe('addArgument', () => {
|
describe('addArgument', () => {
|
||||||
@@ -20,21 +21,25 @@ describe('FunctionCallArgumentCollection', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('getAllParameterNames', () => {
|
describe('getAllParameterNames', () => {
|
||||||
it('returns as expected', () => {
|
describe('returns as expected', () => {
|
||||||
// arrange
|
// arrange
|
||||||
const testCases = [{
|
const testCases: ReadonlyArray<{
|
||||||
name: 'no args',
|
readonly description: string;
|
||||||
|
readonly args: readonly IFunctionCallArgument[];
|
||||||
|
readonly expectedParameterNames: string[];
|
||||||
|
}> = [{
|
||||||
|
description: 'no args',
|
||||||
args: [],
|
args: [],
|
||||||
expected: [],
|
expectedParameterNames: [],
|
||||||
}, {
|
}, {
|
||||||
name: 'with some args',
|
description: 'with some args',
|
||||||
args: [
|
args: [
|
||||||
new FunctionCallArgumentStub().withParameterName('a-param-name'),
|
new FunctionCallArgumentStub().withParameterName('a-param-name'),
|
||||||
new FunctionCallArgumentStub().withParameterName('b-param-name')],
|
new FunctionCallArgumentStub().withParameterName('b-param-name')],
|
||||||
expected: ['a-param-name', 'b-param-name'],
|
expectedParameterNames: ['a-param-name', 'b-param-name'],
|
||||||
}];
|
}];
|
||||||
for (const testCase of testCases) {
|
for (const testCase of testCases) {
|
||||||
it(testCase.name, () => {
|
it(testCase.description, () => {
|
||||||
const sut = new FunctionCallArgumentCollection();
|
const sut = new FunctionCallArgumentCollection();
|
||||||
// act
|
// act
|
||||||
for (const arg of testCase.args) {
|
for (const arg of testCase.args) {
|
||||||
@@ -42,7 +47,7 @@ describe('FunctionCallArgumentCollection', () => {
|
|||||||
}
|
}
|
||||||
const actual = sut.getAllParameterNames();
|
const actual = sut.getAllParameterNames();
|
||||||
// assert
|
// assert
|
||||||
expect(actual).to.equal(testCase.expected);
|
expect(actual).to.deep.equal(testCase.expectedParameterNames);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ describe('SharedFunction', () => {
|
|||||||
// assert
|
// assert
|
||||||
expect(sut.name).equal(expected);
|
expect(sut.name).equal(expected);
|
||||||
});
|
});
|
||||||
it('throws when absent', () => {
|
describe('throws when absent', () => {
|
||||||
itEachAbsentStringValue((absentValue) => {
|
itEachAbsentStringValue((absentValue) => {
|
||||||
// arrange
|
// arrange
|
||||||
const expectedError = 'missing function name';
|
const expectedError = 'missing function name';
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { InjectionKeys } from '@/presentation/injectionSymbols';
|
|||||||
import { provideDependencies, type VueDependencyInjectionApi } from '@/presentation/bootstrapping/DependencyProvider';
|
import { provideDependencies, type VueDependencyInjectionApi } from '@/presentation/bootstrapping/DependencyProvider';
|
||||||
import { ApplicationContextStub } from '@tests/unit/shared/Stubs/ApplicationContextStub';
|
import { ApplicationContextStub } from '@tests/unit/shared/Stubs/ApplicationContextStub';
|
||||||
import { itIsSingleton } from '@tests/unit/shared/TestCases/SingletonTests';
|
import { itIsSingleton } from '@tests/unit/shared/TestCases/SingletonTests';
|
||||||
|
import type { IApplicationContext } from '@/application/Context/IApplicationContext';
|
||||||
|
|
||||||
describe('DependencyProvider', () => {
|
describe('DependencyProvider', () => {
|
||||||
describe('provideDependencies', () => {
|
describe('provideDependencies', () => {
|
||||||
@@ -74,25 +75,25 @@ function createSingletonTests() {
|
|||||||
const registeredObject = api.inject(injectionKey);
|
const registeredObject = api.inject(injectionKey);
|
||||||
expect(registeredObject).to.be.instanceOf(Object);
|
expect(registeredObject).to.be.instanceOf(Object);
|
||||||
});
|
});
|
||||||
it('should return the same instance for singleton dependency', () => {
|
describe('should return the same instance for singleton dependency', () => {
|
||||||
|
// arrange
|
||||||
|
const singletonContext = new ApplicationContextStub();
|
||||||
|
const api = new VueDependencyInjectionApiStub();
|
||||||
|
new ProvideDependenciesBuilder()
|
||||||
|
.withContext(singletonContext)
|
||||||
|
.withApi(api)
|
||||||
|
.provideDependencies();
|
||||||
|
// act
|
||||||
|
const getRegisteredInstance = () => api.inject(injectionKey);
|
||||||
|
// assert
|
||||||
itIsSingleton({
|
itIsSingleton({
|
||||||
getter: () => {
|
getter: getRegisteredInstance,
|
||||||
// arrange
|
|
||||||
const api = new VueDependencyInjectionApiStub();
|
|
||||||
// act
|
|
||||||
new ProvideDependenciesBuilder()
|
|
||||||
.withApi(api)
|
|
||||||
.provideDependencies();
|
|
||||||
// expect
|
|
||||||
const registeredObject = api.inject(injectionKey);
|
|
||||||
return registeredObject;
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
class ProvideDependenciesBuilder {
|
class ProvideDependenciesBuilder {
|
||||||
private context = new ApplicationContextStub();
|
private context: IApplicationContext = new ApplicationContextStub();
|
||||||
|
|
||||||
private api: VueDependencyInjectionApi = new VueDependencyInjectionApiStub();
|
private api: VueDependencyInjectionApi = new VueDependencyInjectionApiStub();
|
||||||
|
|
||||||
@@ -101,6 +102,11 @@ class ProvideDependenciesBuilder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public withContext(context: IApplicationContext): this {
|
||||||
|
this.context = context;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public provideDependencies() {
|
public provideDependencies() {
|
||||||
return provideDependencies(this.context, this.api);
|
return provideDependencies(this.context, this.api);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import type { TreeInputNodeData } from '@/presentation/components/Scripts/View/T
|
|||||||
|
|
||||||
describe('TreeNodeInitializerAndUpdater', () => {
|
describe('TreeNodeInitializerAndUpdater', () => {
|
||||||
describe('updateRootNodes', () => {
|
describe('updateRootNodes', () => {
|
||||||
it('should throw an error if no data is provided', () => {
|
describe('should throw an error if no data is provided', () => {
|
||||||
itEachAbsentCollectionValue<TreeInputNodeData>((absentValue) => {
|
itEachAbsentCollectionValue<TreeInputNodeData>((absentValue) => {
|
||||||
// arrange
|
// arrange
|
||||||
const expectedError = 'missing data';
|
const expectedError = 'missing data';
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import { ScriptDiagnosticsCollectorStub } from '../../../shared/Stubs/ScriptDiag
|
|||||||
|
|
||||||
describe('IpcRegistration', () => {
|
describe('IpcRegistration', () => {
|
||||||
describe('registerAllIpcChannels', () => {
|
describe('registerAllIpcChannels', () => {
|
||||||
it('registers all defined IPC channels', () => {
|
describe('registers all defined IPC channels', () => {
|
||||||
Object.entries(IpcChannelDefinitions).forEach(([key, expectedChannel]) => {
|
Object.entries(IpcChannelDefinitions).forEach(([key, expectedChannel]) => {
|
||||||
it(key, () => {
|
it(key, () => {
|
||||||
// arrange
|
// arrange
|
||||||
|
|||||||
Reference in New Issue
Block a user