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.
120 lines
4.5 KiB
TypeScript
120 lines
4.5 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { ScriptingLanguage } from '@/domain/ScriptingLanguage';
|
|
import { ScriptingDefinitionParser } from '@/application/Parser/ScriptingDefinition/ScriptingDefinitionParser';
|
|
import { IEnumParser } from '@/application/Common/Enum';
|
|
import { ICodeSubstituter } from '@/application/Parser/ScriptingDefinition/ICodeSubstituter';
|
|
import { IScriptingDefinition } from '@/domain/IScriptingDefinition';
|
|
import { ProjectInformationStub } from '@tests/unit/shared/Stubs/ProjectInformationStub';
|
|
import { EnumParserStub } from '@tests/unit/shared/Stubs/EnumParserStub';
|
|
import { ScriptingDefinitionDataStub } from '@tests/unit/shared/Stubs/ScriptingDefinitionDataStub';
|
|
import { CodeSubstituterStub } from '@tests/unit/shared/Stubs/CodeSubstituterStub';
|
|
import { itEachAbsentObjectValue } from '@tests/unit/shared/TestCases/AbsentTests';
|
|
|
|
describe('ScriptingDefinitionParser', () => {
|
|
describe('parseScriptingDefinition', () => {
|
|
describe('throws when info is missing', () => {
|
|
itEachAbsentObjectValue((absentValue) => {
|
|
// arrange
|
|
const expectedError = 'missing info';
|
|
const info = absentValue;
|
|
const definition = new ScriptingDefinitionDataStub();
|
|
const sut = new ScriptingDefinitionParserBuilder()
|
|
.build();
|
|
// act
|
|
const act = () => sut.parse(definition, info);
|
|
// assert
|
|
expect(act).to.throw(expectedError);
|
|
});
|
|
});
|
|
describe('throws when definition is missing', () => {
|
|
itEachAbsentObjectValue((absentValue) => {
|
|
// arrange
|
|
const expectedError = 'missing definition';
|
|
const info = new ProjectInformationStub();
|
|
const definition = absentValue;
|
|
const sut = new ScriptingDefinitionParserBuilder()
|
|
.build();
|
|
// act
|
|
const act = () => sut.parse(definition, info);
|
|
// assert
|
|
expect(act).to.throw(expectedError);
|
|
});
|
|
});
|
|
describe('language', () => {
|
|
it('parses as expected', () => {
|
|
// arrange
|
|
const expectedLanguage = ScriptingLanguage.batchfile;
|
|
const languageText = 'batchfile';
|
|
const expectedName = 'language';
|
|
const info = new ProjectInformationStub();
|
|
const definition = new ScriptingDefinitionDataStub()
|
|
.withLanguage(languageText);
|
|
const parserMock = new EnumParserStub<ScriptingLanguage>()
|
|
.setup(expectedName, languageText, expectedLanguage);
|
|
const sut = new ScriptingDefinitionParserBuilder()
|
|
.withParser(parserMock)
|
|
.build();
|
|
// act
|
|
const actual = sut.parse(definition, info);
|
|
// assert
|
|
expect(actual.language).to.equal(expectedLanguage);
|
|
});
|
|
});
|
|
describe('substitutes code as expected', () => {
|
|
// arrange
|
|
const code = 'hello';
|
|
const expected = 'substituted';
|
|
const testCases = [
|
|
{
|
|
name: 'startCode',
|
|
getActualValue: (result: IScriptingDefinition) => result.startCode,
|
|
data: new ScriptingDefinitionDataStub()
|
|
.withStartCode(code),
|
|
},
|
|
{
|
|
name: 'endCode',
|
|
getActualValue: (result: IScriptingDefinition) => result.endCode,
|
|
data: new ScriptingDefinitionDataStub()
|
|
.withEndCode(code),
|
|
},
|
|
];
|
|
for (const testCase of testCases) {
|
|
it(testCase.name, () => {
|
|
const info = new ProjectInformationStub();
|
|
const substituterMock = new CodeSubstituterStub()
|
|
.setup(code, info, expected);
|
|
const sut = new ScriptingDefinitionParserBuilder()
|
|
.withSubstituter(substituterMock)
|
|
.build();
|
|
// act
|
|
const definition = sut.parse(testCase.data, info);
|
|
// assert
|
|
const actual = testCase.getActualValue(definition);
|
|
expect(actual).to.equal(expected);
|
|
});
|
|
}
|
|
});
|
|
});
|
|
});
|
|
|
|
class ScriptingDefinitionParserBuilder {
|
|
private languageParser: IEnumParser<ScriptingLanguage> = new EnumParserStub<ScriptingLanguage>()
|
|
.setupDefaultValue(ScriptingLanguage.shellscript);
|
|
|
|
private codeSubstituter: ICodeSubstituter = new CodeSubstituterStub();
|
|
|
|
public withParser(parser: IEnumParser<ScriptingLanguage>) {
|
|
this.languageParser = parser;
|
|
return this;
|
|
}
|
|
|
|
public withSubstituter(substituter: ICodeSubstituter) {
|
|
this.codeSubstituter = substituter;
|
|
return this;
|
|
}
|
|
|
|
public build() {
|
|
return new ScriptingDefinitionParser(this.languageParser, this.codeSubstituter);
|
|
}
|
|
}
|