Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No tests listed using tsx loader #250

Open
Danielku15 opened this issue Oct 21, 2023 · 2 comments
Open

No tests listed using tsx loader #250

Danielku15 opened this issue Oct 21, 2023 · 2 comments

Comments

@Danielku15
Copy link

I have the following setup and no tests are listed in the test explorer. Not sure what could be the cause and I had once a similar to same setup working and running. I lately upgraded Node.js so that could be related.

image

Files

.vscode/settings.json
{
    "mochaExplorer.files": "test/**/*.test.ts",
    "mochaExplorer.nodeArgv": [
        "--experimental-specifier-resolution=node",
        "--loader=tsx",
        "--no-warnings=ExperimentalWarning",
    ],
    "mochaExplorer.logpanel": true
}
tests/rules.test.ts
describe("Suite", () => {
    it('Test', () => {
        
    });
});
.mocharc.json
{
    "extension": [
        "ts"
    ],
    "node-option": [
        "experimental-specifier-resolution=node",
        "loader=tsx",
        "no-warnings=ExperimentalWarning"
    ],
    "spec": "test/**/*.test.ts"
}
package.json
{
    "name": "test",
    "version": "1.0.0",
    "description": "",
    "scripts": {
        "test": "mocha"
    },
    "dependencies": {},
    "devDependencies": {
        "@types/node": "^20.8.7",
        "@types/mocha": "^10.0.3",
        "assert": "^2.1.0",
        "mocha": "^10.2.0",
        "tsx": "^3.14.0",
        "typescript": "^5.2.2"
    }
}

Running Tests

npm run test
PS D:\Dev\mocha-test-explorer> npm run test

> [email protected] test
> mocha



  Suite
    ✔ Test


  1 passing (3ms)
Mocha Explorer Log
[2023-10-21 10:02:19.969] [INFO] Loading test files of d:\Dev\mocha-test-explorer
[2023-10-21 10:02:19.969] [DEBUG] Using working directory: D:\Dev\mocha-test-explorer
[2023-10-21 10:02:20.036] [DEBUG] Using nodePath: C:\Program Files\nodejs\node.exe
[2023-10-21 10:02:20.169] [DEBUG] Using Mocha options: {"ui":"bdd","timeout":null,"retries":0,"requires":[],"delay":false,"fullTrace":false,"exit":false,"asyncOnly":false,"parallel":false}
[2023-10-21 10:02:20.170] [DEBUG] Looking for test files ["test/**/*.test.ts"] in d:\Dev\mocha-test-explorer
[2023-10-21 10:02:20.171] [DEBUG] Found test files ["D:\\Dev\\mocha-test-explorer\\test\\rules.test.ts"]
[2023-10-21 10:02:20.171] [DEBUG] Using environment variables from config: {}
[2023-10-21 10:02:20.171] [DEBUG] Spawning c:\Users\Daniel\.vscode\extensions\hbenl.vscode-mocha-test-adapter-2.14.1\out\worker\bundle.js with IPC options {}
[2023-10-21 10:02:20.300] [INFO] Received error from worker
[2023-10-21 10:02:20.317] [INFO] Worker: Using the mocha package at D:\Dev\mocha-test-explorer\node_modules\mocha
[2023-10-21 10:02:20.317] [INFO] Received error from worker
[2023-10-21 10:02:20.318] [INFO] Received error from worker
[2023-10-21 10:02:20.321] [INFO] Received error from worker
[2023-10-21 10:02:20.322] [INFO] Received error from worker
[2023-10-21 10:02:20.323] [INFO] Received error from worker
[2023-10-21 10:02:20.324] [INFO] Received error from worker
[2023-10-21 10:02:20.325] [INFO] Received error from worker
[2023-10-21 10:02:20.327] [INFO] Received error from worker
[2023-10-21 10:02:20.328] [INFO] Received error from worker
[2023-10-21 10:02:20.329] [INFO] Received error from worker
[2023-10-21 10:02:20.330] [INFO] Received error from worker
[2023-10-21 10:02:20.331] [INFO] Received error from worker
[2023-10-21 10:02:20.332] [INFO] Received error from worker
[2023-10-21 10:02:20.333] [INFO] Received error from worker
[2023-10-21 10:02:20.334] [INFO] Received error from worker
[2023-10-21 10:02:20.335] [INFO] Received error from worker
[2023-10-21 10:02:20.337] [INFO] Received error from worker
[2023-10-21 10:02:20.338] [INFO] Received error from worker
[2023-10-21 10:02:20.340] [INFO] Received error from worker
[2023-10-21 10:02:20.342] [INFO] Received error from worker
[2023-10-21 10:02:20.343] [INFO] Received error from worker
[2023-10-21 10:02:20.345] [INFO] Received error from worker
[2023-10-21 10:02:20.345] [INFO] Received error from worker
[2023-10-21 10:02:20.346] [INFO] Received error from worker
[2023-10-21 10:02:20.348] [INFO] Received error from worker
[2023-10-21 10:02:20.350] [INFO] Received error from worker
[2023-10-21 10:02:20.351] [INFO] Received error from worker
[2023-10-21 10:02:20.361] [INFO] Received error from worker
[2023-10-21 10:02:20.363] [INFO] Received error from worker
[2023-10-21 10:02:20.365] [INFO] Received error from worker
[2023-10-21 10:02:20.366] [INFO] Received error from worker
[2023-10-21 10:02:20.368] [INFO] Received error from worker
[2023-10-21 10:02:20.370] [INFO] Received error from worker
[2023-10-21 10:02:20.372] [INFO] Received error from worker
[2023-10-21 10:02:20.374] [INFO] Received error from worker
[2023-10-21 10:02:20.375] [INFO] Received error from worker
[2023-10-21 10:02:20.381] [INFO] Received error from worker
[2023-10-21 10:02:20.382] [INFO] Received error from worker
[2023-10-21 10:02:20.383] [INFO] Received error from worker
[2023-10-21 10:02:20.385] [INFO] Received error from worker
[2023-10-21 10:02:20.387] [INFO] Received error from worker
[2023-10-21 10:02:20.389] [INFO] Received error from worker
[2023-10-21 10:02:20.391] [INFO] Received error from worker
[2023-10-21 10:02:20.393] [INFO] Received error from worker
[2023-10-21 10:02:20.395] [INFO] Received error from worker
[2023-10-21 10:02:20.397] [INFO] Received error from worker
[2023-10-21 10:02:20.398] [INFO] Received error from worker
[2023-10-21 10:02:20.399] [INFO] Received error from worker
[2023-10-21 10:02:20.401] [INFO] Received error from worker
[2023-10-21 10:02:20.402] [INFO] Received error from worker
[2023-10-21 10:02:20.404] [INFO] Received error from worker
[2023-10-21 10:02:20.405] [INFO] Received error from worker
[2023-10-21 10:02:20.407] [INFO] Received error from worker
[2023-10-21 10:02:20.408] [INFO] Received error from worker
[2023-10-21 10:02:20.409] [INFO] Received error from worker
[2023-10-21 10:02:20.411] [INFO] Received error from worker
[2023-10-21 10:02:20.412] [INFO] Received error from worker
[2023-10-21 10:02:20.413] [INFO] Received error from worker
[2023-10-21 10:02:20.414] [INFO] Received error from worker
[2023-10-21 10:02:20.415] [INFO] Received error from worker
[2023-10-21 10:02:20.417] [INFO] Received error from worker
[2023-10-21 10:02:20.418] [INFO] Received error from worker
[2023-10-21 10:02:20.419] [INFO] Received error from worker
[2023-10-21 10:02:20.420] [INFO] Received error from worker
[2023-10-21 10:02:20.421] [INFO] Received error from worker
[2023-10-21 10:02:20.422] [INFO] Received error from worker
[2023-10-21 10:02:20.423] [INFO] Received error from worker
[2023-10-21 10:02:20.424] [INFO] Received error from worker
[2023-10-21 10:02:20.424] [INFO] Received error from worker
[2023-10-21 10:02:20.427] [INFO] Received error from worker
[2023-10-21 10:02:20.427] [INFO] Worker: Patching Mocha
[2023-10-21 10:02:20.428] [INFO] Worker: Loading files
[2023-10-21 10:02:20.428] [INFO] Worker: Trying to use Mocha's experimental ESM module loader
[2023-10-21 10:02:20.429] [INFO] Received error from worker
[2023-10-21 10:02:20.430] [INFO] Worker: Patching describe
[2023-10-21 10:02:20.430] [INFO] Worker: Patching describe.skip
[2023-10-21 10:02:20.430] [INFO] Worker: Patching describe.only
[2023-10-21 10:02:20.430] [INFO] Worker: Patching it
[2023-10-21 10:02:20.430] [INFO] Worker: Patching it.only
[2023-10-21 10:02:20.430] [INFO] Worker: Patching it.skip
[2023-10-21 10:02:20.430] [INFO] Worker: Patching context
[2023-10-21 10:02:20.430] [INFO] Worker: Patching context.skip
[2023-10-21 10:02:20.430] [INFO] Worker: Patching context.only
[2023-10-21 10:02:20.430] [INFO] Worker: Patching specify
[2023-10-21 10:02:20.430] [INFO] Worker: Patching specify.only
[2023-10-21 10:02:20.430] [INFO] Worker: Patching specify.skip
[2023-10-21 10:02:20.430] [INFO] Worker: Patching describe
[2023-10-21 10:02:20.431] [INFO] Worker: Patching describe.skip
[2023-10-21 10:02:20.431] [INFO] Worker: Patching describe.only
[2023-10-21 10:02:20.431] [INFO] Worker: Patching it
[2023-10-21 10:02:20.431] [INFO] Worker: Patching it.only
[2023-10-21 10:02:20.431] [INFO] Worker: Patching it.skip
[2023-10-21 10:02:20.431] [INFO] Worker: Patching context
[2023-10-21 10:02:20.431] [INFO] Worker: Patching context.skip
[2023-10-21 10:02:20.431] [INFO] Worker: Patching context.only
[2023-10-21 10:02:20.431] [INFO] Worker: Patching specify
[2023-10-21 10:02:20.431] [INFO] Worker: Patching specify.only
[2023-10-21 10:02:20.431] [INFO] Worker: Patching specify.skip
[2023-10-21 10:02:20.432] [INFO] Received error from worker
[2023-10-21 10:02:20.477] [INFO] Worker: Looking for D:\Dev\mocha-test-explorer\test\rules.test.ts in Error
    at findCallLocation (c:\Users\Daniel\.vscode\extensions\hbenl.vscode-mocha-test-adapter-2.14.1\out\worker\bundle.js:918:17)
    at <anonymous> (c:\Users\Daniel\.vscode\extensions\hbenl.vscode-mocha-test-adapter-2.14.1\out\worker\bundle.js:909:30)
    at Suite.<anonymous> (d:\Dev\mocha-test-explorer\test\rules.test.ts:2:5)
    at Object.create (d:\Dev\mocha-test-explorer\node_modules\mocha\lib\interfaces\common.js:148:19)
    at context.describe.context.context (d:\Dev\mocha-test-explorer\node_modules\mocha\lib\interfaces\bdd.js:42:27)
    at <anonymous> (c:\Users\Daniel\.vscode\extensions\hbenl.vscode-mocha-test-adapter-2.14.1\out\worker\bundle.js:907:37)
    at <anonymous> (d:\Dev\mocha-test-explorer\test\rules.test.ts:1:1)
    at Object.<anonymous> (d:\Dev\mocha-test-explorer\test\rules.test.ts:5:2)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Object.j (D:\Dev\mocha-test-explorer\node_modules\tsx\dist\cjs\index.cjs:1:1197)
[2023-10-21 10:02:20.482] [INFO] Worker: Looking for D:\Dev\mocha-test-explorer\test\rules.test.ts in Error
    at findCallLocation (c:\Users\Daniel\.vscode\extensions\hbenl.vscode-mocha-test-adapter-2.14.1\out\worker\bundle.js:918:17)
    at <anonymous> (c:\Users\Daniel\.vscode\extensions\hbenl.vscode-mocha-test-adapter-2.14.1\out\worker\bundle.js:909:30)
    at <anonymous> (d:\Dev\mocha-test-explorer\test\rules.test.ts:1:1)
    at Object.<anonymous> (d:\Dev\mocha-test-explorer\test\rules.test.ts:5:2)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Object.j (D:\Dev\mocha-test-explorer\node_modules\tsx\dist\cjs\index.cjs:1:1197)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:169:29)
    at ModuleJob.run (node:internal/modules/esm/module_job:194:25)
[2023-10-21 10:02:20.484] [INFO] Worker (stdout): 

[2023-10-21 10:02:20.484] [INFO] Worker (stdout): 

[2023-10-21 10:02:20.485] [INFO] Worker (stdout):   0 passing (1ms)

[2023-10-21 10:02:20.485] [INFO] Worker (stdout): 

[2023-10-21 10:02:20.485] [INFO] Worker: Converting tests and suites
[2023-10-21 10:02:20.485] [INFO] Received tests from worker
[2023-10-21 10:02:20.486] [INFO] Received error from worker
[2023-10-21 10:02:20.495] [INFO] Worker finished with code 0 and signal null

Environment

Node: v18.18.2
NPM: 9.1.3
VS Code: 1.83.1
Operating System: Windows 11 Pro 22H2
Test Explorer UI: v2.21.1
Mocha Test Explorer: v2.14.1

@Danielku15
Copy link
Author

I think I have some new findings but no solution yet.

I am diving into the extension further I patched locally some things to see the messages exchanged between the worker loading the tests and the plugin process. This is the test model loaded and received here:

{
    "type": "suite",
    "id": "undefined: ",
    "label": "",
    "children": [{
            "type": "suite",
            "id": "D:\\Dev\\mocha-test-explorer\\test\\rules.test.ts: Suite",
            "label": "Suite",
            "file": "D:\\Dev\\mocha-test-explorer\\test\\rules.test.ts",
            "line": 0,
            "children": [{
                    "type": "test",
                    "id": "D:\\Dev\\mocha-test-explorer\\test\\rules.test.ts: Suite Test",
                    "label": "Test",
                    "file": "D:\\Dev\\mocha-test-explorer\\test\\rules.test.ts",
                    "line": 1,
                    "skipped": false
                }
            ]
        }
    ]
}

The Suite ID and label made me worrying. But also afterwards this error is signaled as finished event:

[2023-10-21 10:42:17.716] [INFO] Received error from worker  {"type":"dependency","path":"file:///D:/Dev/mocha-test-explorer/test/rules.test.ts"}

This error clears out the test list loaded. Commenting out this signaling I see the tests. But executing them doesn't work. It just shows:

image

@Danielku15
Copy link
Author

Danielku15 commented Oct 21, 2023

I narrowed down the root cause. The tsx loader is also sending messages via process.send

https://github.com/esbuild-kit/tsx/blob/7e916f5a1db5b21589cedc1dc91b0c498f87adf9/src/cjs/index.ts#L61C1-L61C1

{"type":"dependency","path":"D:\\Dev\\mocha-test-explorer\\node_modules\\mocha\\lib\\context.js"}

Those are then misinterpreted here breaking everything:

this.nodesById.clear();
if (info) {
if (info.type === 'suite') {
this.log.info('Received tests from worker');
info.id = `${this.workspaceFolderPath}: Mocha`;
info.label = 'Mocha';
this.collectNodesById(info);
this.testsEmitter.fire(<TestLoadFinishedEvent>{ type: 'finished', suite: info });
if (changedFiles) {
const changedTests = findTests(info, { tests:
info => ((info.file !== undefined) && (changedFiles.indexOf(info.file) >= 0))
});
this.retireEmitter.fire({ tests: [ ...changedTests ].map(info => info.id) })
} else {
this.retireEmitter.fire({});
}
} else { // info.type === 'error'
this.log.info('Received error from worker');
this.testsEmitter.fire(<TestLoadFinishedEvent>{ type: 'finished', errorMessage: info.errorMessage });
}

I could open a PR with a fix ensuring we only handle "own" events in the plugin.

@hbenl Is this project still alive? I wonder as it looks rather dead: no code changes since a long time, PRs and issues not answered, and it currently doesn't build.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant