Skip to content
This repository was archived by the owner on Jun 24, 2025. It is now read-only.

Commit 17fac31

Browse files
committed
convert es6 tests to ts
1 parent 615f157 commit 17fac31

File tree

7 files changed

+35
-27
lines changed

7 files changed

+35
-27
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"build-docs": "npm run build-backend-docs && npm run build-frontend-docs",
3030
"webpack": "webpack -c webpack.config.js",
3131
"test-jasmine": "TRILIUM_DATA_DIR=./data-test ts-node ./node_modules/.bin/jasmine",
32-
"test-es6": "node -r esm spec-es6/attribute_parser.spec.js ",
32+
"test-es6": "ts-node spec-es6/attribute_parser.spec.ts ",
3333
"test": "npm run test-jasmine && npm run test-es6",
3434
"postinstall": "rimraf ./node_modules/canvas"
3535
},

spec-es6/attribute_parser.spec.js renamed to spec-es6/attribute_parser.spec.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
1-
import attributeParser from '../src/public/app/services/attribute_parser.js';
2-
import {describe, it, expect, execute} from './mini_test.js';
1+
import * as attributeParser from '../src/public/app/services/attribute_parser.js';
2+
3+
import {describe, it, expect, execute} from './mini_test';
34

45
describe("Lexing", () => {
56
it("simple label", () => {
6-
expect(attributeParser.lex("#label").map(t => t.text))
7+
expect(attributeParser.lex("#label").map((t: any) => t.text))
78
.toEqual(["#label"]);
89
});
910

1011
it("simple label with trailing spaces", () => {
11-
expect(attributeParser.lex(" #label ").map(t => t.text))
12+
expect(attributeParser.lex(" #label ").map((t: any) => t.text))
1213
.toEqual(["#label"]);
1314
});
1415

1516
it("inherited label", () => {
16-
expect(attributeParser.lex("#label(inheritable)").map(t => t.text))
17+
expect(attributeParser.lex("#label(inheritable)").map((t: any) => t.text))
1718
.toEqual(["#label", "(", "inheritable", ")"]);
1819

19-
expect(attributeParser.lex("#label ( inheritable ) ").map(t => t.text))
20+
expect(attributeParser.lex("#label ( inheritable ) ").map((t: any) => t.text))
2021
.toEqual(["#label", "(", "inheritable", ")"]);
2122
});
2223

2324
it("label with value", () => {
24-
expect(attributeParser.lex("#label=Hallo").map(t => t.text))
25+
expect(attributeParser.lex("#label=Hallo").map((t: any) => t.text))
2526
.toEqual(["#label", "=", "Hallo"]);
2627
});
2728

@@ -32,25 +33,25 @@ describe("Lexing", () => {
3233
});
3334

3435
it("relation with value", () => {
35-
expect(attributeParser.lex('~relation=#root/RclIpMauTOKS/NFi2gL4xtPxM').map(t => t.text))
36+
expect(attributeParser.lex('~relation=#root/RclIpMauTOKS/NFi2gL4xtPxM').map((t: any) => t.text))
3637
.toEqual(["~relation", "=", "#root/RclIpMauTOKS/NFi2gL4xtPxM"]);
3738
});
3839

3940
it("use quotes to define value", () => {
40-
expect(attributeParser.lex("#'label a'='hello\"` world'").map(t => t.text))
41+
expect(attributeParser.lex("#'label a'='hello\"` world'").map((t: any) => t.text))
4142
.toEqual(["#label a", "=", 'hello"` world']);
4243

43-
expect(attributeParser.lex('#"label a" = "hello\'` world"').map(t => t.text))
44+
expect(attributeParser.lex('#"label a" = "hello\'` world"').map((t: any) => t.text))
4445
.toEqual(["#label a", "=", "hello'` world"]);
4546

46-
expect(attributeParser.lex('#`label a` = `hello\'" world`').map(t => t.text))
47+
expect(attributeParser.lex('#`label a` = `hello\'" world`').map((t: any) => t.text))
4748
.toEqual(["#label a", "=", "hello'\" world"]);
4849
});
4950
});
5051

5152
describe("Parser", () => {
5253
it("simple label", () => {
53-
const attrs = attributeParser.parse(["#token"].map(t => ({text: t})));
54+
const attrs = attributeParser.parse(["#token"].map((t: any) => ({text: t})));
5455

5556
expect(attrs.length).toEqual(1);
5657
expect(attrs[0].type).toEqual('label');
@@ -60,7 +61,7 @@ describe("Parser", () => {
6061
});
6162

6263
it("inherited label", () => {
63-
const attrs = attributeParser.parse(["#token", "(", "inheritable", ")"].map(t => ({text: t})));
64+
const attrs = attributeParser.parse(["#token", "(", "inheritable", ")"].map((t: any) => ({text: t})));
6465

6566
expect(attrs.length).toEqual(1);
6667
expect(attrs[0].type).toEqual('label');
@@ -70,7 +71,7 @@ describe("Parser", () => {
7071
});
7172

7273
it("label with value", () => {
73-
const attrs = attributeParser.parse(["#token", "=", "val"].map(t => ({text: t})));
74+
const attrs = attributeParser.parse(["#token", "=", "val"].map((t: any) => ({text: t})));
7475

7576
expect(attrs.length).toEqual(1);
7677
expect(attrs[0].type).toEqual('label');
@@ -79,14 +80,14 @@ describe("Parser", () => {
7980
});
8081

8182
it("relation", () => {
82-
let attrs = attributeParser.parse(["~token", "=", "#root/RclIpMauTOKS/NFi2gL4xtPxM"].map(t => ({text: t})));
83+
let attrs = attributeParser.parse(["~token", "=", "#root/RclIpMauTOKS/NFi2gL4xtPxM"].map((t: any) => ({text: t})));
8384

8485
expect(attrs.length).toEqual(1);
8586
expect(attrs[0].type).toEqual('relation');
8687
expect(attrs[0].name).toEqual("token");
8788
expect(attrs[0].value).toEqual('NFi2gL4xtPxM');
8889

89-
attrs = attributeParser.parse(["~token", "=", "#NFi2gL4xtPxM"].map(t => ({text: t})));
90+
attrs = attributeParser.parse(["~token", "=", "#NFi2gL4xtPxM"].map((t: any) => ({text: t})));
9091

9192
expect(attrs.length).toEqual(1);
9293
expect(attrs[0].type).toEqual('relation');

spec-es6/mini_test.js renamed to spec-es6/mini_test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
export function describe(name, cb) {
1+
export function describe(name: string, cb: () => any) {
22
console.log(`Running ${name}`);
33

44
cb();
55
}
66

7-
export async function it(name, cb) {
7+
export async function it(name: string, cb: () => any) {
88
console.log(` Running ${name}`);
99

1010
cb();
1111
}
1212

1313
let errorCount = 0;
1414

15-
export function expect(val) {
15+
export function expect(val: any) {
1616
return {
17-
toEqual: comparedVal => {
17+
toEqual: (comparedVal: any) => {
1818
const jsonVal = JSON.stringify(val);
1919
const comparedJsonVal = JSON.stringify(comparedVal);
2020

@@ -44,11 +44,11 @@ export function expect(val) {
4444
errorCount++;
4545
}
4646
},
47-
toThrow: errorMessage => {
47+
toThrow: (errorMessage: any) => {
4848
try {
4949
val();
5050
}
51-
catch (e) {
51+
catch (e: any) {
5252
if (e.message !== errorMessage) {
5353
console.trace("toThrow caught exception, but messages differ");
5454
console.error(`expected: ${errorMessage}`);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
declare module 'attribute_parser';
2+
3+
4+
export function lex(str: string): any[]
5+
export function parse(tokens: any[], str?: string, allowEmptyRelations?: boolean): any[]
6+
export function lexAndParse(str: string, allowEmptyRelations?: boolean): any[]
7+

src/public/app/services/attribute_parser.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import utils from "./utils.js";
1+
const utils = require("./utils.js");
22

33
function lex(str) {
44
str = str.trim();
@@ -222,7 +222,7 @@ function lexAndParse(str, allowEmptyRelations = false) {
222222
return parse(tokens, str, allowEmptyRelations);
223223
}
224224

225-
export default {
225+
module.exports = {
226226
lex,
227227
parse,
228228
lexAndParse

src/public/app/services/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ function createImageSrcUrl(note) {
505505
return `api/images/${note.noteId}/${encodeURIComponent(note.title)}?timestamp=${Date.now()}`;
506506
}
507507

508-
export default {
508+
module.exports = {
509509
reloadFrontendApp,
510510
parseDate,
511511
formatDateISO,

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"downlevelIteration": true,
1212
"skipLibCheck": true
1313
},
14-
"include": ["./src/**/*.js", "./src/**/*.ts", "./*.ts", "./spec/**/*.ts"],
14+
"include": ["./src/**/*.js", "./src/**/*.ts", "./*.ts", "./spec/**/*.ts", "./spec-es6/**/*.ts"],
1515
"exclude": ["./node_modules/**/*"],
1616
"ts-node": {
1717
"files": true

0 commit comments

Comments
 (0)