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.
81 lines
2.7 KiB
TypeScript
81 lines
2.7 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import type { DocumentableData } from '@/application/collections/';
|
|
import { parseDocs } from '@/application/Parser/DocumentationParser';
|
|
import { itEachAbsentObjectValue, itEachAbsentStringValue } from '@tests/unit/shared/TestCases/AbsentTests';
|
|
|
|
describe('DocumentationParser', () => {
|
|
describe('parseDocs', () => {
|
|
describe('throws when node is missing', () => {
|
|
itEachAbsentObjectValue((absentValue) => {
|
|
// arrange
|
|
const expectedError = 'missing documentable';
|
|
// act
|
|
const act = () => parseDocs(absentValue);
|
|
// assert
|
|
expect(act).to.throw(expectedError);
|
|
});
|
|
});
|
|
describe('throws when single documentation is missing', () => {
|
|
itEachAbsentStringValue((absentValue) => {
|
|
// arrange
|
|
const expectedError = 'missing documentation';
|
|
const node: DocumentableData = { docs: ['non empty doc 1', absentValue] };
|
|
// act
|
|
const act = () => parseDocs(node);
|
|
// assert
|
|
expect(act).to.throw(expectedError);
|
|
});
|
|
});
|
|
describe('throws when type is unexpected', () => {
|
|
// arrange
|
|
const expectedTypeError = 'docs field (documentation) must be an array of strings';
|
|
const wrongTypedValue = 22 as never;
|
|
const testCases: ReadonlyArray<{ name: string, node: DocumentableData }> = [
|
|
{
|
|
name: 'given docs',
|
|
node: { docs: wrongTypedValue },
|
|
},
|
|
{
|
|
name: 'single doc',
|
|
node: { docs: ['non empty doc 1', wrongTypedValue] },
|
|
},
|
|
];
|
|
for (const testCase of testCases) {
|
|
it(testCase.name, () => {
|
|
// act
|
|
const act = () => parseDocs(testCase.node);
|
|
// assert
|
|
expect(act).to.throw(expectedTypeError);
|
|
});
|
|
}
|
|
});
|
|
it('returns empty when empty', () => {
|
|
// arrange
|
|
const empty: DocumentableData = { };
|
|
// act
|
|
const actual = parseDocs(empty);
|
|
// assert
|
|
expect(actual).to.have.lengthOf(0);
|
|
});
|
|
it('returns single item when string', () => {
|
|
// arrange
|
|
const url = 'https://privacy.sexy';
|
|
const expected = [url];
|
|
const sut: DocumentableData = { docs: url };
|
|
// act
|
|
const actual = parseDocs(sut);
|
|
// assert
|
|
expect(actual).to.deep.equal(expected);
|
|
});
|
|
it('returns all when array', () => {
|
|
// arrange
|
|
const expected = ['https://privacy.sexy', 'https://github.com/undergroundwires/privacy.sexy'];
|
|
const sut: DocumentableData = { docs: expected };
|
|
// act
|
|
const actual = parseDocs(sut);
|
|
// assert
|
|
expect(actual).to.deep.equal(expected);
|
|
});
|
|
});
|
|
});
|