This commit updates various dependencies to their latest versions.
Other changes include:
- Moved the following from `devDependencies` to `dependencies`:
- `electron-log`
- `electron-updater`
- Remove `npm` dependency.
- Code changes:
- Add type casting in several places to align with the latest
`typescript` version.
- Adopt to new return type of `setTimeout`.
- Dependencies not upgraded due to
`@vue/eslint-config-airbnb-with-typescript` not supporting
`@eslint-typescript` V6 (see vuejs/eslint-config-airbnb#58):
- `vue/eslint-config-typescript`
- `@typescript-eslint/eslint-plugin`
- `@typescript-eslint/parser`
- Enable video recording for cypress as it's disabled by default since
13.X.X.
134 lines
4.0 KiB
TypeScript
134 lines
4.0 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { ScriptingDefinition } from '@/domain/ScriptingDefinition';
|
|
import { ScriptingLanguage } from '@/domain/ScriptingLanguage';
|
|
import { getEnumValues } from '@/application/Common/Enum';
|
|
import { itEachAbsentStringValue } from '@tests/unit/shared/TestCases/AbsentTests';
|
|
|
|
describe('ScriptingDefinition', () => {
|
|
describe('language', () => {
|
|
describe('sets as expected', () => {
|
|
// arrange
|
|
const expectedValues = getEnumValues(ScriptingLanguage);
|
|
expectedValues.forEach((expected) => {
|
|
it(ScriptingLanguage[expected], () => {
|
|
// act
|
|
const sut = new ScriptingDefinitionBuilder()
|
|
.withLanguage(expected)
|
|
.build();
|
|
// assert
|
|
expect(sut.language).to.equal(expected);
|
|
});
|
|
});
|
|
});
|
|
it('throws if unknown', () => {
|
|
// arrange
|
|
const unknownValue: ScriptingLanguage = 666 as never;
|
|
const errorMessage = `unsupported language: ${unknownValue}`;
|
|
// act
|
|
const act = () => new ScriptingDefinitionBuilder()
|
|
.withLanguage(unknownValue)
|
|
.build();
|
|
// assert
|
|
expect(act).to.throw(errorMessage);
|
|
});
|
|
});
|
|
describe('fileExtension', () => {
|
|
describe('returns expected for each language', () => {
|
|
// arrange
|
|
const testCases = new Map<ScriptingLanguage, string>([
|
|
[ScriptingLanguage.batchfile, 'bat'],
|
|
[ScriptingLanguage.shellscript, 'sh'],
|
|
]);
|
|
for (const test of testCases.entries()) {
|
|
const language = test[0];
|
|
const expectedExtension = test[1];
|
|
it(`${ScriptingLanguage[language]} has ${expectedExtension}`, () => {
|
|
// act
|
|
const sut = new ScriptingDefinitionBuilder()
|
|
.withLanguage(language)
|
|
.build();
|
|
// assert
|
|
expect(sut.fileExtension, expectedExtension);
|
|
});
|
|
}
|
|
});
|
|
});
|
|
describe('startCode', () => {
|
|
it('sets as expected', () => {
|
|
// arrange
|
|
const expected = 'REM start-code';
|
|
// act
|
|
const sut = new ScriptingDefinitionBuilder()
|
|
.withStartCode(expected)
|
|
.build();
|
|
// assert
|
|
expect(sut.startCode).to.equal(expected);
|
|
});
|
|
describe('throws when absent', () => {
|
|
itEachAbsentStringValue((absentValue) => {
|
|
// arrange
|
|
const expectedError = 'missing start code';
|
|
const undefinedValue = absentValue;
|
|
// act
|
|
const act = () => new ScriptingDefinitionBuilder()
|
|
.withStartCode(undefinedValue)
|
|
.build();
|
|
// assert
|
|
expect(act).to.throw(expectedError);
|
|
});
|
|
});
|
|
});
|
|
describe('endCode', () => {
|
|
it('sets as expected', () => {
|
|
// arrange
|
|
const expected = 'REM end-code';
|
|
// act
|
|
const sut = new ScriptingDefinitionBuilder()
|
|
.withEndCode(expected)
|
|
.build();
|
|
// assert
|
|
expect(sut.endCode).to.equal(expected);
|
|
});
|
|
describe('throws when undefined', () => {
|
|
itEachAbsentStringValue((absentValue) => {
|
|
// arrange
|
|
const expectedError = 'missing end code';
|
|
const undefinedValue = absentValue;
|
|
// act
|
|
const act = () => new ScriptingDefinitionBuilder()
|
|
.withEndCode(undefinedValue)
|
|
.build();
|
|
// assert
|
|
expect(act).to.throw(expectedError);
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
class ScriptingDefinitionBuilder {
|
|
private language = ScriptingLanguage.shellscript;
|
|
|
|
private startCode = 'REM start-code';
|
|
|
|
private endCode = 'REM end-code';
|
|
|
|
public withLanguage(language: ScriptingLanguage): ScriptingDefinitionBuilder {
|
|
this.language = language;
|
|
return this;
|
|
}
|
|
|
|
public withStartCode(startCode: string): ScriptingDefinitionBuilder {
|
|
this.startCode = startCode;
|
|
return this;
|
|
}
|
|
|
|
public withEndCode(endCode: string): ScriptingDefinitionBuilder {
|
|
this.endCode = endCode;
|
|
return this;
|
|
}
|
|
|
|
public build(): ScriptingDefinition {
|
|
return new ScriptingDefinition(this.language, this.startCode, this.endCode);
|
|
}
|
|
}
|