diff options
author | Benjamin Pasero <benjamin.pasero@microsoft.com> | 2021-11-19 13:12:49 +0300 |
---|---|---|
committer | Benjamin Pasero <benjamin.pasero@microsoft.com> | 2021-11-19 13:12:53 +0300 |
commit | ddbda4c196baa9dfc43c5da2401f063d4bd76724 (patch) | |
tree | f5a7cbf644ad3591a3cff3aa9456936542463ab8 | |
parent | b8357ede65e5117dd85ad2288002451e674de98d (diff) |
tests - enable crash reporter for electron based unit tests
//cc @deepak1556
-rw-r--r-- | scripts/test.bat | 2 | ||||
-rwxr-xr-x | scripts/test.sh | 6 | ||||
-rw-r--r-- | test/unit/electron/index.js | 39 |
3 files changed, 41 insertions, 6 deletions
diff --git a/scripts/test.bat b/scripts/test.bat index 7232c26193c..d45505db8a7 100644 --- a/scripts/test.bat +++ b/scripts/test.bat @@ -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 diff --git a/scripts/test.sh b/scripts/test.sh index 10ffb97c71f..14a72e09cc3 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -21,6 +21,8 @@ else CODE=".build/electron/$NAME" fi +VSCODECRASHDIR=$ROOT/.build/crashes + # Node modules test -d node_modules || yarn @@ -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 diff --git a/test/unit/electron/index.js b/test/unit/electron/index.js index 089e25286cb..f5dc37d1093 100644 --- a/test/unit/electron/index.js +++ b/test/unit/electron/index.js @@ -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'); @@ -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'); @@ -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) { |