Skip to content

Commit

Permalink
tests - enable crash reporter for electron based unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed Nov 19, 2021
1 parent b8357ed commit ddbda4c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 6 deletions.
2 changes: 1 addition & 1 deletion scripts/test.bat
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ if %errorlevel% neq 0 node .\node_modules\gulp\bin\gulp.js electron

:: Run tests
set ELECTRON_ENABLE_LOGGING=1
%CODE% .\test\unit\electron\index.js %*
%CODE% .\test\unit\electron\index.js --crash-reporter-directory=%~dp0\..\.build\crashes %*

popd

Expand Down
6 changes: 4 additions & 2 deletions scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ else
CODE=".build/electron/$NAME"
fi

VSCODECRASHDIR=$ROOT/.build/crashes

# Node modules
test -d node_modules || yarn

Expand All @@ -32,10 +34,10 @@ if [[ "$OSTYPE" == "darwin"* ]]; then
cd $ROOT ; ulimit -n 4096 ; \
ELECTRON_ENABLE_LOGGING=1 \
"$CODE" \
test/unit/electron/index.js "$@"
test/unit/electron/index.js --crash-reporter-directory=$VSCODECRASHDIR "$@"
else
cd $ROOT ; \
ELECTRON_ENABLE_LOGGING=1 \
"$CODE" \
test/unit/electron/index.js $LINUX_EXTRA_ARGS "$@"
test/unit/electron/index.js --crash-reporter-directory=$VSCODECRASHDIR $LINUX_EXTRA_ARGS "$@"
fi
39 changes: 36 additions & 3 deletions test/unit/electron/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
// come before any mocha imports.
process.env.MOCHA_COLORS = '1';

const { app, BrowserWindow, ipcMain } = require('electron');
const { app, BrowserWindow, ipcMain, crashReporter } = require('electron');
const product = require('../../../product.json');
const { tmpdir } = require('os');
const { join } = require('path');
const { existsSync, mkdirSync } = require('fs');
const path = require('path');
const mocha = require('mocha');
const events = require('events');
Expand All @@ -34,6 +35,7 @@ const optimist = require('optimist')
.describe('reporter-options', 'the mocha reporter options').string('reporter-options').default('reporter-options', '')
.describe('wait-server', 'port to connect to and wait before running tests')
.describe('timeout', 'timeout for tests')
.describe('crash-reporter-directory', 'crash reporter directory').string('crash-reporter-directory')
.describe('tfs').string('tfs')
.describe('help', 'show the help').alias('help', 'h');

Expand All @@ -44,8 +46,39 @@ if (argv.help) {
process.exit(0);
}

let crashReporterDirectory = argv['crash-reporter-directory'];
if (crashReporterDirectory) {
crashReporterDirectory = path.normalize(crashReporterDirectory);

if (!path.isAbsolute(crashReporterDirectory)) {
console.error(`The path '${crashReporterDirectory}' specified for --crash-reporter-directory must be absolute.`);
app.exit(1);
}

if (!existsSync(crashReporterDirectory)) {
try {
mkdirSync(crashReporterDirectory);
} catch (error) {
console.error(`The path '${crashReporterDirectory}' specified for --crash-reporter-directory does not seem to exist or cannot be created.`);
app.exit(1);
}
}

// Crashes are stored in the crashDumps directory by default, so we
// need to change that directory to the provided one
console.log(`Found --crash-reporter-directory argument. Setting crashDumps directory to be '${crashReporterDirectory}'`);
app.setPath('crashDumps', crashReporterDirectory);

crashReporter.start({
companyName: 'Microsoft',
productName: process.env['VSCODE_DEV'] ? `${product.nameShort} Dev` : product.nameShort,
uploadToServer: false,
compress: true
});
}

if (!argv.debug) {
app.setPath('userData', join(tmpdir(), `vscode-tests-${Date.now()}`));
app.setPath('userData', path.join(tmpdir(), `vscode-tests-${Date.now()}`));
}

function deserializeSuite(suite) {
Expand Down

0 comments on commit ddbda4c

Please sign in to comment.