|
@@ -15,24 +15,32 @@ describe('crashReporter module', function () {
|
|
|
if (process.mas) {
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+ var originalTempDirectory = null
|
|
|
+ var tempDirectory = null
|
|
|
+
|
|
|
+ before(function () {
|
|
|
+ tempDirectory = temp.mkdirSync('electronCrashReporterSpec-')
|
|
|
+ originalTempDirectory = app.getPath('temp')
|
|
|
+ app.setPath('temp', tempDirectory)
|
|
|
+ })
|
|
|
+
|
|
|
+ after(function () {
|
|
|
+ app.setPath('temp', originalTempDirectory)
|
|
|
+ })
|
|
|
+
|
|
|
var fixtures = path.resolve(__dirname, 'fixtures')
|
|
|
const generateSpecs = (description, browserWindowOpts) => {
|
|
|
describe(description, function () {
|
|
|
var w = null
|
|
|
- var originalTempDirectory = null
|
|
|
- var tempDirectory = null
|
|
|
|
|
|
beforeEach(function () {
|
|
|
w = new BrowserWindow(Object.assign({
|
|
|
show: false
|
|
|
}, browserWindowOpts))
|
|
|
- tempDirectory = temp.mkdirSync('electronCrashReporterSpec-')
|
|
|
- originalTempDirectory = app.getPath('temp')
|
|
|
- app.setPath('temp', tempDirectory)
|
|
|
})
|
|
|
|
|
|
afterEach(function () {
|
|
|
- app.setPath('temp', originalTempDirectory)
|
|
|
return closeWindow(w).then(function () { w = null })
|
|
|
})
|
|
|
|
|
@@ -77,13 +85,15 @@ describe('crashReporter module', function () {
|
|
|
it('should not send minidump if uploadToServer is false', function (done) {
|
|
|
this.timeout(120000)
|
|
|
|
|
|
+ let server
|
|
|
+ let dumpFile
|
|
|
+ let crashesDir = crashReporter.getCrashesDirectory()
|
|
|
+ const existingDumpFiles = new Set()
|
|
|
if (process.platform === 'darwin') {
|
|
|
+ // crashpad puts the dump files in the "completed" subdirectory
|
|
|
+ crashesDir = path.join(crashesDir, 'completed')
|
|
|
crashReporter.setUploadToServer(false)
|
|
|
}
|
|
|
-
|
|
|
- let server
|
|
|
- let dumpFile
|
|
|
- let crashesDir
|
|
|
const testDone = (uploaded) => {
|
|
|
if (uploaded) {
|
|
|
return done(new Error('fail'))
|
|
@@ -93,7 +103,6 @@ describe('crashReporter module', function () {
|
|
|
crashReporter.setUploadToServer(true)
|
|
|
}
|
|
|
assert(fs.existsSync(dumpFile))
|
|
|
- fs.unlinkSync(dumpFile)
|
|
|
done()
|
|
|
}
|
|
|
|
|
@@ -103,7 +112,7 @@ describe('crashReporter module', function () {
|
|
|
if (err) {
|
|
|
return
|
|
|
}
|
|
|
- const dumps = files.filter((file) => /\.dmp$/.test(file))
|
|
|
+ const dumps = files.filter((file) => /\.dmp$/.test(file) && !existingDumpFiles.has(file))
|
|
|
if (!dumps.length) {
|
|
|
return
|
|
|
}
|
|
@@ -111,34 +120,17 @@ describe('crashReporter module', function () {
|
|
|
dumpFile = path.join(crashesDir, dumps[0])
|
|
|
clearInterval(pollInterval)
|
|
|
// dump file should not be deleted when not uploading, so we wait
|
|
|
- // 500 ms and assert it still exists in `testDone`
|
|
|
- setTimeout(testDone, 500)
|
|
|
+ // 1s and assert it still exists in `testDone`
|
|
|
+ setTimeout(testDone, 1000)
|
|
|
})
|
|
|
}
|
|
|
|
|
|
- remote.ipcMain.once('set-crash-directory', (event, dir) => {
|
|
|
- if (process.platform === 'linux') {
|
|
|
- crashesDir = dir
|
|
|
- } else {
|
|
|
- crashesDir = crashReporter.getCrashesDirectory()
|
|
|
- if (process.platform === 'darwin') {
|
|
|
- // crashpad uses an extra subdirectory
|
|
|
- crashesDir = path.join(crashesDir, 'completed')
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // Before starting, remove all dump files in the crash directory.
|
|
|
- // This is required because:
|
|
|
- // - mac crashpad not seem to allow changing the crash directory after
|
|
|
- // the first "start" call.
|
|
|
- // - Other tests in this suite may leave dumps there.
|
|
|
- // - We want to verify in `testDone` that a dump file is created and
|
|
|
- // not deleted.
|
|
|
+ remote.ipcMain.once('list-existing-dumps', (event) => {
|
|
|
fs.readdir(crashesDir, (err, files) => {
|
|
|
if (!err) {
|
|
|
for (const file of files) {
|
|
|
if (/\.dmp$/.test(file)) {
|
|
|
- fs.unlinkSync(path.join(crashesDir, file))
|
|
|
+ existingDumpFiles.add(file)
|
|
|
}
|
|
|
}
|
|
|
}
|