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.
92 lines
2.4 KiB
TypeScript
92 lines
2.4 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { ScriptCode } from '@/domain/ScriptCode';
|
|
import { AbsentStringTestCases } from '@tests/unit/shared/TestCases/AbsentTests';
|
|
|
|
describe('ScriptCode', () => {
|
|
describe('code', () => {
|
|
describe('throws with invalid code', () => {
|
|
// arrange
|
|
const testCases = [
|
|
{
|
|
name: 'throws when "execute" and "revert" are same',
|
|
code: {
|
|
execute: 'same',
|
|
revert: 'same',
|
|
},
|
|
expectedError: '(revert): Code itself and its reverting code cannot be the same',
|
|
},
|
|
...AbsentStringTestCases.map((testCase) => ({
|
|
name: `cannot construct with ${testCase.valueName} "execute"`,
|
|
code: {
|
|
execute: testCase.absentValue,
|
|
revert: 'code',
|
|
},
|
|
expectedError: 'missing code',
|
|
})),
|
|
];
|
|
for (const testCase of testCases) {
|
|
it(testCase.name, () => {
|
|
// act
|
|
const act = () => new ScriptCodeBuilder()
|
|
.withExecute(testCase.code.execute)
|
|
.withRevert(testCase.code.revert)
|
|
.build();
|
|
// assert
|
|
expect(act).to.throw(testCase.expectedError);
|
|
});
|
|
}
|
|
});
|
|
describe('sets as expected with valid "execute" or "revert"', () => {
|
|
// arrange
|
|
const testCases = [
|
|
{
|
|
testName: 'code and revert code is given',
|
|
code: 'valid code',
|
|
revertCode: 'valid revert-code',
|
|
},
|
|
{
|
|
testName: 'only code is given but not revert code',
|
|
code: 'valid code',
|
|
revertCode: undefined,
|
|
},
|
|
];
|
|
// assert
|
|
for (const testCase of testCases) {
|
|
it(testCase.testName, () => {
|
|
// act
|
|
const sut = new ScriptCodeBuilder()
|
|
.withExecute(testCase.code)
|
|
.withRevert(testCase.revertCode)
|
|
.build();
|
|
// assert
|
|
expect(sut.execute).to.equal(testCase.code);
|
|
expect(sut.revert).to.equal(testCase.revertCode);
|
|
});
|
|
}
|
|
});
|
|
});
|
|
});
|
|
|
|
class ScriptCodeBuilder {
|
|
public execute = 'default-execute-code';
|
|
|
|
public revert = '';
|
|
|
|
public withExecute(execute: string) {
|
|
this.execute = execute;
|
|
return this;
|
|
}
|
|
|
|
public withRevert(revert: string) {
|
|
this.revert = revert;
|
|
return this;
|
|
}
|
|
|
|
public build(): ScriptCode {
|
|
return new ScriptCode(
|
|
this.execute,
|
|
this.revert,
|
|
);
|
|
}
|
|
}
|