As part of transition to Vue 3.0 and Vite (#230), this commit facilitates the shift towards building rest of the application using Vite. By doing so, it eliminates reliance on outdated Electron building system that offered limited control, blocking desktop builds (#233). Changes include: - Introduce Vite with Vue 2.0 plugin for test execution. - Remove `mocha`, `chai` and other related dependencies. - Adjust test to Vitest syntax. - Revise and update `tests.md` to document the changes. - Add `@modyfi/vite-plugin-yaml` plugin to be able to use yaml file depended logic on test files, replacing previous webpack behavior. - Fix failing tests that are revealed by Vitest due to unhandled errors and lack of assertments. - Remove the test that depends on Vue CLI populating `process.env`. - Use `jsdom` for unit test environment, adding it to dependency to `package.json` as project now depends on it and it was not specified even though `package-lock.json` included it.
91 lines
3.5 KiB
TypeScript
91 lines
3.5 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { SharedFunctionCollection } from '@/application/Parser/Script/Compiler/Function/SharedFunctionCollection';
|
|
import { SharedFunctionStub } from '@tests/unit/shared/Stubs/SharedFunctionStub';
|
|
import { FunctionBodyType } from '@/application/Parser/Script/Compiler/Function/ISharedFunction';
|
|
import { FunctionCallStub } from '@tests/unit/shared/Stubs/FunctionCallStub';
|
|
import { itEachAbsentObjectValue, itEachAbsentStringValue } from '@tests/unit/shared/TestCases/AbsentTests';
|
|
|
|
describe('SharedFunctionCollection', () => {
|
|
describe('addFunction', () => {
|
|
describe('throws if function is missing', () => {
|
|
itEachAbsentObjectValue((absentValue) => {
|
|
// arrange
|
|
const expectedError = 'missing function';
|
|
const func = absentValue;
|
|
const sut = new SharedFunctionCollection();
|
|
// act
|
|
const act = () => sut.addFunction(func);
|
|
// assert
|
|
expect(act).to.throw(expectedError);
|
|
});
|
|
});
|
|
it('throws if function with same name already exists', () => {
|
|
// arrange
|
|
const functionName = 'duplicate-function';
|
|
const expectedError = `function with name ${functionName} already exists`;
|
|
const func = new SharedFunctionStub(FunctionBodyType.Code)
|
|
.withName('duplicate-function');
|
|
const sut = new SharedFunctionCollection();
|
|
sut.addFunction(func);
|
|
// act
|
|
const act = () => sut.addFunction(func);
|
|
// assert
|
|
expect(act).to.throw(expectedError);
|
|
});
|
|
});
|
|
describe('getFunctionByName', () => {
|
|
describe('throws if name is absent', () => {
|
|
itEachAbsentStringValue((absentValue) => {
|
|
// arrange
|
|
const expectedError = 'missing function name';
|
|
const sut = new SharedFunctionCollection();
|
|
// act
|
|
const act = () => sut.getFunctionByName(absentValue);
|
|
// assert
|
|
expect(act).to.throw(expectedError);
|
|
});
|
|
});
|
|
it('throws if function does not exist', () => {
|
|
// arrange
|
|
const name = 'unique-name';
|
|
const expectedError = `called function is not defined "${name}"`;
|
|
const func = new SharedFunctionStub(FunctionBodyType.Code)
|
|
.withName('unexpected-name');
|
|
const sut = new SharedFunctionCollection();
|
|
sut.addFunction(func);
|
|
// act
|
|
const act = () => sut.getFunctionByName(name);
|
|
// assert
|
|
expect(act).to.throw(expectedError);
|
|
});
|
|
describe('returns existing function', () => {
|
|
it('when function with inline code is added', () => {
|
|
// arrange
|
|
const expected = new SharedFunctionStub(FunctionBodyType.Code)
|
|
.withName('expected-function-name');
|
|
const sut = new SharedFunctionCollection();
|
|
// act
|
|
sut.addFunction(expected);
|
|
const actual = sut.getFunctionByName(expected.name);
|
|
// assert
|
|
expect(actual).to.equal(expected);
|
|
});
|
|
it('when calling function is added', () => {
|
|
// arrange
|
|
const callee = new SharedFunctionStub(FunctionBodyType.Code)
|
|
.withName('calleeFunction');
|
|
const caller = new SharedFunctionStub(FunctionBodyType.Calls)
|
|
.withName('callerFunction')
|
|
.withCalls(new FunctionCallStub().withFunctionName(callee.name));
|
|
const sut = new SharedFunctionCollection();
|
|
// act
|
|
sut.addFunction(callee);
|
|
sut.addFunction(caller);
|
|
const actual = sut.getFunctionByName(caller.name);
|
|
// assert
|
|
expect(actual).to.equal(caller);
|
|
});
|
|
});
|
|
});
|
|
});
|