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:
undergroundwires
2024-03-15 08:33:59 +01:00
parent adc2089887
commit e7218850ba
7 changed files with 485 additions and 265 deletions

View File

@@ -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', () => {
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({
getter: () => {
// arrange
const api = new VueDependencyInjectionApiStub();
// act
new ProvideDependenciesBuilder()
.withApi(api)
.provideDependencies();
// expect
const registeredObject = api.inject(injectionKey);
return registeredObject;
},
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);
}

View File

@@ -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';

View File

@@ -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