Skip to content

Commit

Permalink
chore: remove unused errors in catchs, and reject parameters (#10354
Browse files Browse the repository at this point in the history
)
  • Loading branch information
G-Rath committed Aug 2, 2020
1 parent 683b7e6 commit fe5b29a
Show file tree
Hide file tree
Showing 44 changed files with 64 additions and 64 deletions.
2 changes: 1 addition & 1 deletion e2e/__tests__/snapshot.test.ts
Expand Up @@ -59,7 +59,7 @@ const initialTestData = fs.readFileSync(snapshotEscapeTestFile, 'utf8');
const fileExists = (filePath: string) => {
try {
return fs.statSync(filePath).isFile();
} catch (e) {}
} catch {}
return false;
};
const getSnapshotOfCopy = () => {
Expand Down
Expand Up @@ -29,7 +29,7 @@ describe('toEqual', () => {
try {
expect(a).toEqual(b);
return true;
} catch (err) {
} catch {
return false;
}
};
Expand Down
Expand Up @@ -20,15 +20,15 @@ describe('toStrictEqual', () => {
try {
expect(a).toStrictEqual(b);
return true;
} catch (err) {
} catch {
return false;
}
};
const safeAssertDeepStrictEqual = (a, b) => {
try {
assert.deepStrictEqual(a, b);
return true;
} catch (err) {
} catch {
return false;
}
};
Expand Down
16 changes: 8 additions & 8 deletions packages/expect/src/__tests__/spyMatchers.test.ts
Expand Up @@ -453,7 +453,7 @@ const createSpy = (fn: jest.Mock) => {

try {
fn(true);
} catch (error) {
} catch {
// ignore error
}

Expand All @@ -479,13 +479,13 @@ const createSpy = (fn: jest.Mock) => {

try {
fn();
} catch (error) {
} catch {
// ignore error
}

try {
fn();
} catch (error) {
} catch {
// ignore error
}

Expand All @@ -501,7 +501,7 @@ const createSpy = (fn: jest.Mock) => {

try {
fn();
} catch (error) {
} catch {
// ignore error
}

Expand Down Expand Up @@ -652,7 +652,7 @@ const createSpy = (fn: jest.Mock) => {

try {
fn(true);
} catch (error) {
} catch {
// ignore error
}

Expand All @@ -679,7 +679,7 @@ const createSpy = (fn: jest.Mock) => {

try {
fn(true);
} catch (error) {
} catch {
// ignore error
}

Expand Down Expand Up @@ -886,7 +886,7 @@ const createSpy = (fn: jest.Mock) => {

try {
fn();
} catch (error) {
} catch {
// ignore error
}

Expand All @@ -908,7 +908,7 @@ const createSpy = (fn: jest.Mock) => {

try {
fn();
} catch (error) {
} catch {
// ignore error
}

Expand Down
2 changes: 1 addition & 1 deletion packages/expect/src/index.ts
Expand Up @@ -338,7 +338,7 @@ const makeThrowingMatcher = (

return asyncResult
.then(aResult => processResult(aResult, asyncError))
.catch(error => handleError(error));
.catch(handleError);
} else {
const syncResult = potentialResult as SyncExpectationResult;

Expand Down
2 changes: 1 addition & 1 deletion packages/jest-changed-files/src/git.ts
Expand Up @@ -94,7 +94,7 @@ const adapter: SCMAdapter = {
const result = await execa('git', options, {cwd});

return path.resolve(cwd, result.stdout);
} catch (e) {
} catch {
return null;
}
},
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-changed-files/src/hg.ts
Expand Up @@ -51,7 +51,7 @@ const adapter: SCMAdapter = {
const result = await execa('hg', ['root'], {cwd, env});

return result.stdout;
} catch (e) {
} catch {
return null;
}
},
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-cli/src/cli/index.ts
Expand Up @@ -97,7 +97,7 @@ const getProjectListFromCLIArgs = (
if (!projects.length && process.platform === 'win32') {
try {
projects.push(tryRealpath(process.cwd()));
} catch (err) {
} catch {
// do nothing, just catch error
// process.binding('fs').realpath can throw, e.g. on mapped drives
}
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-cli/src/init/index.ts
Expand Up @@ -53,7 +53,7 @@ export default async (
projectPackageJson = JSON.parse(
fs.readFileSync(projectPackageJsonPath, 'utf-8'),
);
} catch (error) {
} catch {
throw new MalformedPackageJsonError(projectPackageJsonPath);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/jest-config/src/__mocks__/read-pkg.js
Expand Up @@ -20,7 +20,7 @@ function readPkg(file) {
try {
const json = JSON.parse(mockFile);
return Promise.resolve(json);
} catch (err) {
} catch {
return Promise.reject(`${file} is not valid JSON.`);
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-config/src/index.ts
Expand Up @@ -64,7 +64,7 @@ export async function readConfig(
let config;
try {
config = JSON.parse(argv.config);
} catch (e) {
} catch {
throw new Error(
'There was an error while parsing the `--config` argument as a JSON string.',
);
Expand Down
8 changes: 4 additions & 4 deletions packages/jest-config/src/normalize.ts
Expand Up @@ -138,7 +138,7 @@ const setupPreset = (
if (presetModule) {
delete require.cache[require.resolve(presetModule)];
}
} catch (e) {}
} catch {}

// @ts-expect-error: `presetModule` can be null?
preset = require(presetModule);
Expand Down Expand Up @@ -278,7 +278,7 @@ const normalizeCollectCoverageFrom = (
if (!Array.isArray(initialCollectCoverageFrom)) {
try {
value = JSON.parse(initialCollectCoverageFrom);
} catch (e) {}
} catch {}

if (options[key] && !Array.isArray(value)) {
value = [initialCollectCoverageFrom];
Expand Down Expand Up @@ -391,7 +391,7 @@ const normalizeRootDir = (
try {
// try to resolve windows short paths, ignoring errors (permission errors, mostly)
options.rootDir = tryRealpath(options.rootDir);
} catch (e) {
} catch {
// ignored
}

Expand Down Expand Up @@ -956,7 +956,7 @@ export default function normalize(
try {
// try to resolve windows short paths, ignoring errors (permission errors, mostly)
newOptions.cwd = tryRealpath(process.cwd());
} catch (e) {
} catch {
// ignored
}

Expand Down
4 changes: 2 additions & 2 deletions packages/jest-config/src/utils.ts
Expand Up @@ -144,7 +144,7 @@ export const resolveWithPrefix = (

try {
return require.resolve(`${prefix}${fileName}`);
} catch (e) {}
} catch {}

module = Resolver.findNodeModule(fileName, {
basedir: rootDir,
Expand All @@ -156,7 +156,7 @@ export const resolveWithPrefix = (

try {
return require.resolve(fileName);
} catch (e) {}
} catch {}

throw createValidationError(
` ${humanOptionName} ${chalk.bold(
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-config/src/validatePattern.ts
Expand Up @@ -10,7 +10,7 @@ export default function validatePattern(pattern?: string): boolean {
try {
// eslint-disable-next-line no-new
new RegExp(pattern, 'i');
} catch (e) {
} catch {
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-core/src/TestNamePatternPrompt.ts
Expand Up @@ -40,7 +40,7 @@ export default class TestNamePatternPrompt extends PatternPrompt {

try {
regex = new RegExp(pattern, 'i');
} catch (e) {
} catch {
return [];
}

Expand Down
2 changes: 1 addition & 1 deletion packages/jest-core/src/TestPathPatternPrompt.ts
Expand Up @@ -47,7 +47,7 @@ export default class TestPathPatternPrompt extends PatternPrompt {

try {
regex = new RegExp(pattern, 'i');
} catch (e) {}
} catch {}

let tests: Array<Test> = [];
if (regex && this._searchSources) {
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-core/src/cli/index.ts
Expand Up @@ -238,7 +238,7 @@ const runWatch = async (
undefined,
filter,
);
} catch (e) {
} catch {
exit(0);
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-diff/src/index.ts
Expand Up @@ -154,7 +154,7 @@ function compareObjects(
options,
);
}
} catch (e) {
} catch {
hasThrown = true;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/jest-haste-map/src/__tests__/index.test.js
Expand Up @@ -1385,7 +1385,7 @@ describe('HasteMap', () => {

describe('file system changes processing', () => {
function waitForItToChange(hasteMap) {
return new Promise((resolve, reject) => {
return new Promise(resolve => {
hasteMap.once('change', resolve);
});
}
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-haste-map/src/index.ts
Expand Up @@ -126,7 +126,7 @@ const canUseWatchman = ((): boolean => {
try {
execSync('watchman --version', {stdio: ['ignore']});
return true;
} catch (e) {}
} catch {}
return false;
})();

Expand Down Expand Up @@ -381,7 +381,7 @@ class HasteMap extends EventEmitter {

try {
hasteMap = serializer.readFileSync(this._cachePath);
} catch (err) {
} catch {
hasteMap = this._createEmptyMap();
}

Expand Down
2 changes: 1 addition & 1 deletion packages/jest-haste-map/src/lib/FSEventsWatcher.ts
Expand Up @@ -19,7 +19,7 @@ import walker from 'walker';
let fsevents: typeof import('fsevents') | null = null;
try {
fsevents = require('fsevents');
} catch (e) {
} catch {
// Optional dependency, only supported on Darwin.
}

Expand Down
2 changes: 1 addition & 1 deletion packages/jest-haste-map/src/lib/isRegExpSupported.ts
Expand Up @@ -10,7 +10,7 @@ export default function isRegExpSupported(value: string): boolean {
// eslint-disable-next-line no-new
new RegExp(value);
return true;
} catch (e) {
} catch {
return false;
}
}
2 changes: 1 addition & 1 deletion packages/jest-jasmine2/src/__tests__/pTimeout.test.ts
Expand Up @@ -30,7 +30,7 @@ describe('pTimeout', () => {
const promise = Promise.reject();
try {
await pTimeout(promise, 1000, clearTimeout, setTimeout, onTimeout);
} catch (e) {}
} catch {}
expect(setTimeout).toHaveBeenCalled();
expect(clearTimeout).toHaveBeenCalled();
expect(onTimeout).not.toHaveBeenCalled();
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-jasmine2/src/jasmine/Suite.ts
Expand Up @@ -207,7 +207,7 @@ export default class Suite {
const child = this.children[i];
try {
child.addExpectationResult.apply(child, args);
} catch (e) {
} catch {
// keep going
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-jasmine2/src/jasmine/spyRegistry.ts
Expand Up @@ -113,7 +113,7 @@ export default class SpyRegistry {
let descriptor;
try {
descriptor = Object.getOwnPropertyDescriptor(obj, methodName);
} catch (e) {
} catch {
// IE 8 doesn't support `definePropery` on non-DOM nodes
}

Expand Down Expand Up @@ -166,7 +166,7 @@ export default class SpyRegistry {
let descriptor: PropertyDescriptor | undefined;
try {
descriptor = Object.getOwnPropertyDescriptor(obj, propertyName);
} catch (e) {
} catch {
// IE 8 doesn't support `definePropery` on non-DOM nodes
}

Expand Down
2 changes: 1 addition & 1 deletion packages/jest-matcher-utils/src/index.ts
Expand Up @@ -93,7 +93,7 @@ export const stringify = (object: unknown, maxDepth: number = 10): string => {
min: true,
plugins: PLUGINS,
});
} catch (e) {
} catch {
result = prettyFormat(object, {
callToJSON: false,
maxDepth,
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-message-util/src/index.ts
Expand Up @@ -26,7 +26,7 @@ let nodeInternals: Array<RegExp> = [];

try {
nodeInternals = StackUtils.nodeInternals();
} catch (e) {
} catch {
// `StackUtils.nodeInternals()` fails in browsers. We don't need to remove
// node internals in the browser though, so no issue.
}
Expand Down Expand Up @@ -295,7 +295,7 @@ export const formatStackTrace = (
// see: https://github.com/facebook/jest/pull/5405#discussion_r164281696
fileContent = fs.readFileSync(filename, 'utf8');
renderedCallsite = getRenderedCallsite(fileContent, line, column);
} catch (e) {
} catch {
// the file does not exist or is inaccessible, we ignore
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-mock/src/__tests__/index.test.ts
Expand Up @@ -765,7 +765,7 @@ describe('moduleMocker', () => {

try {
fn(2, 4);
} catch (error) {
} catch {
// ignore error
}

Expand Down
2 changes: 1 addition & 1 deletion packages/jest-reporters/src/coverage_reporter.ts
Expand Up @@ -212,7 +212,7 @@ export default class CoverageReporter extends BaseReporter {

try {
await Promise.all(instrumentation);
} catch (err) {
} catch {
// Do nothing; errors were reported earlier to the console.
}

Expand Down

0 comments on commit fe5b29a

Please sign in to comment.