chore: fix linting (#23473)

This commit is contained in:
Samuel Attard 2020-05-08 11:30:37 -07:00 committed by GitHub
parent 21900fe4f4
commit 091f45b879
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 37 deletions

View file

@ -1,54 +1,54 @@
import { expect } from 'chai' import { expect } from 'chai';
import * as cp from 'child_process' import * as cp from 'child_process';
import * as fs from 'fs' import * as fs from 'fs';
import * as path from 'path' import * as path from 'path';
const fixturePath = path.resolve(__dirname, 'fixtures', 'crash-cases') const fixturePath = path.resolve(__dirname, 'fixtures', 'crash-cases');
let children: cp.ChildProcessWithoutNullStreams[] = [] let children: cp.ChildProcessWithoutNullStreams[] = [];
const runFixtureAndEnsureCleanExit = (args: string[]) => { const runFixtureAndEnsureCleanExit = (args: string[]) => {
let out = '' let out = '';
const child = cp.spawn(process.execPath, args) const child = cp.spawn(process.execPath, args);
children.push(child) children.push(child);
child.stdout.on('data', (chunk: Buffer) => { child.stdout.on('data', (chunk: Buffer) => {
out += chunk.toString() out += chunk.toString();
}) });
child.stderr.on('data', (chunk: Buffer) => { child.stderr.on('data', (chunk: Buffer) => {
out += chunk.toString() out += chunk.toString();
}) });
return new Promise((resolve) => { return new Promise((resolve) => {
child.on('exit', (code, signal) => { child.on('exit', (code, signal) => {
if (code !== 0 || signal !== null) { if (code !== 0 || signal !== null) {
console.error(out) console.error(out);
} }
expect(signal).to.equal(null, 'exit signal should be null') expect(signal).to.equal(null, 'exit signal should be null');
expect(code).to.equal(0, 'should have exited with code 0') expect(code).to.equal(0, 'should have exited with code 0');
children = children.filter(c => c !== child) children = children.filter(c => c !== child);
resolve() resolve();
}) });
}) });
} };
describe('crash cases', () => { describe('crash cases', () => {
afterEach(() => { afterEach(() => {
for (const child of children) { for (const child of children) {
child.kill() child.kill();
} }
expect(children).to.have.lengthOf(0, 'all child processes should have exited cleanly') expect(children).to.have.lengthOf(0, 'all child processes should have exited cleanly');
children.length = 0 children.length = 0;
}) });
const cases = fs.readdirSync(fixturePath) const cases = fs.readdirSync(fixturePath);
for (const crashCase of cases) { for (const crashCase of cases) {
it(`the "${crashCase}" case should not crash`, () => { it(`the "${crashCase}" case should not crash`, () => {
const fixture = path.resolve(fixturePath, crashCase) const fixture = path.resolve(fixturePath, crashCase);
const argsFile = path.resolve(fixture, 'electron.args') const argsFile = path.resolve(fixture, 'electron.args');
const args = [fixture] const args = [fixture];
if (fs.existsSync(argsFile)) { if (fs.existsSync(argsFile)) {
args.push(...fs.readFileSync(argsFile, 'utf8').trim().split('\n')) args.push(...fs.readFileSync(argsFile, 'utf8').trim().split('\n'));
} }
return runFixtureAndEnsureCleanExit(args) return runFixtureAndEnsureCleanExit(args);
}) });
} }
}) });

View file

@ -1,6 +1,6 @@
const { app, session } = require('electron') const { app, session } = require('electron');
app.on('ready', () => { app.on('ready', () => {
session.fromPartition('in-memory') session.fromPartition('in-memory');
process.exit(0) process.exit(0);
}) });