Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
connectdotz committed Apr 11, 2024
1 parent b9c3c5b commit 49dc972
Show file tree
Hide file tree
Showing 24 changed files with 576 additions and 2,068 deletions.
132 changes: 37 additions & 95 deletions .eslintrc.js
@@ -1,116 +1,58 @@
module.exports = {
root: true,
env: {
es6: true,
node: true,
browser: true,
jest: true,
},
globals: {
Atomics: 'readonly',
SharedArrayBuffer: 'readonly',
},
settings: {
'import/parsers': {
'@babel/eslint-parser': ['.js'],
'@typescript-eslint/parser': ['.ts'],
},
'import/resolver': {
node: true,
'eslint-import-resolver-typescript': true,
},
},
parser: '@babel/eslint-parser',
parserOptions: {
sourceType: 'module',
babelOptions: {
// configuration for @babel/eslint-parser
configFile: './babel.config.js',
},
// configuration for @typescript-eslint
project: 'tsconfig.json',
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint', 'prettier'],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'prettier',
'plugin:prettier/recommended',
],
rules: {
'prettier/prettier': 'error',
// too many tests to fix, disable for now
'@typescript-eslint/ban-types': 'off',
// customize argument ignore pattern
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': ['error', {argsIgnorePattern: '^_'}],
},
overrides: [
// linting setup for JS files.
{
files: '**/*.js',
parser: '@babel/eslint-parser',
plugins: ['@babel', 'prettier', 'import'],
extends: ['airbnb-base', 'prettier', 'plugin:prettier/recommended'],
files: ['**/__tests__/**/*.ts', '**/*.test.ts', '**/*.spec.ts'],
env: {
jest: true,
'jest/globals': true,
},
plugins: ['jest'],
extends: ['plugin:jest/recommended'],
rules: {
'prettier/prettier': ['error', {endOfLine: 'auto'}],
'no-underscore-dangle': 'off',
camelcase: 'off',
'no-param-reassign': ['error', {props: false}],
'import/extensions': [0, 'never', {ts: 'never'}],
'import/named': 'off',
'import/namespace': 'off',
'import/default': 'off',
'import/no-named-as-default-member': 'off',
'import/no-named-as-default': 'off',
'max-classes-per-file': 'off',
'prefer-object-spread': 'off',
'@typescript-eslint/restrict-template-expressions': [
2,
{
allowNumber: true,
allowBoolean: true,
allowAny: true,
allowNullish: true,
},
],
// Test-specific rules
'no-empty-function': 'off',
'no-unused-expressions': 'off',
// jest specific
'jest/no-conditional-expect': 'off',
// Any other rule adjustments for test files
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
},
},
// linting setup for TS files.
{
files: '**/*.ts',
plugins: ['@babel', 'prettier', 'import', '@typescript-eslint'],
extends: [
'airbnb-typescript/base',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
'prettier',
'plugin:prettier/recommended',
],
files: ['src/**/*.ts'],
rules: {
'prettier/prettier': ['error', {endOfLine: 'auto'}],
'no-underscore-dangle': 'off',
camelcase: 'off',
'no-param-reassign': ['error', {props: false}],
'import/extensions': [0, 'never', {ts: 'never'}],
'import/named': 'off',
'import/namespace': 'off',
'import/default': 'off',
'import/no-named-as-default-member': 'off',
'import/no-named-as-default': 'off',
'max-classes-per-file': 'off',
// TS specific
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/prefer-regexp-exec': 'off',
'@typescript-eslint/array-type': [
'error',
{
default: 'array',
readonly: 'array',
},
],
'@typescript-eslint/naming-convention': [
'error',
{
selector: 'variable',
format: ['camelCase', 'UPPER_CASE', 'PascalCase', 'snake_case'],
leadingUnderscore: 'allow', // Allows leading underscores for variables
},
{
selector: 'function',
format: ['camelCase'],
leadingUnderscore: 'allow', // Allows leading underscores for functions
},
{
selector: 'typeLike',
format: ['PascalCase'], // Enforces PascalCase for types and interfaces
},
],
// Source file specific rules
},
},
],
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -2,4 +2,5 @@ node_modules/
build/
coverage/
*.tgz
.eslintcache
.eslintcache
index.d.ts
1 change: 1 addition & 0 deletions .npmignore
Expand Up @@ -10,6 +10,7 @@ fixtures
babel.config.js
prettier.config.js
tsconfig.json
tsconfig.*.json
dangerfile.js
yarn.lock
*.tgz
Expand Down
6 changes: 0 additions & 6 deletions babel.config.js

This file was deleted.

51 changes: 21 additions & 30 deletions package.json
@@ -1,71 +1,62 @@
{
"name": "jest-editor-support",
"version": "31.1.2",
"version": "32.0.0-beta.0",
"repository": {
"type": "git",
"url": "https://github.com/jest-community/jest-editor-support"
},
"license": "MIT",
"main": "build/index.js",
"scripts": {
"build": "babel src/ -d build/ --extensions \".js,.ts\" --source-maps inline",
"build:types": "tsc --emitDeclarationOnly && rm build/index.d.ts",
"prepublish": "yarn build:types && yarn build",
"clean": "rimraf ./build ./index.d.ts",
"build": "tsc --noEmit",
"build:types": "dts-bundle-generator -o ./index.d.ts src/index.ts",
"build:prod": "yarn clean & tsc -p tsconfig.prod.json",
"prepublish": "yarn build:prod && yarn build:types",
"test": "jest",
"lint": "eslint \"?(__mocks__|src|tests)/**/*.+(js|ts)\" ",
"lint:fix": "eslint \"?(__mocks__|src|tests)/**/*.+(js|ts)\" --fix",
"ci": "yarn type-check && yarn lint && yarn test --coverage && yarn type-check",
"ci": "yarn build && yarn lint && yarn test --coverage",
"prettier": "prettier --check \"?(__mocks__|src|tests)/**/*.+(js|ts)\" ",
"prettier-write": "prettier --write",
"prettier-project": "yarn prettier-write \"?(__mocks__|src|tests)/**/*.+(js|ts)\" ",
"type-check": "tsc --noEmit",
"type-check:watch": "yarn type-check -- --watch"
"prettier-project": "yarn prettier-write \"?(__mocks__|src|tests)/**/*.+(js|ts)\" "
},
"devDependencies": {
"@babel/cli": "^7.19.3",
"@babel/core": "^7.20.12",
"@babel/eslint-parser": "^7.19.1",
"@babel/eslint-plugin": "^7.19.1",
"@babel/plugin-transform-react-jsx": "^7.19.0",
"@babel/preset-env": "^7.20.2",
"@babel/preset-typescript": "^7.18.6",
"@jest/types": "^29.3.1",
"@types/jest": "^29.2.4",
"@types/node": "^18.11.16",
"@typescript-eslint/eslint-plugin": "^5.46.1",
"@typescript-eslint/parser": "^5.46.1",
"babel-jest": "^29.3.1",
"eslint": "^8.29.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-airbnb-typescript": "^17.0.0",
"eslint-config-prettier": "^8.5.0",
"eslint-import-resolver-typescript": "^3.5.2",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-prettier": "^4.2.1",
"dts-bundle-generator": "^9.3.1",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-jest": "^27.9.0",
"eslint-plugin-prettier": "^5.1.3",
"jest": "^29.3.1",
"prettier": "^2.8.1",
"prettier": "^3.2.5",
"rimraf": "^5.0.5",
"ts-jest": "^29.1.2",
"typescript": "^5.4.2"
},
"dependencies": {
"@babel/parser": "^7.20.7",
"@babel/runtime": "^7.20.7",
"@babel/traverse": "7.23.2",
"@babel/types": "^7.20.7",
"core-js": "^3.17.3",
"@jest/test-result": "^29.3.1",
"@jest/types": "^29.3.1",
"jest-snapshot": "^27.2.0"
},
"jest": {
"preset": "ts-jest",
"testEnvironment": "node",
"testPathIgnorePatterns": [
"<rootDir>/node_modules/",
"<rootDir>/build/",
"<rootDir>/fixtures/"
],
"coveragePathIgnorePatterns": [
"<rootDir>/fixtures/"
],
"transform": {
"^.+\\.[t|j]sx?$": "babel-jest"
}
]
},
"typings": "index.d.ts"
}
8 changes: 8 additions & 0 deletions prettier.config.js
Expand Up @@ -5,4 +5,12 @@ module.exports = {
singleQuote: true,
printWidth: 120,
bracketSpacing: false,
overrides: [
{
files: '*.ts',
options: {
parser: 'typescript',
},
},
],
};
1 change: 0 additions & 1 deletion src/Process.ts
Expand Up @@ -19,7 +19,6 @@ const isLoginShell = (arg: any): arg is LoginShell => arg && typeof arg.path ===
* @param {string[]} args
* @returns {ChildProcess}
*/
// eslint-disable-next-line import/prefer-default-export
export const createProcess = (workspace: ProjectWorkspace, args: string[]): ChildProcess => {
const runtimeExecutable = [workspace.jestCommandLine, ...args];

Expand Down
28 changes: 18 additions & 10 deletions src/Runner.ts
Expand Up @@ -10,11 +10,19 @@ import {readFile} from 'fs';
import {tmpdir} from 'os';
import * as path from 'path';
import EventEmitter from 'events';
import {messageTypes} from './types';
import {MessageTypes} from './types';
import type {Options, MessageType} from './types';
import ProjectWorkspace from './project_workspace';
import {createProcess} from './Process';

export type RunnerEvent =
| 'processClose'
| 'processExit'
| 'executableJSON'
| 'executableStdErr'
| 'executableOutput'
| 'terminalError';

// This class represents the running process, and
// passes out events when it understands what data is being
// pass sent out of the process
Expand Down Expand Up @@ -160,7 +168,7 @@ export default class Runner extends EventEmitter {
_parseOutput(data: Buffer, isStdErr: boolean): MessageType {
const msgType = this.findMessageType(data);
switch (msgType) {
case messageTypes.testResults:
case MessageTypes.testResults:
this.emit('executableStdErr', data, {
type: msgType,
});
Expand All @@ -177,8 +185,8 @@ export default class Runner extends EventEmitter {
});
this.prevMessageTypes.length = 0;
break;
case messageTypes.watchUsage:
case messageTypes.noTests:
case MessageTypes.watchUsage:
case MessageTypes.noTests:
this.prevMessageTypes.push(msgType);
this.emit('executableStdErr', data, {
type: msgType,
Expand Down Expand Up @@ -247,23 +255,23 @@ export default class Runner extends EventEmitter {
const testResultsRegex = /Test results written to/;

const checks = [
{regex: testResultsRegex, messageType: messageTypes.testResults},
{regex: noTestRegex, messageType: messageTypes.noTests},
{regex: watchUsageRegex, messageType: messageTypes.watchUsage},
{regex: testResultsRegex, messageType: MessageTypes.testResults},
{regex: noTestRegex, messageType: MessageTypes.noTests},
{regex: watchUsageRegex, messageType: MessageTypes.watchUsage},
];

const str = buf.toString('utf8');
const match = checks.find(({regex}) => regex.test(str));
return match ? match.messageType : messageTypes.unknown;
return match ? match.messageType : MessageTypes.unknown;
}

doResultsFollowNoTestsFoundMessage(): boolean {
if (this.prevMessageTypes.length === 1) {
return this.prevMessageTypes[0] === messageTypes.noTests;
return this.prevMessageTypes[0] === MessageTypes.noTests;
}

if (this.prevMessageTypes.length === 2) {
return this.prevMessageTypes[0] === messageTypes.noTests && this.prevMessageTypes[1] === messageTypes.watchUsage;
return this.prevMessageTypes[0] === MessageTypes.noTests && this.prevMessageTypes[1] === MessageTypes.watchUsage;
}

return false;
Expand Down

0 comments on commit 49dc972

Please sign in to comment.