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.
99 lines
3.3 KiB
TypeScript
99 lines
3.3 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { IExpression } from '@/application/Parser/Script/Compiler/Expressions/Expression/IExpression';
|
|
import { IExpressionParser } from '@/application/Parser/Script/Compiler/Expressions/Parser/IExpressionParser';
|
|
import { CompositeExpressionParser } from '@/application/Parser/Script/Compiler/Expressions/Parser/CompositeExpressionParser';
|
|
import { ExpressionStub } from '@tests/unit/shared/Stubs/ExpressionStub';
|
|
import { itEachAbsentObjectValue } from '@tests/unit/shared/TestCases/AbsentTests';
|
|
|
|
describe('CompositeExpressionParser', () => {
|
|
describe('ctor', () => {
|
|
it('throws if null parsers given', () => {
|
|
// arrange
|
|
const expectedError = 'missing leafs';
|
|
const parsers = null;
|
|
// act
|
|
const act = () => new CompositeExpressionParser(parsers);
|
|
// assert
|
|
expect(act).to.throw(expectedError);
|
|
});
|
|
describe('throws if one of the parsers is undefined', () => {
|
|
itEachAbsentObjectValue((absentValue) => {
|
|
// arrange
|
|
const expectedError = 'missing leaf';
|
|
const parsers: readonly IExpressionParser[] = [absentValue, mockParser()];
|
|
// act
|
|
const act = () => new CompositeExpressionParser(parsers);
|
|
// assert
|
|
expect(act).to.throw(expectedError);
|
|
});
|
|
});
|
|
});
|
|
describe('findExpressions', () => {
|
|
describe('returns result from parsers as expected', () => {
|
|
// arrange
|
|
const pool = [
|
|
new ExpressionStub(), new ExpressionStub(), new ExpressionStub(),
|
|
new ExpressionStub(), new ExpressionStub(),
|
|
];
|
|
const testCases = [
|
|
{
|
|
name: 'from single parsing none',
|
|
parsers: [mockParser()],
|
|
expected: [],
|
|
},
|
|
{
|
|
name: 'from single parsing single',
|
|
parsers: [mockParser(pool[0])],
|
|
expected: [pool[0]],
|
|
},
|
|
{
|
|
name: 'from single parsing multiple',
|
|
parsers: [mockParser(pool[0], pool[1])],
|
|
expected: [pool[0], pool[1]],
|
|
},
|
|
{
|
|
name: 'from multiple parsers with each parsing single',
|
|
parsers: [
|
|
mockParser(pool[0]),
|
|
mockParser(pool[1]),
|
|
mockParser(pool[2]),
|
|
],
|
|
expected: [pool[0], pool[1], pool[2]],
|
|
},
|
|
{
|
|
name: 'from multiple parsers with each parsing multiple',
|
|
parsers: [
|
|
mockParser(pool[0], pool[1]),
|
|
mockParser(pool[2], pool[3], pool[4])],
|
|
expected: [pool[0], pool[1], pool[2], pool[3], pool[4]],
|
|
},
|
|
{
|
|
name: 'from multiple parsers with only some parsing',
|
|
parsers: [
|
|
mockParser(pool[0], pool[1]),
|
|
mockParser(),
|
|
mockParser(pool[2]),
|
|
mockParser(),
|
|
],
|
|
expected: [pool[0], pool[1], pool[2]],
|
|
},
|
|
];
|
|
for (const testCase of testCases) {
|
|
it(testCase.name, () => {
|
|
const sut = new CompositeExpressionParser(testCase.parsers);
|
|
// act
|
|
const result = sut.findExpressions('non-important-code');
|
|
// expect
|
|
expect(result).to.deep.equal(testCase.expected);
|
|
});
|
|
}
|
|
});
|
|
});
|
|
});
|
|
|
|
function mockParser(...result: IExpression[]): IExpressionParser {
|
|
return {
|
|
findExpressions: () => result,
|
|
};
|
|
}
|