I am trying to write end-to-end tests for a VS Code extension. I would like to use JavaScript, not TypeScript. So, I took the example from here: https://github.com/microsoft/vscode-extension-samples/tree/main/helloworld-test-sample and converted the code to JavaScript and CommonJS. When I do, I get this error:
Error: Path file:///Users/kurmasz/Documents/LocalResearch/QLC/gvQLC/test/suite/index does not point to a valid extension test runner.
Here is my index.js:
const path = require('path')
const Mocha = require('mocha')
const glob = require('glob')
console.log('********************* Here!')
module.exports = function run() {
// Create the mocha test
const mocha = new Mocha({
ui: 'tdd'
});
const testsRoot = path.resolve(__dirname, '..');
console.log(`********************** Test Root: ${testsRoot}`)
return new Promise((c, e) => {
glob('**/**.test.js', { cwd: testsRoot }, (err, files) => {
if (err) {
return e(err);
}
// Add files to the test suite
files.forEach(f => mocha.addFile(path.resolve(testsRoot, f)));
try {
// Run the mocha test
mocha.run(failures => {
if (failures > 0) {
e(new Error(`${failures} tests failed.`));
} else {
c();
}
});
} catch (err) {
console.error(err);
e(err);
}
});
});
}
console.log('********************* Done!')
Both console statements print, so the code is running and not throwing an error.
I am using VS Code 1.101.0 @vscode/test-electron 2.5.2 mocha 11.6.0
I also see this when I run the test:
✔ Validated version: 1.101.1
✔ Found existing install in /Users/.../.vscode-test/vscode-darwin-1.101.1
Can anybody tell what I'm doing wrong?
Update: I cloned helloworld-test-sample, then looked at the JavaScript generated by compiling the TypeScript. This is the beginning of index.js:
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.run = run;
const path = require("path");
const Mocha = require("mocha");
const glob = require("glob");
function run() {
When I use this structure (with __esModule), then the "does not point to a valid extension test runner" error goes away. Does this mean that my JavaScript version of index.js is wrong? Or do I just need to use TypeScript for my tests?