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",
|
||||
"typescript": "^5.3.3",
|
||||
"vite": "^5.1.6",
|
||||
"vitest": "^0.34.6",
|
||||
"vitest": "^1.3.1",
|
||||
"vue-tsc": "^1.8.19",
|
||||
"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 { FunctionCallArgumentStub } from '@tests/unit/shared/Stubs/FunctionCallArgumentStub';
|
||||
import { itEachAbsentStringValue } from '@tests/unit/shared/TestCases/AbsentTests';
|
||||
import type { IFunctionCallArgument } from '@/application/Parser/Script/Compiler/Function/Call/Argument/IFunctionCallArgument';
|
||||
|
||||
describe('FunctionCallArgumentCollection', () => {
|
||||
describe('addArgument', () => {
|
||||
@@ -20,21 +21,25 @@ describe('FunctionCallArgumentCollection', () => {
|
||||
});
|
||||
});
|
||||
describe('getAllParameterNames', () => {
|
||||
it('returns as expected', () => {
|
||||
describe('returns as expected', () => {
|
||||
// arrange
|
||||
const testCases = [{
|
||||
name: 'no args',
|
||||
const testCases: ReadonlyArray<{
|
||||
readonly description: string;
|
||||
readonly args: readonly IFunctionCallArgument[];
|
||||
readonly expectedParameterNames: string[];
|
||||
}> = [{
|
||||
description: 'no args',
|
||||
args: [],
|
||||
expected: [],
|
||||
expectedParameterNames: [],
|
||||
}, {
|
||||
name: 'with some args',
|
||||
description: 'with some args',
|
||||
args: [
|
||||
new FunctionCallArgumentStub().withParameterName('a-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) {
|
||||
it(testCase.name, () => {
|
||||
it(testCase.description, () => {
|
||||
const sut = new FunctionCallArgumentCollection();
|
||||
// act
|
||||
for (const arg of testCase.args) {
|
||||
@@ -42,7 +47,7 @@ describe('FunctionCallArgumentCollection', () => {
|
||||
}
|
||||
const actual = sut.getAllParameterNames();
|
||||
// assert
|
||||
expect(actual).to.equal(testCase.expected);
|
||||
expect(actual).to.deep.equal(testCase.expectedParameterNames);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -25,7 +25,7 @@ describe('SharedFunction', () => {
|
||||
// assert
|
||||
expect(sut.name).equal(expected);
|
||||
});
|
||||
it('throws when absent', () => {
|
||||
describe('throws when absent', () => {
|
||||
itEachAbsentStringValue((absentValue) => {
|
||||
// arrange
|
||||
const expectedError = 'missing function name';
|
||||
|
||||
@@ -4,6 +4,7 @@ import { InjectionKeys } from '@/presentation/injectionSymbols';
|
||||
import { provideDependencies, type VueDependencyInjectionApi } from '@/presentation/bootstrapping/DependencyProvider';
|
||||
import { ApplicationContextStub } from '@tests/unit/shared/Stubs/ApplicationContextStub';
|
||||
import { itIsSingleton } from '@tests/unit/shared/TestCases/SingletonTests';
|
||||
import type { IApplicationContext } from '@/application/Context/IApplicationContext';
|
||||
|
||||
describe('DependencyProvider', () => {
|
||||
describe('provideDependencies', () => {
|
||||
@@ -74,25 +75,25 @@ function createSingletonTests() {
|
||||
const registeredObject = api.inject(injectionKey);
|
||||
expect(registeredObject).to.be.instanceOf(Object);
|
||||
});
|
||||
it('should return the same instance for singleton dependency', () => {
|
||||
itIsSingleton({
|
||||
getter: () => {
|
||||
describe('should return the same instance for singleton dependency', () => {
|
||||
// arrange
|
||||
const singletonContext = new ApplicationContextStub();
|
||||
const api = new VueDependencyInjectionApiStub();
|
||||
// act
|
||||
new ProvideDependenciesBuilder()
|
||||
.withContext(singletonContext)
|
||||
.withApi(api)
|
||||
.provideDependencies();
|
||||
// expect
|
||||
const registeredObject = api.inject(injectionKey);
|
||||
return registeredObject;
|
||||
},
|
||||
// act
|
||||
const getRegisteredInstance = () => api.inject(injectionKey);
|
||||
// assert
|
||||
itIsSingleton({
|
||||
getter: getRegisteredInstance,
|
||||
});
|
||||
});
|
||||
};
|
||||
}
|
||||
class ProvideDependenciesBuilder {
|
||||
private context = new ApplicationContextStub();
|
||||
private context: IApplicationContext = new ApplicationContextStub();
|
||||
|
||||
private api: VueDependencyInjectionApi = new VueDependencyInjectionApiStub();
|
||||
|
||||
@@ -101,6 +102,11 @@ class ProvideDependenciesBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public withContext(context: IApplicationContext): this {
|
||||
this.context = context;
|
||||
return this;
|
||||
}
|
||||
|
||||
public provideDependencies() {
|
||||
return provideDependencies(this.context, this.api);
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import type { TreeInputNodeData } from '@/presentation/components/Scripts/View/T
|
||||
|
||||
describe('TreeNodeInitializerAndUpdater', () => {
|
||||
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) => {
|
||||
// arrange
|
||||
const expectedError = 'missing data';
|
||||
|
||||
@@ -13,7 +13,7 @@ import { ScriptDiagnosticsCollectorStub } from '../../../shared/Stubs/ScriptDiag
|
||||
|
||||
describe('IpcRegistration', () => {
|
||||
describe('registerAllIpcChannels', () => {
|
||||
it('registers all defined IPC channels', () => {
|
||||
describe('registers all defined IPC channels', () => {
|
||||
Object.entries(IpcChannelDefinitions).forEach(([key, expectedChannel]) => {
|
||||
it(key, () => {
|
||||
// arrange
|
||||
|
||||
Reference in New Issue
Block a user