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.
63 lines
1.9 KiB
TypeScript
63 lines
1.9 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { ApplicationFactory, ApplicationGetterType } from '@/application/ApplicationFactory';
|
|
import { ApplicationStub } from '@tests/unit/shared/Stubs/ApplicationStub';
|
|
import { itEachAbsentObjectValue } from '@tests/unit/shared/TestCases/AbsentTests';
|
|
|
|
describe('ApplicationFactory', () => {
|
|
describe('ctor', () => {
|
|
describe('throws if getter is absent', () => {
|
|
itEachAbsentObjectValue((absentValue) => {
|
|
// arrange
|
|
const expectedError = 'missing getter';
|
|
const getter: ApplicationGetterType = absentValue;
|
|
// act
|
|
const act = () => new SystemUnderTest(getter);
|
|
// assert
|
|
expect(act).to.throw(expectedError);
|
|
});
|
|
});
|
|
});
|
|
describe('getApp', () => {
|
|
it('returns result from the getter', async () => {
|
|
// arrange
|
|
const expected = new ApplicationStub();
|
|
const getter: ApplicationGetterType = () => expected;
|
|
const sut = new SystemUnderTest(getter);
|
|
// act
|
|
const actual = await Promise.all([
|
|
sut.getApp(),
|
|
sut.getApp(),
|
|
sut.getApp(),
|
|
sut.getApp(),
|
|
]);
|
|
// assert
|
|
expect(actual.every((value) => value === expected));
|
|
});
|
|
it('only executes getter once', async () => {
|
|
// arrange
|
|
let totalExecution = 0;
|
|
const expected = new ApplicationStub();
|
|
const getter: ApplicationGetterType = () => {
|
|
totalExecution++;
|
|
return expected;
|
|
};
|
|
const sut = new SystemUnderTest(getter);
|
|
// act
|
|
await Promise.all([
|
|
sut.getApp(),
|
|
sut.getApp(),
|
|
sut.getApp(),
|
|
sut.getApp(),
|
|
]);
|
|
// assert
|
|
expect(totalExecution).to.equal(1);
|
|
});
|
|
});
|
|
});
|
|
|
|
class SystemUnderTest extends ApplicationFactory {
|
|
public constructor(costlyGetter: ApplicationGetterType) {
|
|
super(costlyGetter);
|
|
}
|
|
}
|