Skip to content

Commit

Permalink
chore: upgrade to typescript 3.9 (#10031)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB authored May 13, 2020
1 parent 0e0eeed commit 9ffd368
Show file tree
Hide file tree
Showing 66 changed files with 198 additions and 197 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module.exports = {
'error',
{argsIgnorePattern: '^_'},
],
'@typescript-eslint/prefer-ts-expect-error': 'error',
// Since we do `export =`. Remove for Jest 25
'import/default': 'off',
'import/order': 'error',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"strip-ansi": "^6.0.0",
"tempy": "^0.5.0",
"throat": "^5.0.0",
"typescript": "^3.8.2",
"typescript": "^3.9.2",
"which": "^2.0.1"
},
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-plugin-jest-hoist/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ FUNCTIONS.mock = args => {

const ids: Set<NodePath<Identifier>> = new Set();
const parentScope = moduleFactory.parentPath.scope;
// @ts-ignore: ReferencedIdentifier is not known on visitors
// @ts-expect-error: ReferencedIdentifier is not known on visitors
moduleFactory.traverse(IDVisitor, {ids});
for (const id of ids) {
const {name} = id.node;
Expand Down
12 changes: 6 additions & 6 deletions packages/jest-circus/src/__tests__/circusItTestError.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,21 @@ describe('test/it error throwing', () => {
});
it(`it throws error with missing callback function`, () => {
expect(() => {
// @ts-ignore: Easy, we're testing runtime errors here
// @ts-expect-error: Easy, we're testing runtime errors here
circusIt('test2');
}).toThrowError(
'Missing second argument. It must be a callback function. Perhaps you want to use `test.todo` for a test placeholder.',
);
});
it(`it throws an error when first argument isn't a string`, () => {
expect(() => {
// @ts-ignore: Easy, we're testing runtime errors here
// @ts-expect-error: Easy, we're testing runtime errors here
circusIt(() => {});
}).toThrowError('Invalid first argument, () => {}. It must be a string.');
});
it('it throws an error when callback function is not a function', () => {
expect(() => {
// @ts-ignore: Easy, we're testing runtime errors here
// @ts-expect-error: Easy, we're testing runtime errors here
circusIt('test4', 'test4b');
}).toThrowError(
'Invalid second argument, test4b. It must be a callback function.',
Expand All @@ -56,21 +56,21 @@ describe('test/it error throwing', () => {
});
it(`test throws error with missing callback function`, () => {
expect(() => {
// @ts-ignore: Easy, we're testing runtime errors here
// @ts-expect-error: Easy, we're testing runtime errors here
circusTest('test6');
}).toThrowError(
'Missing second argument. It must be a callback function. Perhaps you want to use `test.todo` for a test placeholder.',
);
});
it(`test throws an error when first argument isn't a string`, () => {
expect(() => {
// @ts-ignore: Easy, we're testing runtime errors here
// @ts-expect-error: Easy, we're testing runtime errors here
circusTest(() => {});
}).toThrowError('Invalid first argument, () => {}. It must be a string.');
});
it('test throws an error when callback function is not a function', () => {
expect(() => {
// @ts-ignore: Easy, we're testing runtime errors here
// @ts-expect-error: Easy, we're testing runtime errors here
circusTest('test8', 'test8b');
}).toThrowError(
'Invalid second argument, test8b. It must be a callback function.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ aliasCircusIt();
describe('test/it.todo error throwing', () => {
it('todo throws error when given no arguments', () => {
expect(() => {
// @ts-ignore: Testing runtime errors here
// @ts-expect-error: Testing runtime errors here
circusIt.todo();
}).toThrowError('Todo must be called with only a description.');
});
Expand All @@ -33,7 +33,7 @@ describe('test/it.todo error throwing', () => {
});
it('todo throws error when given none string description', () => {
expect(() => {
// @ts-ignore: Testing runtime errors here
// @ts-expect-error: Testing runtime errors here
circusIt.todo(() => {});
}).toThrowError('Todo must be called with only a description.');
});
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-cli/src/__tests__/cli/args.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ describe('check', () => {

describe('buildArgv', () => {
it('should return only camelcased args ', () => {
// @ts-ignore
// @ts-expect-error
const mockProcessArgv = jest
.spyOn(process.argv, 'slice')
.mockImplementation(() => ['--clear-mocks']);
// @ts-ignore
// @ts-expect-error
const actual = buildArgv(null);
expect(actual).not.toHaveProperty('clear-mocks');
expect(actual).toHaveProperty('clearMocks', true);
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-cli/src/init/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export default async (

let promptAborted: boolean = false;

// @ts-ignore: Return type cannot be object - faulty typings
// @ts-expect-error: Return type cannot be object - faulty typings
const results: PromptsResults = await prompts(questions, {
onCancel: () => {
promptAborted = true;
Expand Down
6 changes: 3 additions & 3 deletions packages/jest-config/src/__tests__/getMaxWorkers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@ describe('getMaxWorkers', () => {
describe('% based', () => {
it('50% = 2 workers', () => {
const argv = {maxWorkers: '50%'};
// @ts-ignore: need to fix the typing
// @ts-expect-error: need to fix the typing
expect(getMaxWorkers(argv)).toBe(2);
});

it('< 0 workers should become 1', () => {
const argv = {maxWorkers: '1%'};
// @ts-ignore: need to fix the typing
// @ts-expect-error: need to fix the typing
expect(getMaxWorkers(argv)).toBe(1);
});

it("0% shouldn't break", () => {
const argv = {maxWorkers: '0%'};
// @ts-ignore: need to fix the typing
// @ts-expect-error: need to fix the typing
expect(getMaxWorkers(argv)).toBe(1);
});
});
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-config/src/__tests__/readConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {readConfig} from '../index';
test('readConfig() throws when an object is passed without a file path', async () => {
await expect(
readConfig(
// @ts-ignore
// @ts-expect-error
null /* argv */,
{} /* packageRootOrConfig */,
false /* skipArgvConfigOption */,
Expand Down
6 changes: 3 additions & 3 deletions packages/jest-config/src/__tests__/readConfigs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jest.mock('../readConfigFileAndSetRootDir', () => jest.fn(() => mockResult));

test('readConfigs() throws when called without project paths', async () => {
await expect(
// @ts-ignore
// @ts-expect-error
readConfigs(null /* argv */, [] /* projectPaths */),
).rejects.toThrowError('jest: No configuration found for any project.');
});
Expand All @@ -29,7 +29,7 @@ test('readConfigs() loads async config file', async () => {
rootDir: './',
}));
await expect(
// @ts-ignore
// @ts-expect-error
readConfigs(
<Config.Argv>{} /* argv */,
['./some-jest-config-file.js'] /* projectPaths */,
Expand All @@ -43,7 +43,7 @@ test('readConfigs() reject if async was rejected', async () => {
throw new Error('Some error');
});
await expect(
// @ts-ignore
// @ts-expect-error
readConfigs(
<Config.Argv>{} /* argv */,
['./some-jest-config-file.js'] /* projectPaths */,
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-config/src/normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ const setupPreset = (
}
} catch (e) {}

// @ts-ignore: `presetModule` can be null?
// @ts-expect-error: `presetModule` can be null?
preset = require(presetModule);
} catch (error) {
if (error instanceof SyntaxError || error instanceof TypeError) {
Expand Down Expand Up @@ -943,7 +943,7 @@ export default function normalize(
});
break;
}
// @ts-ignore: automock is missing in GlobalConfig, so what
// @ts-expect-error: automock is missing in GlobalConfig, so what
newOptions[key] = value;
return newOptions;
}, newOptions);
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-config/src/readConfigFileAndSetRootDir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as path from 'path';
import {pathToFileURL} from 'url';
import * as fs from 'graceful-fs';
import type {Config} from '@jest/types';
// @ts-ignore: vendored
// @ts-expect-error: vendored
import jsonlint from './vendor/jsonlint';
import {JEST_CONFIG_EXT_JSON, PACKAGE_JSON} from './constants';

Expand Down
2 changes: 1 addition & 1 deletion packages/jest-core/src/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ const getPluginIdentifier = (plugin: WatchPlugin) =>
// WatchPlugin is an interface, and it is my understanding interface
// static fields are not definable anymore, no idea how to circumvent
// this :-(
// @ts-ignore: leave `displayName` be.
// @ts-expect-error: leave `displayName` be.
plugin.constructor.displayName || plugin.constructor.name;

const getPluginKey = (
Expand Down
6 changes: 3 additions & 3 deletions packages/jest-environment-jsdom/src/__mocks__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ const vm = jest.requireActual('vm');
const JSDOMEnvironment = jest.createMockFromModule('../index') as jest.Mock;

JSDOMEnvironment.mockImplementation(function (config) {
// @ts-ignore
// @ts-expect-error
this.global = {
JSON,
console: {},
};

const globalValues = {...config.globals};
for (const customGlobalKey in globalValues) {
// @ts-ignore
// @ts-expect-error
this.global[customGlobalKey] = globalValues[customGlobalKey];
}
});
Expand All @@ -28,7 +28,7 @@ JSDOMEnvironment.prototype.runSourceText.mockImplementation(function (
sourceText: string,
filename: string,
) {
// @ts-ignore
// @ts-expect-error
return vm.runInNewContext(sourceText, this.global, {
displayErrors: false,
filename,
Expand Down
5 changes: 3 additions & 2 deletions packages/jest-environment-jsdom/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class JSDOMEnvironment implements JestEnvironment {
virtualConsole: new VirtualConsole().sendTo(options.console || console),
...config.testEnvironmentOptions,
});
const global = (this.global = this.dom.window.document.defaultView as Win);
const global = (this.global = (this.dom.window.document
.defaultView as unknown) as Win);

if (!global) {
throw new Error('JSDOM did not return a Window object');
Expand Down Expand Up @@ -118,7 +119,7 @@ class JSDOMEnvironment implements JestEnvironment {
this.global.close();
}
this.errorEventListener = null;
// @ts-ignore
// @ts-expect-error
this.global = null;
this.dom = null;
this.fakeTimers = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('NodeEnvironment', () => {
const timer2 = env1.global.setInterval(() => {}, 0);

[timer1, timer2].forEach(timer => {
// @ts-ignore
// @ts-expect-error
expect(timer.id).not.toBeUndefined();
expect(typeof timer.ref).toBe('function');
expect(typeof timer.unref).toBe('function');
Expand Down
6 changes: 5 additions & 1 deletion packages/jest-fake-timers/src/legacyFakeTimers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,10 +366,11 @@ export default class FakeTimers<TimerRef> {

private _createMocks() {
const fn = (impl: Function) =>
// @ts-ignore TODO: figure out better typings here
// @ts-expect-error TODO: figure out better typings here
this._moduleMocker.fn().mockImplementation(impl);

const promisifiableFakeSetTimeout = fn(this._fakeSetTimeout.bind(this));
// @ts-expect-error TODO: figure out better typings here
promisifiableFakeSetTimeout[util.promisify.custom] = (
delay?: number,
arg?: unknown,
Expand All @@ -382,8 +383,11 @@ export default class FakeTimers<TimerRef> {
clearInterval: fn(this._fakeClearTimer.bind(this)),
clearTimeout: fn(this._fakeClearTimer.bind(this)),
nextTick: fn(this._fakeNextTick.bind(this)),
// @ts-expect-error TODO: figure out better typings here
setImmediate: fn(this._fakeSetImmediate.bind(this)),
// @ts-expect-error TODO: figure out better typings here
setInterval: fn(this._fakeSetInterval.bind(this)),
// @ts-expect-error TODO: figure out better typings here
setTimeout: promisifiableFakeSetTimeout,
};
}
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-fake-timers/src/modernFakeTimers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export default class FakeTimers {

runAllTicks(): void {
if (this._checkFakeTimers()) {
// @ts-ignore
// @ts-expect-error
this._clock.runMicrotasks();
}
}
Expand Down
13 changes: 6 additions & 7 deletions packages/jest-haste-map/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import HasteModuleMap, {
import nodeCrawl = require('./crawlers/node');
import normalizePathSep from './lib/normalizePathSep';
import watchmanCrawl = require('./crawlers/watchman');
// @ts-ignore: not converted to TypeScript - it's a fork: https://github.com/facebook/jest/pull/5387
// @ts-expect-error: not converted to TypeScript - it's a fork: https://github.com/facebook/jest/pull/5387
import WatchmanWatcher from './lib/WatchmanWatcher';
import FSEventsWatcher = require('./lib/FSEventsWatcher');
import * as fastPath from './lib/fast_path';
Expand Down Expand Up @@ -513,7 +513,6 @@ class HasteMap extends EventEmitter {
error.stack = ''; // Remove stack for stack-less errors.
}

// @ts-ignore: checking error code is OK if error comes from "fs".
if (!['ENOENT', 'EACCES'].includes(error.code)) {
throw error;
}
Expand Down Expand Up @@ -677,9 +676,9 @@ class HasteMap extends EventEmitter {
private _cleanup() {
const worker = this._worker;

// @ts-ignore
// @ts-expect-error
if (worker && typeof worker.end === 'function') {
// @ts-ignore
// @ts-expect-error
worker.end();
}

Expand All @@ -701,7 +700,7 @@ class HasteMap extends EventEmitter {
if ((options && options.forceInBand) || this._options.maxWorkers <= 1) {
this._worker = {getSha1, worker};
} else {
// @ts-ignore: assignment of a worker with custom properties.
// @ts-expect-error: assignment of a worker with custom properties.
this._worker = new Worker(require.resolve('./worker'), {
exposedMethods: ['getSha1', 'worker'],
maxRetries: 3,
Expand Down Expand Up @@ -789,7 +788,7 @@ class HasteMap extends EventEmitter {
let mustCopy = true;

const createWatcher = (root: Config.Path): Promise<Watcher> => {
// @ts-ignore: TODO how? "Cannot use 'new' with an expression whose type lacks a call or construct signature."
// @ts-expect-error: TODO how? "Cannot use 'new' with an expression whose type lacks a call or construct signature."
const watcher = new Watcher(root, {
dot: false,
glob: extensions.map(extension => '**/*.' + extension),
Expand Down Expand Up @@ -1035,7 +1034,7 @@ class HasteMap extends EventEmitter {
}

end(): Promise<void> {
// @ts-ignore: TODO TS cannot decide if `setInterval` and `clearInterval` comes from NodeJS or the DOM
// @ts-expect-error: TODO TS cannot decide if `setInterval` and `clearInterval` comes from NodeJS or the DOM
clearInterval(this._changeInterval);
if (!this._watchers.length) {
return Promise.resolve();
Expand Down
3 changes: 2 additions & 1 deletion packages/jest-haste-map/src/lib/FSEventsWatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import {EventEmitter} from 'events';
import * as fs from 'graceful-fs';
import anymatch, {Matcher} from 'anymatch';
import micromatch = require('micromatch');
// @ts-ignore no types
// @ts-expect-error no types
import walker from 'walker';

// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error
// @ts-ignore: this is for CI which runs linux and might not have this
let fsevents: typeof import('fsevents') | null = null;
try {
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-jasmine2/src/__tests__/Suite.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('Suite', () => {

it("doesn't throw on addExpectationResult when there are no children", () => {
expect(() => {
// @ts-ignore
// @ts-expect-error
suite.addExpectationResult();
}).not.toThrow();
});
Expand Down
Loading

0 comments on commit 9ffd368

Please sign in to comment.