mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
convert es6 tests to ts
This commit is contained in:
parent
615f15756b
commit
17fac31cd1
@ -29,7 +29,7 @@
|
||||
"build-docs": "npm run build-backend-docs && npm run build-frontend-docs",
|
||||
"webpack": "webpack -c webpack.config.js",
|
||||
"test-jasmine": "TRILIUM_DATA_DIR=./data-test ts-node ./node_modules/.bin/jasmine",
|
||||
"test-es6": "node -r esm spec-es6/attribute_parser.spec.js ",
|
||||
"test-es6": "ts-node spec-es6/attribute_parser.spec.ts ",
|
||||
"test": "npm run test-jasmine && npm run test-es6",
|
||||
"postinstall": "rimraf ./node_modules/canvas"
|
||||
},
|
||||
|
@ -1,27 +1,28 @@
|
||||
import attributeParser from '../src/public/app/services/attribute_parser.js';
|
||||
import {describe, it, expect, execute} from './mini_test.js';
|
||||
import * as attributeParser from '../src/public/app/services/attribute_parser.js';
|
||||
|
||||
import {describe, it, expect, execute} from './mini_test';
|
||||
|
||||
describe("Lexing", () => {
|
||||
it("simple label", () => {
|
||||
expect(attributeParser.lex("#label").map(t => t.text))
|
||||
expect(attributeParser.lex("#label").map((t: any) => t.text))
|
||||
.toEqual(["#label"]);
|
||||
});
|
||||
|
||||
it("simple label with trailing spaces", () => {
|
||||
expect(attributeParser.lex(" #label ").map(t => t.text))
|
||||
expect(attributeParser.lex(" #label ").map((t: any) => t.text))
|
||||
.toEqual(["#label"]);
|
||||
});
|
||||
|
||||
it("inherited label", () => {
|
||||
expect(attributeParser.lex("#label(inheritable)").map(t => t.text))
|
||||
expect(attributeParser.lex("#label(inheritable)").map((t: any) => t.text))
|
||||
.toEqual(["#label", "(", "inheritable", ")"]);
|
||||
|
||||
expect(attributeParser.lex("#label ( inheritable ) ").map(t => t.text))
|
||||
expect(attributeParser.lex("#label ( inheritable ) ").map((t: any) => t.text))
|
||||
.toEqual(["#label", "(", "inheritable", ")"]);
|
||||
});
|
||||
|
||||
it("label with value", () => {
|
||||
expect(attributeParser.lex("#label=Hallo").map(t => t.text))
|
||||
expect(attributeParser.lex("#label=Hallo").map((t: any) => t.text))
|
||||
.toEqual(["#label", "=", "Hallo"]);
|
||||
});
|
||||
|
||||
@ -32,25 +33,25 @@ describe("Lexing", () => {
|
||||
});
|
||||
|
||||
it("relation with value", () => {
|
||||
expect(attributeParser.lex('~relation=#root/RclIpMauTOKS/NFi2gL4xtPxM').map(t => t.text))
|
||||
expect(attributeParser.lex('~relation=#root/RclIpMauTOKS/NFi2gL4xtPxM').map((t: any) => t.text))
|
||||
.toEqual(["~relation", "=", "#root/RclIpMauTOKS/NFi2gL4xtPxM"]);
|
||||
});
|
||||
|
||||
it("use quotes to define value", () => {
|
||||
expect(attributeParser.lex("#'label a'='hello\"` world'").map(t => t.text))
|
||||
expect(attributeParser.lex("#'label a'='hello\"` world'").map((t: any) => t.text))
|
||||
.toEqual(["#label a", "=", 'hello"` world']);
|
||||
|
||||
expect(attributeParser.lex('#"label a" = "hello\'` world"').map(t => t.text))
|
||||
expect(attributeParser.lex('#"label a" = "hello\'` world"').map((t: any) => t.text))
|
||||
.toEqual(["#label a", "=", "hello'` world"]);
|
||||
|
||||
expect(attributeParser.lex('#`label a` = `hello\'" world`').map(t => t.text))
|
||||
expect(attributeParser.lex('#`label a` = `hello\'" world`').map((t: any) => t.text))
|
||||
.toEqual(["#label a", "=", "hello'\" world"]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Parser", () => {
|
||||
it("simple label", () => {
|
||||
const attrs = attributeParser.parse(["#token"].map(t => ({text: t})));
|
||||
const attrs = attributeParser.parse(["#token"].map((t: any) => ({text: t})));
|
||||
|
||||
expect(attrs.length).toEqual(1);
|
||||
expect(attrs[0].type).toEqual('label');
|
||||
@ -60,7 +61,7 @@ describe("Parser", () => {
|
||||
});
|
||||
|
||||
it("inherited label", () => {
|
||||
const attrs = attributeParser.parse(["#token", "(", "inheritable", ")"].map(t => ({text: t})));
|
||||
const attrs = attributeParser.parse(["#token", "(", "inheritable", ")"].map((t: any) => ({text: t})));
|
||||
|
||||
expect(attrs.length).toEqual(1);
|
||||
expect(attrs[0].type).toEqual('label');
|
||||
@ -70,7 +71,7 @@ describe("Parser", () => {
|
||||
});
|
||||
|
||||
it("label with value", () => {
|
||||
const attrs = attributeParser.parse(["#token", "=", "val"].map(t => ({text: t})));
|
||||
const attrs = attributeParser.parse(["#token", "=", "val"].map((t: any) => ({text: t})));
|
||||
|
||||
expect(attrs.length).toEqual(1);
|
||||
expect(attrs[0].type).toEqual('label');
|
||||
@ -79,14 +80,14 @@ describe("Parser", () => {
|
||||
});
|
||||
|
||||
it("relation", () => {
|
||||
let attrs = attributeParser.parse(["~token", "=", "#root/RclIpMauTOKS/NFi2gL4xtPxM"].map(t => ({text: t})));
|
||||
let attrs = attributeParser.parse(["~token", "=", "#root/RclIpMauTOKS/NFi2gL4xtPxM"].map((t: any) => ({text: t})));
|
||||
|
||||
expect(attrs.length).toEqual(1);
|
||||
expect(attrs[0].type).toEqual('relation');
|
||||
expect(attrs[0].name).toEqual("token");
|
||||
expect(attrs[0].value).toEqual('NFi2gL4xtPxM');
|
||||
|
||||
attrs = attributeParser.parse(["~token", "=", "#NFi2gL4xtPxM"].map(t => ({text: t})));
|
||||
attrs = attributeParser.parse(["~token", "=", "#NFi2gL4xtPxM"].map((t: any) => ({text: t})));
|
||||
|
||||
expect(attrs.length).toEqual(1);
|
||||
expect(attrs[0].type).toEqual('relation');
|
@ -1,10 +1,10 @@
|
||||
export function describe(name, cb) {
|
||||
export function describe(name: string, cb: () => any) {
|
||||
console.log(`Running ${name}`);
|
||||
|
||||
cb();
|
||||
}
|
||||
|
||||
export async function it(name, cb) {
|
||||
export async function it(name: string, cb: () => any) {
|
||||
console.log(` Running ${name}`);
|
||||
|
||||
cb();
|
||||
@ -12,9 +12,9 @@ export async function it(name, cb) {
|
||||
|
||||
let errorCount = 0;
|
||||
|
||||
export function expect(val) {
|
||||
export function expect(val: any) {
|
||||
return {
|
||||
toEqual: comparedVal => {
|
||||
toEqual: (comparedVal: any) => {
|
||||
const jsonVal = JSON.stringify(val);
|
||||
const comparedJsonVal = JSON.stringify(comparedVal);
|
||||
|
||||
@ -44,11 +44,11 @@ export function expect(val) {
|
||||
errorCount++;
|
||||
}
|
||||
},
|
||||
toThrow: errorMessage => {
|
||||
toThrow: (errorMessage: any) => {
|
||||
try {
|
||||
val();
|
||||
}
|
||||
catch (e) {
|
||||
catch (e: any) {
|
||||
if (e.message !== errorMessage) {
|
||||
console.trace("toThrow caught exception, but messages differ");
|
||||
console.error(`expected: ${errorMessage}`);
|
7
src/public/app/services/attribute_parser.d.ts
vendored
Normal file
7
src/public/app/services/attribute_parser.d.ts
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
declare module 'attribute_parser';
|
||||
|
||||
|
||||
export function lex(str: string): any[]
|
||||
export function parse(tokens: any[], str?: string, allowEmptyRelations?: boolean): any[]
|
||||
export function lexAndParse(str: string, allowEmptyRelations?: boolean): any[]
|
||||
|
@ -1,4 +1,4 @@
|
||||
import utils from "./utils.js";
|
||||
const utils = require("./utils.js");
|
||||
|
||||
function lex(str) {
|
||||
str = str.trim();
|
||||
@ -222,7 +222,7 @@ function lexAndParse(str, allowEmptyRelations = false) {
|
||||
return parse(tokens, str, allowEmptyRelations);
|
||||
}
|
||||
|
||||
export default {
|
||||
module.exports = {
|
||||
lex,
|
||||
parse,
|
||||
lexAndParse
|
||||
|
@ -505,7 +505,7 @@ function createImageSrcUrl(note) {
|
||||
return `api/images/${note.noteId}/${encodeURIComponent(note.title)}?timestamp=${Date.now()}`;
|
||||
}
|
||||
|
||||
export default {
|
||||
module.exports = {
|
||||
reloadFrontendApp,
|
||||
parseDate,
|
||||
formatDateISO,
|
||||
|
@ -11,7 +11,7 @@
|
||||
"downlevelIteration": true,
|
||||
"skipLibCheck": true
|
||||
},
|
||||
"include": ["./src/**/*.js", "./src/**/*.ts", "./*.ts", "./spec/**/*.ts"],
|
||||
"include": ["./src/**/*.js", "./src/**/*.ts", "./*.ts", "./spec/**/*.ts", "./spec-es6/**/*.ts"],
|
||||
"exclude": ["./node_modules/**/*"],
|
||||
"ts-node": {
|
||||
"files": true
|
||||
|
Loading…
x
Reference in New Issue
Block a user