Skip to content

Commit f9b0a91

Browse files
authored
upgrade dependency to the latest (#97)
1 parent 7ef5fad commit f9b0a91

19 files changed

+2638
-2587
lines changed

.eslintrc.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@ module.exports = {
1111
},
1212
settings: {
1313
'import/parsers': {
14-
'babel-eslint': ['.js'],
14+
'@babel/eslint-parser': ['.js'],
1515
'@typescript-eslint/parser': ['.ts'],
1616
},
1717
'import/resolver': {
1818
node: true,
1919
'eslint-import-resolver-typescript': true,
2020
},
2121
},
22-
parser: 'babel-eslint',
22+
parser: '@babel/eslint-parser',
2323
parserOptions: {
2424
sourceType: 'module',
2525
babelOptions: {
26-
// configuration for babel-eslint
27-
configFile: 'babel.config.js',
26+
// configuration for @babel/eslint-parser
27+
configFile: './babel.config.js',
2828
},
2929
// configuration for @typescript-eslint
3030
project: 'tsconfig.json',
@@ -33,10 +33,11 @@ module.exports = {
3333
// linting setup for JS files.
3434
{
3535
files: '**/*.js',
36-
plugins: ['babel', 'flowtype', 'prettier', 'import'],
36+
parser: '@babel/eslint-parser',
37+
plugins: ['@babel', 'flowtype', 'prettier', 'import'],
3738
extends: ['airbnb-base', 'plugin:flowtype/recommended', 'prettier', 'plugin:prettier/recommended'],
3839
rules: {
39-
'prettier/prettier': ["error", { "endOfLine": "auto" }],
40+
'prettier/prettier': ['error', {endOfLine: 'auto'}],
4041
'no-underscore-dangle': 'off',
4142
camelcase: 'off',
4243
'no-param-reassign': ['error', {props: false}],
@@ -53,7 +54,7 @@ module.exports = {
5354
// linting setup for TS files.
5455
{
5556
files: '**/*.ts',
56-
plugins: ['babel', 'prettier', 'import', '@typescript-eslint'],
57+
plugins: ['@babel', 'prettier', 'import', '@typescript-eslint'],
5758
extends: [
5859
'airbnb-typescript/base',
5960
'plugin:@typescript-eslint/eslint-recommended',
@@ -63,7 +64,7 @@ module.exports = {
6364
'plugin:prettier/recommended',
6465
],
6566
rules: {
66-
'prettier/prettier': ["error", { "endOfLine": "auto" }],
67+
'prettier/prettier': ['error', {endOfLine: 'auto'}],
6768
'no-underscore-dangle': 'off',
6869
camelcase: 'off',
6970
'no-param-reassign': ['error', {props: false}],

.flowconfig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[ignore]
2+
<PROJECT_ROOT>/node_modules/resolve/.*
23

34
[include]
45
src
@@ -9,9 +10,9 @@ flow-typed
910

1011

1112
[lints]
13+
untyped-type-import=warn
1214

1315
[options]
14-
esproposal.optional_chaining=enable
1516
module.file_ext=.js
1617
module.file_ext=.ts
1718

.npmignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ fixtures
99
.eslintrc.js
1010
babel.config.js
1111
prettier.config.js
12+
tsconfig.json
1213
dangerfile.js
1314
yarn.lock
1415
*.tgz
16+
flow-typed/**
17+
.gitattributes
18+
.github/**
19+
.husky/**

package.json

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -30,38 +30,40 @@
3030
"prepare": "husky install"
3131
},
3232
"devDependencies": {
33-
"@babel/cli": "^7.15.7",
34-
"@babel/core": "^7.15.5",
35-
"@babel/preset-env": "^7.15.6",
36-
"@babel/preset-flow": "^7.14.5",
37-
"@babel/preset-typescript": "^7.15.0",
38-
"@types/jest": "^27.0.1",
39-
"@typescript-eslint/eslint-plugin": "^4.31.1",
40-
"@typescript-eslint/parser": "^4.31.1",
41-
"babel-eslint": "^10.1.0",
42-
"babel-jest": "^27.2.0",
43-
"eslint": "^7.32.0",
44-
"eslint-config-airbnb-base": "^14.2.1",
45-
"eslint-config-airbnb-typescript": "^14.0.0",
46-
"eslint-config-prettier": "^8.3.0",
47-
"eslint-import-resolver-typescript": "^2.5.0",
48-
"eslint-plugin-babel": "^5.3.1",
49-
"eslint-plugin-flowtype": "^6.0.1",
50-
"eslint-plugin-import": "^2.24.2",
51-
"eslint-plugin-prettier": "^4.0.0",
52-
"flow-bin": "^0.97.0",
33+
"@babel/cli": "^7.19.3",
34+
"@babel/core": "^7.20.5",
35+
"@babel/eslint-parser": "^7.19.1",
36+
"@babel/eslint-plugin": "^7.19.1",
37+
"@babel/plugin-transform-react-jsx": "^7.19.0",
38+
"@babel/preset-env": "^7.20.2",
39+
"@babel/preset-flow": "^7.18.6",
40+
"@babel/preset-typescript": "^7.18.6",
41+
"@types/jest": "^29.2.4",
42+
"@types/node": "^18.11.16",
43+
"@typescript-eslint/eslint-plugin": "^5.46.1",
44+
"@typescript-eslint/parser": "^5.46.1",
45+
"babel-jest": "^29.3.1",
46+
"eslint": "^8.29.0",
47+
"eslint-config-airbnb-base": "^15.0.0",
48+
"eslint-config-airbnb-typescript": "^17.0.0",
49+
"eslint-config-prettier": "^8.5.0",
50+
"eslint-import-resolver-typescript": "^3.5.2",
51+
"eslint-plugin-flowtype": "^8.0.3",
52+
"eslint-plugin-import": "^2.26.0",
53+
"eslint-plugin-prettier": "^4.2.1",
54+
"flow-bin": "^0.196.0",
5355
"husky": ">=7.0.2",
54-
"jest": "^27.2.0",
56+
"jest": "^29.3.1",
5557
"lint-staged": ">=11.1.2",
56-
"prettier": "^2.4.1",
57-
"typescript": "^4.4.3"
58+
"prettier": "^2.8.1",
59+
"typescript": "^4.9.4"
5860
},
5961
"dependencies": {
60-
"@babel/parser": "^7.15.7",
61-
"@babel/runtime": "^7.15.4",
62-
"@babel/traverse": "^7.15.4",
63-
"@babel/types": "^7.15.6",
64-
"@jest/types": "^27.1.1",
62+
"@babel/parser": "^7.20.5",
63+
"@babel/runtime": "^7.20.6",
64+
"@babel/traverse": "^7.20.5",
65+
"@babel/types": "^7.20.5",
66+
"@jest/types": "^29.3.1",
6567
"core-js": "^3.17.3",
6668
"jest-snapshot": "^27.2.0"
6769
},

src/Runner.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@ import {createProcess} from './Process';
2121
// passes out events when it understands what data is being
2222
// pass sent out of the process
2323
export default class Runner extends EventEmitter {
24-
debugprocess: ChildProcess;
24+
debugprocess: ?ChildProcess;
2525

2626
outputPath: string;
2727

28+
// $FlowIgnore[value-as-type]
2829
workspace: ProjectWorkspace;
2930

31+
// $FlowIgnore[value-as-type]
3032
_createProcess: (workspace: ProjectWorkspace, args: Array<string>) => ChildProcess;
3133

3234
watchMode: boolean;
@@ -39,6 +41,7 @@ export default class Runner extends EventEmitter {
3941

4042
_exited: boolean;
4143

44+
// $FlowIgnore[value-as-type]
4245
constructor(workspace: ProjectWorkspace, options?: Options) {
4346
super();
4447

@@ -97,17 +100,18 @@ export default class Runner extends EventEmitter {
97100
this.watchAll = watchAll;
98101

99102
const args = this._getArgs();
100-
this.debugprocess = this._createProcess(this.workspace, args);
101-
this.debugprocess.stdout.on('data', (data: Buffer) => {
103+
const debugprocess = this._createProcess(this.workspace, args);
104+
this.debugprocess = debugprocess;
105+
debugprocess.stdout.on('data', (data: Buffer) => {
102106
this._parseOutput(data, false);
103107
});
104108

105-
this.debugprocess.stderr.on('data', (data: Buffer) => {
109+
debugprocess.stderr.on('data', (data: Buffer) => {
106110
// jest 23 could send test results message to stderr
107111
// see https://github.com/facebook/jest/pull/4858
108112
this._parseOutput(data, true);
109113
});
110-
this.debugprocess.on('exit', (code: number | null, signal: string | null) => {
114+
debugprocess.on('exit', (code: number | null, signal: string | null) => {
111115
this._exited = true;
112116

113117
// this is mainly for backward compatibility, should be deprecated soon
@@ -117,12 +121,12 @@ export default class Runner extends EventEmitter {
117121
this.prevMessageTypes.length = 0;
118122
});
119123

120-
this.debugprocess.on('error', (error: Error) => {
124+
debugprocess.on('error', (error: Error) => {
121125
this.emit('terminalError', `Process failed: ${error.message}`);
122126
this.prevMessageTypes.length = 0;
123127
});
124128

125-
this.debugprocess.on('close', (code: number | null, signal: string | null) => {
129+
debugprocess.on('close', (code: number | null, signal: string | null) => {
126130
// this is mainly for backward compatibility, should be deprecated soon
127131
this.emit('debuggerProcessExit');
128132

@@ -216,13 +220,15 @@ export default class Runner extends EventEmitter {
216220
// knowing this could leave orphan process...
217221
// eslint-disable-next-line no-console
218222
console.warn(
219-
`failed to kill process group, this could leave some orphan process whose ppid=${this.debugprocess.pid}. error=`,
223+
`failed to kill process group, this could leave some orphan process whose ppid=${
224+
this.debugprocess?.pid || 'process-non-exist'
225+
}. error=`,
220226
e
221227
);
222-
this.debugprocess.kill();
228+
this.debugprocess?.kill();
223229
}
224230
}
225-
delete this.debugprocess;
231+
this.debugprocess = undefined;
226232
}
227233

228234
// eslint-disable-next-line class-methods-use-this
@@ -242,7 +248,7 @@ export default class Runner extends EventEmitter {
242248
return match ? match.messageType : messageTypes.unknown;
243249
}
244250

245-
doResultsFollowNoTestsFoundMessage() {
251+
doResultsFollowNoTestsFoundMessage(): boolean {
246252
if (this.prevMessageTypes.length === 1) {
247253
return this.prevMessageTypes[0] === messageTypes.noTests;
248254
}

src/Settings.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
import type {Options} from './types';
11-
import ProjectWorkspace from './project_workspace';
11+
import type ProjectWorkspace from './project_workspace';
1212
import {createProcess} from './Process';
1313

1414
type Glob = string;
@@ -30,7 +30,7 @@ type JestSettings = {
3030
};
3131

3232
function parseSettings(text: string, debug: ?boolean = false): JestSettings {
33-
const jsonPattern = new RegExp(/^[\s]*\{/gm);
33+
const jsonPattern = /^[\s]*\{/gm;
3434
let settings = null;
3535

3636
try {
@@ -62,6 +62,7 @@ function parseSettings(text: string, debug: ?boolean = false): JestSettings {
6262
};
6363
}
6464

65+
// $FlowIgnore[value-as-type]
6566
export default function getSettings(workspace: ProjectWorkspace, options?: Options): Promise<JestSettings> {
6667
return new Promise((resolve, reject) => {
6768
const _createProcess = (options && options.createProcess) || createProcess;

src/Snapshot.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010

1111
import traverse from '@babel/traverse';
12-
import {buildSnapshotResolver, SnapshotResolver, utils, SnapshotData} from 'jest-snapshot';
12+
import {buildSnapshotResolver, type SnapshotResolver, type SnapshotData, utils} from 'jest-snapshot';
1313
import type {ProjectConfig} from '../types/Config';
1414

1515
import {getASTfor} from './parsers/babel_parser';
@@ -49,16 +49,16 @@ const validParents = Object.assign(
4949
})
5050
);
5151

52-
const isValidMemberExpression = (node) =>
52+
const isValidMemberExpression = (node: any) =>
5353
node.object && base[node.object.name] && node.property && decorators[node.property.name];
5454

55-
const isDescribe = (node) =>
55+
const isDescribe = (node: any) =>
5656
describeVariants[node.name] || (isValidMemberExpression(node) && node.object.name === 'describe');
5757

58-
const isValidParent = (parent) =>
58+
const isValidParent = (parent: any) =>
5959
parent.callee && (validParents[parent.callee.name] || isValidMemberExpression(parent.callee));
6060

61-
const getArrayOfParents = (path) => {
61+
const getArrayOfParents = (path: any) => {
6262
const result = [];
6363
let parent = path.parentPath;
6464
while (parent) {
@@ -90,8 +90,10 @@ export default class Snapshot {
9090

9191
_projectConfig: ?ProjectConfig;
9292

93+
// $FlowIgnore[value-as-type]
9394
snapshotResolver: ?SnapshotResolver;
9495

96+
// $FlowIgnore[value-as-type]
9597
_resolverPromise: Promise<SnapshotResolver>;
9698

9799
constructor(parser: any, customMatchers?: Array<string>, projectConfig?: ProjectConfig) {
@@ -118,7 +120,7 @@ export default class Snapshot {
118120
}
119121

120122
const Visitors = {
121-
Identifier(path, found, matchers) {
123+
Identifier(path: any, found: any, matchers: any) {
122124
if (matchers.indexOf(path.node.name) >= 0) {
123125
found.push({
124126
node: path.node,
@@ -145,6 +147,7 @@ export default class Snapshot {
145147
}));
146148
}
147149

150+
// $FlowIgnore[value-as-type]
148151
async _getSnapshotResolver(): Promise<SnapshotResolver> {
149152
if (!this.snapshotResolver) {
150153
await this._resolverPromise;
@@ -160,6 +163,7 @@ export default class Snapshot {
160163
* a SnapshotData object will be returned with all matched snapshots. If nothing matched, null will be returned.
161164
* @throws throws exception if the snapshot version mismatched or any other unexpected error.
162165
*/
166+
// $FlowIgnore[value-as-type]
163167
async getSnapshotContent(filePath: string, name: string | RegExp): Promise<string | SnapshotData | null> {
164168
const snapshotResolver = await this._getSnapshotResolver();
165169

@@ -169,6 +173,7 @@ export default class Snapshot {
169173
return snapshots[name];
170174
}
171175
const regex = name;
176+
// $FlowIgnore[value-as-type]
172177
const data: SnapshotData = {};
173178
Object.entries(snapshots).forEach(([key, value]) => {
174179
if (regex.test(key)) {

src/__tests__/parsers/babel_parser.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/no-unsafe-argument */
12
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
23
/* eslint-disable @typescript-eslint/no-unsafe-call */
34
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
@@ -1012,6 +1013,21 @@ describe('parsers', () => {
10121013
const itBlock = parseResult.itBlocks[0];
10131014
assertBlock2(itBlock, 2, 11, 4, 13, 'should parse');
10141015
});
1016+
it('https://github.com/jest-community/jest-editor-support/issues/96', () => {
1017+
const data = `
1018+
import { asMockedFunction, type AnyFunction } from '@whatever/jest-types';
1019+
test('a test', () => {
1020+
expect(true).toBe(true);
1021+
});
1022+
`;
1023+
const parseResult = parseFunction('whatever', data);
1024+
expect(parseResult.itBlocks.length).toEqual(1);
1025+
1026+
const name = 'a test';
1027+
const itBlock = parseResult.itBlocks[0];
1028+
assertBlock2(itBlock, 3, 9, 5, 11, name);
1029+
assertNameInfo(itBlock, name, 3, 15, 3, 20);
1030+
});
10151031
});
10161032
});
10171033
});

src/__tests__/parsers/parser_nodes.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ describe('ParsedNode', () => {
5353
it('throws an error when adding an unknown child', async () => {
5454
const root = new ParsedNode('describe', 'a/b/c');
5555
expect(() => {
56+
// $FlowIgnore[prop-missing]
5657
root.addChild('unknown');
5758
}).toThrow(TypeError);
5859
});

src/__tests__/process.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/no-unsafe-argument */
12
/* eslint-disable @typescript-eslint/no-explicit-any */
23
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
34
/* eslint-disable @typescript-eslint/no-unsafe-call */

0 commit comments

Comments
 (0)