From 80bb7af08c700862fc524b48fce6b1aa60fa1d7a Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Thu, 26 Oct 2023 18:49:15 +0200 Subject: [PATCH] node: Fix typescript setup for tests Share tsconfig.json so that ava runs the typescript compiler also on the tests. Similary, the syntax check now also covers the tests. Sadly, the exception that the Slint compiler throws is not type declared, so we have to use any. Similarly, the object share returned by loadFile() is unknown in terms of properties, callbacks, etc. --- api/node/__test__/api.spec.ts | 14 +++++++------- api/node/__test__/compiler.spec.ts | 14 +++++++------- api/node/__test__/js_value_conversion.spec.ts | 2 +- api/node/package.json | 2 +- api/node/tsconfig.json | 6 ++++++ 5 files changed, 22 insertions(+), 16 deletions(-) create mode 100644 api/node/tsconfig.json diff --git a/api/node/__test__/api.spec.ts b/api/node/__test__/api.spec.ts index 2637d0ffb..38d7b7166 100644 --- a/api/node/__test__/api.spec.ts +++ b/api/node/__test__/api.spec.ts @@ -7,16 +7,16 @@ const path = require('node:path'); import { loadFile, CompileError } from '../index' test('loadFile', (t) => { - let demo = loadFile(path.join(__dirname, "resources/test.slint")); + let demo = loadFile(path.join(__dirname, "resources/test.slint")) as any; let test = new demo.Test(); t.is(test.check, "Test"); let errorPath = path.join(__dirname, "resources/error.slint"); const error = t.throws(() => { - loadFile(errorPath) - }, - {instanceOf: CompileError} + loadFile(errorPath) + }, + { instanceOf: CompileError } ); t.is(error?.message, "Could not compile " + errorPath); @@ -46,12 +46,12 @@ test('loadFile', (t) => { }) test('constructor parameters', (t) => { - let demo = loadFile(path.join(__dirname, "resources/test-constructor.slint")); + let demo = loadFile(path.join(__dirname, "resources/test-constructor.slint")) as any; let hello = ""; - let test = new demo.Test({ say_hello: function() { hello = "hello"; }, check: "test"}); + let test = new demo.Test({ say_hello: function () { hello = "hello"; }, check: "test" }); test.say_hello(); t.is(test.check, "test"); t.is(hello, "hello"); -}) \ No newline at end of file +}) diff --git a/api/node/__test__/compiler.spec.ts b/api/node/__test__/compiler.spec.ts index 62025ba57..91031f4b8 100644 --- a/api/node/__test__/compiler.spec.ts +++ b/api/node/__test__/compiler.spec.ts @@ -19,13 +19,13 @@ test('get/set library paths', (t) => { let compiler = new private_api.ComponentCompiler; compiler.libraryPaths = { - "libfile.slint" : "third_party/libfoo/ui/lib.slint", - "libdir" : "third_party/libbar/ui/", + "libfile.slint": "third_party/libfoo/ui/lib.slint", + "libdir": "third_party/libbar/ui/", }; t.deepEqual(compiler.libraryPaths, { - "libfile.slint" : "third_party/libfoo/ui/lib.slint", - "libdir" : "third_party/libbar/ui/", + "libfile.slint": "third_party/libfoo/ui/lib.slint", + "libdir": "third_party/libbar/ui/", }); }) @@ -241,13 +241,13 @@ test('non-existent properties and callbacks', (t) => { const prop_err = t.throws(() => { instance!.setProperty("non-existent", 42); - }); + }) as any; t.is(prop_err!.code, 'GenericFailure'); t.is(prop_err!.message, 'Property non-existent not found in the component'); const callback_err = t.throws(() => { instance!.setCallback("non-existent-callback", () => { }); - }); + }) as any; t.is(callback_err!.code, 'GenericFailure'); t.is(callback_err!.message, 'Callback non-existent-callback not found in the component'); -}) \ No newline at end of file +}) diff --git a/api/node/__test__/js_value_conversion.spec.ts b/api/node/__test__/js_value_conversion.spec.ts index 032fe4b52..46aae9ce5 100644 --- a/api/node/__test__/js_value_conversion.spec.ts +++ b/api/node/__test__/js_value_conversion.spec.ts @@ -157,7 +157,7 @@ test('set struct properties', (t) => { }, { instanceOf: Error } - ); + ) as any; t.is(incomplete_struct_err!.code, 'InvalidArg'); t.is(incomplete_struct_err!.message, 'expect Number, got: Undefined'); diff --git a/api/node/package.json b/api/node/package.json index 6c11978a2..e6f701135 100644 --- a/api/node/package.json +++ b/api/node/package.json @@ -30,7 +30,7 @@ "install": "npm run build", "docs": "npm run build && typedoc --hideGenerator --treatWarningsAsErrors --readme cover.md index.ts", "test": "ava", - "syntax_check": "tsc -noEmit index.ts" + "syntax_check": "tsc -noEmit" }, "ava": { "require": [ diff --git a/api/node/tsconfig.json b/api/node/tsconfig.json new file mode 100644 index 000000000..09d960629 --- /dev/null +++ b/api/node/tsconfig.json @@ -0,0 +1,6 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "esnext" + } +}