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

@@ -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);
});
}
});

View File

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