Edoardo Luppi
02/22/2024, 9:27 PM@JsExport
fun run(): Promise<Void>? {
val mocha = Mocha(jso {
ui = Interface.tdd
color = true
})
val testsRoot = path.resolve(js("__dirname") as String)
mocha.addFile(path.resolve(testsRoot, "tests.mjs"))
try {
return Promise { c, e ->
mocha.run { ... }
}
} catch (e: Throwable) {
console.error(e)
return null
}
}
And your actual tests:
@Suppress("DEPRECATION")
@EagerInitialization
val e = {
suite("Extension Test Suite") {
test("Sample test") {
println("OK!")
}
}
}
The @EagerInitialization
bit is required so that the function gets executed immediately.
It's a bit messy to look at, but I haven't found other solutionsArtem Kobzar
02/23/2024, 9:51 AMMocha
in kotlin.test by default, am I right?Ilya Goncharov [JB]
02/23/2024, 9:52 AMArtem Kobzar
02/23/2024, 9:57 AMval e = {
suite("Extension Test Suite") {
test("Sample test") {
println("OK!")
}
}
}
Edoardo Luppi
02/23/2024, 10:44 AMcode --extensionDevelopmentPath=... --extensionTestsPath=.../src/test/suite/index
Where index
is the compiled index.kt
file that contains
@JsExport
fun run(): Promise<Void>? { ...
I couldn't find a solution to do this using the standard way of starting testsEdoardo Luppi
02/23/2024, 10:44 AMEdoardo Luppi
02/23/2024, 10:48 AMArtem Kobzar
02/23/2024, 10:48 AMIlya Goncharov [JB]
02/23/2024, 7:12 PMEdoardo Luppi
02/23/2024, 7:18 PMrun
method in the JS script, as its entry point.Ilya Goncharov [JB]
02/23/2024, 7:28 PMEdoardo Luppi
02/23/2024, 7:29 PMIlya Goncharov [JB]
02/23/2024, 7:29 PMrun
method is okay, but why do you need the second part, when you are using EagerInitialization
? I mean kotlin compiler generates side effects for kotlin testIlya Goncharov [JB]
02/23/2024, 7:30 PMEdoardo Luppi
02/23/2024, 7:31 PMEdoardo Luppi
02/23/2024, 7:32 PMEdoardo Luppi
02/23/2024, 8:50 PMIlya Goncharov [JB]
02/26/2024, 11:02 AMkotlin-test
library
Because for example this
class Foo {
@Test
fun foo() {
println("OK")
}
}
will be compiled to
suite('Foo', () => {
test('foo', () => {
println("OK")
});
});
It looks like what VS code expects from tests
So, ``--extensionDevelopmentPath` has to point onto your extension executable file, and --extensionTestsPath
has to point onto your runner, and inside your runner, you should point your test file.
But as I understand you can use easier way with @vscode/test-electron
package (https://code.visualstudio.com/api/working-with-extensions/testing-extension#advanced-setup-your-own-runner)
It does not require to operate with Mocha
instanceEdoardo Luppi
02/26/2024, 11:10 AMBut as I understand, you can write tests just withIt is true that kotlin-test compiles down to a Mocha test suite. However, currently I see no way of communicating the test results to the VS Code instance. The runner script returns a Promise with test results from alibrarykotlin-test
run
function:
return new Promise((resolve, reject) => {
try {
mocha.run(failures => {
if (failures > 0) {
reject(new Error(`${failures} tests failed.`));
} else {
resolve();
}
});
} catch (err) {
reject(err);
}
});
That's the part I'm missing.
Since the outputted JS test file doesn't have a run
entry point, I don't see how VS Code can be made aware of those test suitesIlya Goncharov [JB]
02/26/2024, 11:25 AMvoid
, because from lambda under run
there is no return
statement.
As I understand just running mocha via cli, just returns the same mocha.run
I’d say I don’t understand how VS code now may know results because returning Promise is void.Edoardo Luppi
02/26/2024, 11:27 AMEdoardo Luppi
03/01/2024, 11:18 AM*-test.js
files doesn't work unfortunately.
Error: Path file:///c%3A/Users/edoardo.luppi/IdeaProjects/client-vscode/build/js/packages/client-vscode-extension-kotlin-test/kotlin/client-vscode-extension-kotlin-test does not point to a valid extension test runner.
at g.qb (c:\Users\edoardo.luppi\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:156:15485)
at async g.$extensionTestsExecute (c:\Users\edoardo.luppi\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:156:15203) {stack: 'Error: Path file:///c%3A/Users/edoardo.luppi/…h\api\node\extensionHostProcess.js:156:15203)', message: 'Path file:///c%3A/Users/edoardo.luppi/IdeaPr… not point to a valid extension test runner.'}
When you use the VS Code launch configuration for tests, as said it uses --extensionTestsPath
which internally uses the same approach as vscode-test
, see https://github.com/microsoft/vscode-test/blob/bc400a29fbd3d54496bbcc7e9cbe5f687880471f/lib/runTest.ts#L78
So the entry point with a Promise<void>
is mandatory.Edoardo Luppi
03/01/2024, 5:42 PM@MochaTest
.
Almost got it to workturansky
03/01/2024, 7:16 PMPromise<void>
is mandatory.
It's already solved by coroutines-test
.
For async tests you can use runTest
.
Modified call runTest
call example is here.
But you can use runTest
directly.Edoardo Luppi
03/01/2024, 7:17 PMrun
function? Because the name of the function is importantturansky
03/01/2024, 7:19 PMexternal interface MochaTestBase {
fun run(): Promise<Void>
}
?Edoardo Luppi
03/01/2024, 7:22 PMturansky
03/01/2024, 7:23 PMEdoardo Luppi
03/01/2024, 7:34 PMrun
function. See the screenshot aboveturansky
03/01/2024, 7:44 PM