feat: implement adapter for node --test

This commit is contained in:
kbwo 2024-10-18 00:05:59 +09:00
parent d275c28e88
commit 8bfe0e9435
9 changed files with 1005 additions and 208 deletions

View file

@ -54,6 +54,14 @@
"exclude": []
}
],
"node-test": [
{
"path": "testing-ls-adapter",
"extra_arg": ["--test-kind=node-test"],
"include": ["/node-test/*.test.js"],
"exclude": []
}
],
"phpunit": [
{
"path": "testing-ls-adapter",
@ -66,5 +74,6 @@
}
}
},
"deno.enable": true
"deno.enable": false,
"tsserver.enable": false
}

View file

@ -1,5 +1,7 @@
const test = require("node:test");
const { describe, it } = require("node:test");
const assert = require("node:assert");
const { throwError } = require("./util.js");
// # Basic example
test("synchronous passing test", (t) => {
// This test passes because it does not throw an exception.
@ -165,3 +167,7 @@ describe.only("a suite", () => {
// This code is run.
});
});
test("import from external file. this must be fail", () => {
throwError();
});

View file

@ -1,149 +1,109 @@
<?xml version="1.0" encoding="utf-8"?>
<testsuites>
<testcase name="synchronous passing test" time="0.000709" classname="test" failure="assert is not defined">
<failure type="testCodeFailure" message="assert is not defined">
[Error [ERR_TEST_FAILURE]: assert is not defined] {
<testcase name="synchronous passing test" time="0.000819" classname="test"/>
<testcase name="synchronous failing test" time="0.001318" classname="test" failure="Expected values to be strictly equal:1 !== 2">
<failure type="testCodeFailure" message="Expected values to be strictly equal:1 !== 2">
[Error [ERR_TEST_FAILURE]: Expected values to be strictly equal:
1 !== 2
] {
failureType: 'testCodeFailure',
cause: ReferenceError [Error]: assert is not defined
at TestContext.&lt;anonymous> (/home/test-user/projects/testing-language-server/demo/node-test/index.test.js:6:3)
at Test.runInAsyncScope (node:async_hooks:203:9)
at Test.run (node:internal/test_runner/test:631:25)
at Test.start (node:internal/test_runner/test:542:17)
at startSubtest (node:internal/test_runner/harness:214:17),
code: 'ERR_TEST_FAILURE'
}
</failure>
</testcase>
<testcase name="synchronous failing test" time="0.000069" classname="test" failure="assert is not defined">
<failure type="testCodeFailure" message="assert is not defined">
[Error [ERR_TEST_FAILURE]: assert is not defined] {
failureType: 'testCodeFailure',
cause: ReferenceError [Error]: assert is not defined
at TestContext.&lt;anonymous> (/home/test-user/projects/testing-language-server/demo/node-test/index.test.js:11:3)
cause: AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
1 !== 2
at TestContext.&lt;anonymous> (/home/test-user/projects/testing-language-server/demo/node-test/index.test.js:13:10)
at Test.runInAsyncScope (node:async_hooks:203:9)
at Test.run (node:internal/test_runner/test:631:25)
at Test.processPendingSubtests (node:internal/test_runner/test:374:18)
at Test.postRun (node:internal/test_runner/test:715:19)
at Test.run (node:internal/test_runner/test:673:12)
at async startSubtest (node:internal/test_runner/harness:214:3),
at async startSubtest (node:internal/test_runner/harness:214:3) {
generatedMessage: true,
code: 'ERR_ASSERTION',
actual: 1,
expected: 2,
operator: 'strictEqual'
},
code: 'ERR_TEST_FAILURE'
}
</failure>
</testcase>
<testcase name="asynchronous passing test" time="0.000199" classname="test" failure="assert is not defined">
<failure type="testCodeFailure" message="assert is not defined">
[Error [ERR_TEST_FAILURE]: assert is not defined] {
<testcase name="asynchronous passing test" time="0.000764" classname="test"/>
<testcase name="asynchronous failing test" time="0.000411" classname="test" failure="Expected values to be strictly equal:1 !== 2">
<failure type="testCodeFailure" message="Expected values to be strictly equal:1 !== 2">
[Error [ERR_TEST_FAILURE]: Expected values to be strictly equal:
1 !== 2
] {
failureType: 'testCodeFailure',
cause: ReferenceError [Error]: assert is not defined
at TestContext.&lt;anonymous> (/home/test-user/projects/testing-language-server/demo/node-test/index.test.js:17:3)
cause: AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
1 !== 2
at TestContext.&lt;anonymous> (/home/test-user/projects/testing-language-server/demo/node-test/index.test.js:25:10)
at Test.runInAsyncScope (node:async_hooks:203:9)
at Test.run (node:internal/test_runner/test:631:25)
at Test.processPendingSubtests (node:internal/test_runner/test:374:18)
at Test.postRun (node:internal/test_runner/test:715:19)
at Test.run (node:internal/test_runner/test:673:12)
at async Test.processPendingSubtests (node:internal/test_runner/test:374:7),
at async Test.processPendingSubtests (node:internal/test_runner/test:374:7) {
generatedMessage: true,
code: 'ERR_ASSERTION',
actual: 1,
expected: 2,
operator: 'strictEqual'
},
code: 'ERR_TEST_FAILURE'
}
</failure>
</testcase>
<testcase name="asynchronous failing test" time="0.000082" classname="test" failure="assert is not defined">
<failure type="testCodeFailure" message="assert is not defined">
[Error [ERR_TEST_FAILURE]: assert is not defined] {
failureType: 'testCodeFailure',
cause: ReferenceError [Error]: assert is not defined
at TestContext.&lt;anonymous> (/home/test-user/projects/testing-language-server/demo/node-test/index.test.js:23:3)
at Test.runInAsyncScope (node:async_hooks:203:9)
at Test.run (node:internal/test_runner/test:631:25)
at Test.processPendingSubtests (node:internal/test_runner/test:374:18)
at Test.postRun (node:internal/test_runner/test:715:19)
at Test.run (node:internal/test_runner/test:673:12)
at async Test.processPendingSubtests (node:internal/test_runner/test:374:7),
code: 'ERR_TEST_FAILURE'
}
</failure>
</testcase>
<testcase name="failing test using Promises" time="0.005495" classname="test" failure="this will cause the test to fail">
<testcase name="failing test using Promises" time="0.005315" classname="test" failure="this will cause the test to fail">
<failure type="testCodeFailure" message="this will cause the test to fail">
[Error [ERR_TEST_FAILURE]: this will cause the test to fail] {
failureType: 'testCodeFailure',
cause: Error: this will cause the test to fail
at Immediate.&lt;anonymous> (/home/test-user/projects/testing-language-server/demo/node-test/index.test.js:30:14)
at Immediate.&lt;anonymous> (/home/test-user/projects/testing-language-server/demo/node-test/index.test.js:32:14)
at process.processImmediate (node:internal/timers:476:21),
code: 'ERR_TEST_FAILURE'
}
</failure>
</testcase>
<testcase name="callback passing test" time="0.000422" classname="test"/>
<testcase name="callback failing test" time="0.000314" classname="test" failure="callback failure">
<testcase name="callback passing test" time="0.000442" classname="test"/>
<testcase name="callback failing test" time="0.000283" classname="test" failure="callback failure">
<failure type="testCodeFailure" message="callback failure">
[Error [ERR_TEST_FAILURE]: callback failure] {
failureType: 'testCodeFailure',
cause: Error: callback failure
at Immediate.&lt;anonymous> (/home/test-user/projects/testing-language-server/demo/node-test/index.test.js:45:10)
at Immediate.&lt;anonymous> (/home/test-user/projects/testing-language-server/demo/node-test/index.test.js:47:10)
at process.processImmediate (node:internal/timers:476:21),
code: 'ERR_TEST_FAILURE'
}
</failure>
</testcase>
<testsuite name="top level test" time="0.000546" disabled="0" errors="0" tests="2" failures="2" skipped="0" hostname="test-user-xxx">
<testcase name="subtest 1" time="0.000082" classname="test" failure="assert is not defined">
<failure type="testCodeFailure" message="assert is not defined">
Error [ERR_TEST_FAILURE]: assert is not defined
at async TestContext.&lt;anonymous> (/home/test-user/projects/testing-language-server/demo/node-test/index.test.js:51:3) {
failureType: 'testCodeFailure',
cause: ReferenceError [Error]: assert is not defined
at TestContext.&lt;anonymous> (/home/test-user/projects/testing-language-server/demo/node-test/index.test.js:52:5)
at Test.runInAsyncScope (node:async_hooks:203:9)
at Test.run (node:internal/test_runner/test:631:25)
at Test.start (node:internal/test_runner/test:542:17)
at TestContext.test (node:internal/test_runner/test:167:20)
at TestContext.&lt;anonymous> (/home/test-user/projects/testing-language-server/demo/node-test/index.test.js:51:11)
at Test.runInAsyncScope (node:async_hooks:203:9)
at Test.run (node:internal/test_runner/test:631:25)
at Test.processPendingSubtests (node:internal/test_runner/test:374:18)
at Test.postRun (node:internal/test_runner/test:715:19),
code: 'ERR_TEST_FAILURE'
}
</failure>
</testcase>
<testcase name="subtest 2" time="0.000112" classname="test" failure="assert is not defined">
<failure type="testCodeFailure" message="assert is not defined">
Error [ERR_TEST_FAILURE]: assert is not defined
at async TestContext.&lt;anonymous> (/home/test-user/projects/testing-language-server/demo/node-test/index.test.js:55:3) {
failureType: 'testCodeFailure',
cause: ReferenceError [Error]: assert is not defined
at TestContext.&lt;anonymous> (/home/test-user/projects/testing-language-server/demo/node-test/index.test.js:56:5)
at Test.runInAsyncScope (node:async_hooks:203:9)
at Test.run (node:internal/test_runner/test:631:25)
at Test.start (node:internal/test_runner/test:542:17)
at TestContext.test (node:internal/test_runner/test:167:20)
at TestContext.&lt;anonymous> (/home/test-user/projects/testing-language-server/demo/node-test/index.test.js:55:11)
at async Test.run (node:internal/test_runner/test:632:9)
at async Test.processPendingSubtests (node:internal/test_runner/test:374:7),
code: 'ERR_TEST_FAILURE'
}
</failure>
</testcase>
<testsuite name="top level test" time="0.000468" disabled="0" errors="0" tests="2" failures="0" skipped="0" hostname="kbwo-21cbcto1ww">
<testcase name="subtest 1" time="0.000136" classname="test"/>
<testcase name="subtest 2" time="0.000058" classname="test"/>
</testsuite>
<testcase name="skip option" time="0.000047" classname="test">
<testcase name="skip option" time="0.000050" classname="test">
<skipped type="skipped" message="true"/>
</testcase>
<testcase name="skip option with message" time="0.000034" classname="test">
<testcase name="skip option with message" time="0.000038" classname="test">
<skipped type="skipped" message="this is skipped"/>
</testcase>
<testcase name="skip() method" time="0.000052" classname="test">
<skipped type="skipped" message="true"/>
</testcase>
<testcase name="skip() method with message" time="0.000082" classname="test">
<testcase name="skip() method with message" time="0.000043" classname="test">
<skipped type="skipped" message="this is skipped"/>
</testcase>
<testcase name="todo option" time="0.000052" classname="test" failure="this does not fail the test">
<testcase name="todo option" time="0.000053" classname="test" failure="this does not fail the test">
<skipped type="todo" message="true"/>
<failure type="testCodeFailure" message="this does not fail the test">
[Error [ERR_TEST_FAILURE]: this does not fail the test] {
failureType: 'testCodeFailure',
cause: Error: this does not fail the test
at TestContext.&lt;anonymous> (/home/test-user/projects/testing-language-server/demo/node-test/index.test.js:85:9)
at TestContext.&lt;anonymous> (/home/test-user/projects/testing-language-server/demo/node-test/index.test.js:87:9)
at Test.runInAsyncScope (node:async_hooks:203:9)
at Test.run (node:internal/test_runner/test:631:25)
at Test.processPendingSubtests (node:internal/test_runner/test:374:18)
@ -154,19 +114,19 @@ Error [ERR_TEST_FAILURE]: assert is not defined
}
</failure>
</testcase>
<testcase name="todo option with message" time="0.000093" classname="test">
<testcase name="todo option with message" time="0.000040" classname="test">
<skipped type="todo" message="this is a todo test"/>
</testcase>
<testcase name="todo() method" time="0.000090" classname="test">
<testcase name="todo() method" time="0.000134" classname="test">
<skipped type="todo" message="true"/>
</testcase>
<testcase name="todo() method with message" time="0.000054" classname="test" failure="this does not fail the test">
<testcase name="todo() method with message" time="0.000067" classname="test" failure="this does not fail the test">
<skipped type="todo" message="this is a todo test and is not treated as a failure"/>
<failure type="testCodeFailure" message="this does not fail the test">
[Error [ERR_TEST_FAILURE]: this does not fail the test] {
failureType: 'testCodeFailure',
cause: Error: this does not fail the test
at TestContext.&lt;anonymous> (/home/test-user/projects/testing-language-server/demo/node-test/index.test.js:99:9)
at TestContext.&lt;anonymous> (/home/test-user/projects/testing-language-server/demo/node-test/index.test.js:101:9)
at Test.runInAsyncScope (node:async_hooks:203:9)
at Test.run (node:internal/test_runner/test:631:25)
at Test.processPendingSubtests (node:internal/test_runner/test:374:18)
@ -177,88 +137,33 @@ Error [ERR_TEST_FAILURE]: assert is not defined
}
</failure>
</testcase>
<testsuite name="A thing" time="0.000522" disabled="0" errors="0" tests="3" failures="3" skipped="1" hostname="test-user-xxx">
<testcase name="should work" time="0.000110" classname="test" failure="assert is not defined">
<failure type="testCodeFailure" message="assert is not defined">
Error [ERR_TEST_FAILURE]: assert is not defined
at async Promise.all (index 0) {
failureType: 'testCodeFailure',
cause: ReferenceError [Error]: assert is not defined
at TestContext.&lt;anonymous> (/home/test-user/projects/testing-language-server/demo/node-test/index.test.js:105:5)
at Test.runInAsyncScope (node:async_hooks:203:9)
at Test.run (node:internal/test_runner/test:631:25)
at Test.start (node:internal/test_runner/test:542:17)
at node:internal/test_runner/test:946:71
at node:internal/per_context/primordials:487:82
at new Promise (&lt;anonymous>)
at new SafePromise (node:internal/per_context/primordials:455:29)
at node:internal/per_context/primordials:487:9
at Array.map (&lt;anonymous>),
code: 'ERR_TEST_FAILURE'
}
</failure>
</testcase>
<testcase name="should be ok" time="0.000053" classname="test" failure="assert is not defined">
<failure type="testCodeFailure" message="assert is not defined">
[Error [ERR_TEST_FAILURE]: assert is not defined] {
failureType: 'testCodeFailure',
cause: ReferenceError [Error]: assert is not defined
at TestContext.&lt;anonymous> (/home/test-user/projects/testing-language-server/demo/node-test/index.test.js:109:5)
at Test.runInAsyncScope (node:async_hooks:203:9)
at Test.run (node:internal/test_runner/test:631:25)
at Suite.processPendingSubtests (node:internal/test_runner/test:374:18)
at Test.postRun (node:internal/test_runner/test:715:19)
at Test.run (node:internal/test_runner/test:673:12)
at async Promise.all (index 0)
at async Suite.run (node:internal/test_runner/test:948:7)
at async Test.processPendingSubtests (node:internal/test_runner/test:374:7),
code: 'ERR_TEST_FAILURE'
}
</failure>
</testcase>
<testsuite name="a nested thing" time="0.000125" disabled="0" errors="0" tests="1" failures="1" skipped="0" hostname="test-user-xxx">
<testcase name="should work" time="0.000054" classname="test" failure="assert is not defined">
<failure type="testCodeFailure" message="assert is not defined">
Error [ERR_TEST_FAILURE]: assert is not defined
at async Promise.all (index 0) {
failureType: 'testCodeFailure',
cause: ReferenceError [Error]: assert is not defined
at TestContext.&lt;anonymous> (/home/test-user/projects/testing-language-server/demo/node-test/index.test.js:114:7)
at Test.runInAsyncScope (node:async_hooks:203:9)
at Test.run (node:internal/test_runner/test:631:25)
at Test.start (node:internal/test_runner/test:542:17)
at node:internal/test_runner/test:946:71
at node:internal/per_context/primordials:487:82
at new Promise (&lt;anonymous>)
at new SafePromise (node:internal/per_context/primordials:455:29)
at node:internal/per_context/primordials:487:9
at Array.map (&lt;anonymous>),
code: 'ERR_TEST_FAILURE'
}
</failure>
</testcase>
<testsuite name="A thing" time="0.000482" disabled="0" errors="0" tests="3" failures="0" skipped="0" hostname="kbwo-21cbcto1ww">
<testcase name="should work" time="0.000108" classname="test"/>
<testcase name="should be ok" time="0.000041" classname="test"/>
<testsuite name="a nested thing" time="0.000099" disabled="0" errors="0" tests="1" failures="0" skipped="0" hostname="kbwo-21cbcto1ww">
<testcase name="should work" time="0.000046" classname="test"/>
</testsuite>
</testsuite>
<testsuite name="this test is run" time="0.000471" disabled="0" errors="0" tests="6" failures="0" skipped="1" hostname="test-user-xxx">
<testcase name="running subtest" time="0.000043" classname="test"/>
<testcase name="this subtest is now skipped" time="0.000063" classname="test"/>
<testsuite name="this test is run" time="0.000507" disabled="0" errors="0" tests="6" failures="0" skipped="1" hostname="kbwo-21cbcto1ww">
<testcase name="running subtest" time="0.000051" classname="test"/>
<testcase name="this subtest is now skipped" time="0.000025" classname="test"/>
<!-- 'only' and 'runOnly' require the &#45;&#45;test-only command-line option. -->
<testcase name="this subtest is run" time="0.000026" classname="test"/>
<testcase name="this subtest is run" time="0.000023" classname="test"/>
<!-- 'only' and 'runOnly' require the &#45;&#45;test-only command-line option. -->
<testcase name="this subtest is now run" time="0.000019" classname="test"/>
<testcase name="skipped subtest 3" time="0.000018" classname="test"/>
<testcase name="this subtest is now run" time="0.000022" classname="test"/>
<testcase name="skipped subtest 3" time="0.000019" classname="test"/>
<!-- 'only' and 'runOnly' require the &#45;&#45;test-only command-line option. -->
<testcase name="skipped subtest 4" time="0.000017" classname="test">
<testcase name="skipped subtest 4" time="0.000029" classname="test">
<skipped type="skipped" message="true"/>
</testcase>
</testsuite>
<!-- 'only' and 'runOnly' require the &#45;&#45;test-only command-line option. -->
<testcase name="this test is not run" time="0.000048" classname="test" failure="fail">
<testcase name="this test is not run" time="0.000057" classname="test" failure="fail">
<failure type="testCodeFailure" message="fail">
[Error [ERR_TEST_FAILURE]: fail] {
failureType: 'testCodeFailure',
cause: Error: fail
at TestContext.&lt;anonymous> (/home/test-user/projects/testing-language-server/demo/node-test/index.test.js:143:9)
at TestContext.&lt;anonymous> (/home/test-user/projects/testing-language-server/demo/node-test/index.test.js:145:9)
at Test.runInAsyncScope (node:async_hooks:203:9)
at Test.run (node:internal/test_runner/test:631:25)
at Test.processPendingSubtests (node:internal/test_runner/test:374:18)
@ -269,15 +174,15 @@ Error [ERR_TEST_FAILURE]: assert is not defined
}
</failure>
</testcase>
<testsuite name="a suite" time="0.000180" disabled="0" errors="0" tests="2" failures="1" skipped="0" hostname="test-user-xxx">
<testcase name="this test is run" time="0.000038" classname="test"/>
<testsuite name="a suite" time="0.000167" disabled="0" errors="0" tests="2" failures="1" skipped="0" hostname="kbwo-21cbcto1ww">
<testcase name="this test is run" time="0.000044" classname="test"/>
<!-- 'only' and 'runOnly' require the &#45;&#45;test-only command-line option. -->
<testcase name="this test is not run" time="0.000033" classname="test" failure="fail">
<testcase name="this test is not run" time="0.000040" classname="test" failure="fail">
<failure type="testCodeFailure" message="fail">
[Error [ERR_TEST_FAILURE]: fail] {
failureType: 'testCodeFailure',
cause: Error: fail
at TestContext.&lt;anonymous> (/home/test-user/projects/testing-language-server/demo/node-test/index.test.js:154:11)
at TestContext.&lt;anonymous> (/home/test-user/projects/testing-language-server/demo/node-test/index.test.js:156:11)
at Test.runInAsyncScope (node:async_hooks:203:9)
at Test.run (node:internal/test_runner/test:631:25)
at Suite.processPendingSubtests (node:internal/test_runner/test:374:18)
@ -291,17 +196,34 @@ Error [ERR_TEST_FAILURE]: assert is not defined
</failure>
</testcase>
</testsuite>
<testsuite name="a suite" time="0.000118" disabled="0" errors="0" tests="2" failures="0" skipped="0" hostname="test-user-xxx">
<testsuite name="a suite" time="0.000180" disabled="0" errors="0" tests="2" failures="0" skipped="0" hostname="kbwo-21cbcto1ww">
<testcase name="this test is run" time="0.000038" classname="test"/>
<testcase name="this test is run" time="0.000023" classname="test"/>
<testcase name="this test is run" time="0.000028" classname="test"/>
</testsuite>
<!-- 'only' and 'runOnly' require the &#45;&#45;test-only command-line option. -->
<!-- tests 33 -->
<testcase name="must be fail" time="0.000055" classname="test" failure="this will cause the test to fail">
<failure type="testCodeFailure" message="this will cause the test to fail">
[Error [ERR_TEST_FAILURE]: this will cause the test to fail] {
failureType: 'testCodeFailure',
cause: Error: this will cause the test to fail
at throwError (/home/test-user/projects/testing-language-server/demo/node-test/util.js:2:9)
at TestContext.&lt;anonymous> (/home/test-user/projects/testing-language-server/demo/node-test/index.test.js:172:3)
at Test.runInAsyncScope (node:async_hooks:203:9)
at Test.run (node:internal/test_runner/test:631:25)
at Test.processPendingSubtests (node:internal/test_runner/test:374:18)
at Suite.postRun (node:internal/test_runner/test:715:19)
at Suite.run (node:internal/test_runner/test:962:10)
at async Test.processPendingSubtests (node:internal/test_runner/test:374:7),
code: 'ERR_TEST_FAILURE'
}
</failure>
</testcase>
<!-- tests 34 -->
<!-- suites 4 -->
<!-- pass 10 -->
<!-- fail 14 -->
<!-- pass 18 -->
<!-- fail 7 -->
<!-- cancelled 0 -->
<!-- skipped 5 -->
<!-- todo 4 -->
<!-- duration_ms 57.894356 -->
<!-- duration_ms 65.919879 -->
</testsuites>

5
demo/node-test/util.js Normal file
View file

@ -0,0 +1,5 @@
const throwError = () => {
throw new Error("this will cause the test to fail");
};
module.exports = { throwError };