mirror of https://github.com/TriliumNext/Notes
Merge pull request #977 from pano9000/test_vitest
test: add vitest as test framework and port current testspull/932/head
commit
7fc5f9ab83
File diff suppressed because it is too large
Load Diff
@ -1,79 +0,0 @@
|
|||||||
export function describe(name: string, cb: () => any) {
|
|
||||||
console.log(`Running ${name}`);
|
|
||||||
|
|
||||||
cb();
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function it(name: string, cb: () => any) {
|
|
||||||
console.log(` Running ${name}`);
|
|
||||||
|
|
||||||
cb();
|
|
||||||
}
|
|
||||||
|
|
||||||
let errorCount = 0;
|
|
||||||
|
|
||||||
export function expect(val: any) {
|
|
||||||
return {
|
|
||||||
toEqual: (comparedVal: any) => {
|
|
||||||
const jsonVal = JSON.stringify(val);
|
|
||||||
const comparedJsonVal = JSON.stringify(comparedVal);
|
|
||||||
|
|
||||||
if (jsonVal !== comparedJsonVal) {
|
|
||||||
console.trace("toEqual check failed.");
|
|
||||||
console.error(`expected: ${comparedJsonVal}`);
|
|
||||||
console.error(`got: ${jsonVal}`);
|
|
||||||
|
|
||||||
errorCount++;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
toBeTruthy: () => {
|
|
||||||
if (!val) {
|
|
||||||
console.trace("toBeTruthy failed.");
|
|
||||||
console.error(`expected: truthy value`);
|
|
||||||
console.error(`got: ${val}`);
|
|
||||||
|
|
||||||
errorCount++;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
toBeFalsy: () => {
|
|
||||||
if (!!val) {
|
|
||||||
console.trace("toBeFalsy failed.");
|
|
||||||
console.error(`expected: null, false, undefined, 0 or empty string`);
|
|
||||||
console.error(`got: ${val}`);
|
|
||||||
|
|
||||||
errorCount++;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
toThrow: (errorMessage: any) => {
|
|
||||||
try {
|
|
||||||
val();
|
|
||||||
} catch (e: any) {
|
|
||||||
if (e.message !== errorMessage) {
|
|
||||||
console.trace("toThrow caught exception, but messages differ");
|
|
||||||
console.error(`expected: ${errorMessage}`);
|
|
||||||
console.error(`got: ${e.message}`);
|
|
||||||
console.error(`${e.stack}`);
|
|
||||||
|
|
||||||
errorCount++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
console.trace("toThrow did not catch any exception.");
|
|
||||||
console.error(`expected: ${errorMessage}`);
|
|
||||||
console.error(`got: [none]`);
|
|
||||||
errorCount++;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function execute() {
|
|
||||||
console.log("");
|
|
||||||
|
|
||||||
if (errorCount) {
|
|
||||||
console.log(`!!!${errorCount} tests failed!!!`);
|
|
||||||
} else {
|
|
||||||
console.log("All tests passed!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,3 +1,5 @@
|
|||||||
describe("Notes", () => {
|
import { describe, it } from "vitest";
|
||||||
|
|
||||||
|
describe.todo("Notes", () => {
|
||||||
it("zzz", () => {});
|
it("zzz", () => {});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
"spec_dir": "",
|
|
||||||
"spec_files": [
|
|
||||||
"spec/**/*.spec.ts",
|
|
||||||
"src/**/*.spec.ts"
|
|
||||||
],
|
|
||||||
"helpers": ["helpers/**/*.js"],
|
|
||||||
"stopSpecOnExpectationFailure": false,
|
|
||||||
"random": true
|
|
||||||
}
|
|
||||||
@ -0,0 +1,24 @@
|
|||||||
|
import { defineConfig } from "vitest/config";
|
||||||
|
import { configDefaults, coverageConfigDefaults } from "vitest/config";
|
||||||
|
|
||||||
|
const customExcludes = [
|
||||||
|
"build/**",
|
||||||
|
"e2e/**",
|
||||||
|
"integration-tests/**",
|
||||||
|
"tests-examples/**",
|
||||||
|
"node_modules/**",
|
||||||
|
"src/public/app-dist/**",
|
||||||
|
"libraries/**",
|
||||||
|
"docs/**",
|
||||||
|
"out/**",
|
||||||
|
"*.config.[jt]s" // playwright.config.ts and similar
|
||||||
|
];
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
test: {
|
||||||
|
exclude: [...configDefaults.exclude, ...customExcludes],
|
||||||
|
coverage: {
|
||||||
|
exclude: [...coverageConfigDefaults.exclude, ...customExcludes]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
Loading…
Reference in New Issue