Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ env:
# Unicode characters are causing 2.7 failures so skip that for now.
special-working-directory: './path with spaces'
special-working-directory-relative: 'path with spaces'
# Use the mocha-multi-reporters and send output to both console (spec) and JUnit (mocha-junit-reporter).
# Send output to both console (spec) and JUnit-compatible XML.
# Also enables a reporter which exits the process running the tests if it haven't already.
MOCHA_REPORTER_JUNIT: true

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ permissions: {}
env:
NODE_VERSION: 22.21.1
PYTHON_VERSION: '3.10' # YML treats 3.10 the number as 3.1, so quotes around 3.10
MOCHA_REPORTER_JUNIT: true # Use the mocha-multi-reporters and send output to both console (spec) and JUnit (mocha-junit-reporter). Also enables a reporter which exits the process running the tests if it haven't already.
MOCHA_REPORTER_JUNIT: true # Send output to both console (spec) and JUnit-compatible XML. Also enables the test completion reporter.
ARTIFACT_NAME_VSIX: ms-python-insiders-vsix
TEST_RESULTS_DIRECTORY: .
# Force a path with spaces and to test extension works in these scenarios
Expand Down
12 changes: 6 additions & 6 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,12 @@
"name": "Unit Tests (without VS Code, *.unit.test.ts)",
"type": "node",
"request": "launch",
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"program": "${workspaceFolder}/node_modules/mocha/bin/mocha.js",
"stopOnEntry": false,
"sourceMaps": true,
"args": [
"./out/test/**/*.unit.test.js",
"--require=out/test/unittests.js",
"--require=./out/test/unittests.js",
"--ui=tdd",
"--recursive",
"--colors",
Expand All @@ -160,12 +160,12 @@
"name": "Unit Tests (fast, without VS Code and without react/monaco, *.unit.test.ts)",
"type": "node",
"request": "launch",
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"program": "${workspaceFolder}/node_modules/mocha/bin/mocha.js",
"stopOnEntry": false,
"sourceMaps": true,
"args": [
"./out/test/**/*.unit.test.js",
"--require=out/test/unittests.js",
"--require=./out/test/unittests.js",
"--ui=tdd",
"--recursive",
"--colors",
Expand All @@ -181,12 +181,12 @@
"name": "Functional Tests (without VS Code, *.functional.test.ts)",
"type": "node",
"request": "launch",
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"program": "${workspaceFolder}/node_modules/mocha/bin/mocha.js",
"stopOnEntry": false,
"sourceMaps": true,
"args": [
"./out/test/**/*.functional.test.js",
"--require=out/test/unittests.js",
"--require=./out/test/unittests.js",
"--ui=tdd",
"--recursive",
"--colors",
Expand Down
3 changes: 0 additions & 3 deletions build/.mocha-multi-reporters.config

This file was deleted.

5 changes: 2 additions & 3 deletions build/.mocha.functional.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
{
"spec": "./out/test/**/*.functional.test.js",
"require": [
"out/test/unittests.js"
"./out/test/unittests.js"
],
"exclude": "out/**/*.jsx",
"reporter": "mocha-multi-reporters",
"reporter-option": "configFile=./build/.mocha-multi-reporters.config",
"reporter": "./build/ci/scripts/ci_reporter.js",
"ui": "tdd",
"recursive": true,
"colors": true,
Expand Down
4 changes: 2 additions & 2 deletions build/.mocha.functional.perf.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"spec": "./out/test/**/*.functional.test.js",
"exclude-out": "out/**/*.jsx",
"require": ["out/test/unittests.js"],
"exclude": "out/**/*.jsx",
"require": ["./out/test/unittests.js"],
"reporter": "spec",
"ui": "tdd",
"recursive": true,
Expand Down
6 changes: 0 additions & 6 deletions build/.mocha.perf.config

This file was deleted.

6 changes: 3 additions & 3 deletions build/.mocha.performance.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"spec": "./out/test/**/*.functional.test.js",
"require": ["out/test/unittests.js"],
"reporter": "mocha-multi-reporters",
"reporter-option": "configFile=build/.mocha.perf.config",
"require": ["./out/test/unittests.js"],
"reporter": "./build/ci/scripts/ci_reporter.js",
"reporter-option": "output=xunit-test-results.xml",
"ui": "tdd",
"recursive": true,
"colors": true,
Expand Down
5 changes: 2 additions & 3 deletions build/.mocha.unittests.js.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"spec": "./out/test/**/*.unit.test.js",
"require": ["source-map-support/register", "out/test/unittests.js"],
"reporter": "mocha-multi-reporters",
"reporter-option": "configFile=build/.mocha-multi-reporters.config",
"require": ["source-map-support/register", "./out/test/unittests.js"],
"reporter": "./build/ci/scripts/ci_reporter.js",
"ui": "tdd",
"recursive": true,
"colors": true
Expand Down
5 changes: 2 additions & 3 deletions build/.mocha.unittests.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
{
"spec": "./out/test/**/*.unit.test.js",
"require": [
"out/test/unittests.js"
"./out/test/unittests.js"
],
"exclude": "out/**/*.jsx",
"reporter": "mocha-multi-reporters",
"reporter-option": "configFile=./build/.mocha-multi-reporters.config",
"reporter": "./build/ci/scripts/ci_reporter.js",
"ui": "tdd",
"recursive": true,
"colors": true,
Expand Down
5 changes: 2 additions & 3 deletions build/.mocha.unittests.ts.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"spec": "./src/test/**/*.unit.test.ts",
"require": ["ts-node/register", "out/test/unittests.js"],
"reporter": "mocha-multi-reporters",
"reporter-option": "configFile=build/.mocha-multi-reporters.config",
"require": ["ts-node/register/files", "./out/test/unittests.js"],
"reporter": "./build/ci/scripts/ci_reporter.js",
"ui": "tdd",
"recursive": true,
"colors": true
Expand Down
31 changes: 31 additions & 0 deletions build/ci/scripts/ci_reporter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use strict';

const { reporters } = require('mocha');
const Spec = require('./spec_with_pid');

class CIReporter extends reporters.XUnit {
constructor(runner, options = {}) {
const reporterOptions = options.reporterOptions || {};
super(runner, {
...options,
reporterOptions: {
...reporterOptions,
output: reporterOptions.output || process.env.MOCHA_FILE || 'test-results.xml',
},
});
const ConsoleReporter = reporterOptions.consoleReporter ? require(reporterOptions.consoleReporter) : Spec;
this.consoleReporter = new ConsoleReporter(runner, options);
}

done(failures, callback) {
super.done(failures, () => {
if (this.consoleReporter.done) {
this.consoleReporter.done(failures, callback);
} else {
callback(failures);
}
});
}
}

module.exports = CIReporter;
107 changes: 52 additions & 55 deletions build/ci/scripts/spec_with_pid.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
* Module dependencies.
*/

const Base = require('mocha/lib/reporters/base');
const { constants } = require('mocha/lib/runner');
const { reporters, Runner } = require('mocha');
const { Base } = reporters;
const { constants } = Runner;

const { EVENT_RUN_BEGIN } = constants;
const { EVENT_RUN_END } = constants;
Expand All @@ -17,7 +18,6 @@ const { EVENT_SUITE_END } = constants;
const { EVENT_TEST_FAIL } = constants;
const { EVENT_TEST_PASS } = constants;
const { EVENT_TEST_PENDING } = constants;
const { inherits } = require('mocha/lib/utils');

const { color } = Base;

Expand All @@ -33,65 +33,62 @@ const prefix = process.env.VSC_PYTHON_CI_TEST_PARALLEL ? `${process.pid} ` : '
* @param {Runner} runner - Instance triggers reporter actions.
* @param {Object} [options] - runner options
*/
function Spec(runner, options) {
Base.call(this, runner, options);
class Spec extends Base {
constructor(runner, options) {
super(runner, options);

let indents = 0;
let n = 0;
let indents = 0;
let n = 0;

function indent() {
return Array(indents).join(' ');
}

runner.on(EVENT_RUN_BEGIN, () => {
Base.consoleLog();
});

runner.on(EVENT_SUITE_BEGIN, (suite) => {
indents += 1;
Base.consoleLog(color('suite', `${prefix}%s%s`), indent(), suite.title);
});

runner.on(EVENT_SUITE_END, () => {
indents -= 1;
if (indents === 1) {
Base.consoleLog();
function indent() {
return Array(indents).join(' ');
}
});

runner.on(EVENT_TEST_PENDING, (test) => {
const fmt = indent() + color('pending', `${prefix} %s`);
Base.consoleLog(fmt, test.title);
});

runner.on(EVENT_TEST_PASS, (test) => {
let fmt;
if (test.speed === 'fast') {
fmt = indent() + color('checkmark', prefix + Base.symbols.ok) + color('pass', ' %s');
runner.on(EVENT_RUN_BEGIN, () => {
Base.consoleLog();
});

runner.on(EVENT_SUITE_BEGIN, (suite) => {
indents += 1;
Base.consoleLog(color('suite', `${prefix}%s%s`), indent(), suite.title);
});

runner.on(EVENT_SUITE_END, () => {
indents -= 1;
if (indents === 1) {
Base.consoleLog();
}
});

runner.on(EVENT_TEST_PENDING, (test) => {
const fmt = indent() + color('pending', `${prefix} %s`);
Base.consoleLog(fmt, test.title);
} else {
fmt =
indent() +
color('checkmark', prefix + Base.symbols.ok) +
color('pass', ' %s') +
color(test.speed, ' (%dms)');
Base.consoleLog(fmt, test.title, test.duration);
}
});

runner.on(EVENT_TEST_FAIL, (test) => {
n += 1;
Base.consoleLog(indent() + color('fail', `${prefix}%d) %s`), n, test.title);
});

runner.once(EVENT_RUN_END, this.epilogue.bind(this));
});

runner.on(EVENT_TEST_PASS, (test) => {
let fmt;
if (test.speed === 'fast') {
fmt = indent() + color('checkmark', prefix + Base.symbols.ok) + color('pass', ' %s');
Base.consoleLog(fmt, test.title);
} else {
fmt =
indent() +
color('checkmark', prefix + Base.symbols.ok) +
color('pass', ' %s') +
color(test.speed, ' (%dms)');
Base.consoleLog(fmt, test.title, test.duration);
}
});

runner.on(EVENT_TEST_FAIL, (test) => {
n += 1;
Base.consoleLog(indent() + color('fail', `${prefix}%d) %s`), n, test.title);
});

runner.once(EVENT_RUN_END, this.epilogue.bind(this));
}
}

/**
* Inherit from `Base.prototype`.
*/
inherits(Spec, Base);

Spec.description = 'hierarchical & verbose [default]';

/**
Expand Down
Loading
Loading