From 347fc02329f3aaf36a409c50871db2163540b821 Mon Sep 17 00:00:00 2001 From: Oleksandr Pankiv <824807+lexpank@users.noreply.github.com> Date: Thu, 11 Dec 2025 16:22:15 +0100 Subject: [PATCH] (chore) Opslevel compliance --- .eslintignore | 4 ---- .eslintrc | 6 ------ eslint.config.cjs | 20 ++++++++++++++++++++ jest-preset.cjs | 3 +++ jest-preset.js | 5 ++--- package.json | 39 +++++++++++++++++++++++---------------- readme.md | 21 ++++++++++----------- src/config.cjs.d.ts | 2 ++ src/config.ts | 8 ++++---- src/index.ts | 4 ++-- src/setup.ts | 6 ++++-- src/teardown.ts | 4 +++- 12 files changed, 73 insertions(+), 49 deletions(-) delete mode 100755 .eslintignore delete mode 100644 .eslintrc create mode 100644 eslint.config.cjs create mode 100644 jest-preset.cjs create mode 100644 src/config.cjs.d.ts diff --git a/.eslintignore b/.eslintignore deleted file mode 100755 index 94e2829..0000000 --- a/.eslintignore +++ /dev/null @@ -1,4 +0,0 @@ -coverage/ -lib/ -renovate.json -tsconfig.json diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index 472eed7..0000000 --- a/.eslintrc +++ /dev/null @@ -1,6 +0,0 @@ -{ - "root": true, - "extends": [ - "@shelf/eslint-config/typescript" - ] -} diff --git a/eslint.config.cjs b/eslint.config.cjs new file mode 100644 index 0000000..34b75a2 --- /dev/null +++ b/eslint.config.cjs @@ -0,0 +1,20 @@ +const baseConfig = require('@shelf/eslint-config/typescript').default; + +module.exports = [ + { + ignores: ['coverage/**', 'lib/**', 'renovate.json', 'tsconfig.json'], + }, + ...baseConfig, + { + files: [ + 'eslint.config.cjs', + 'jest-preset.cjs', + 'src/config.ts', + 'src/setup.ts', + 'src/teardown.ts', + ], + rules: { + '@typescript-eslint/no-require-imports': 'off', + }, + }, +]; diff --git a/jest-preset.cjs b/jest-preset.cjs new file mode 100644 index 0000000..d5b9d6b --- /dev/null +++ b/jest-preset.cjs @@ -0,0 +1,3 @@ +const preset = require('./lib/index.cjs'); + +module.exports = preset; diff --git a/jest-preset.js b/jest-preset.js index 0699e09..527d3b7 100644 --- a/jest-preset.js +++ b/jest-preset.js @@ -1,4 +1,3 @@ -// eslint-disable-next-line @typescript-eslint/no-var-requires -const preset = require('./lib'); +import preset from './jest-preset.cjs'; -module.exports = preset; +export default preset; diff --git a/package.json b/package.json index 14b62c2..d983af4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,8 @@ { "name": "@shelf/jest-gremlin", "version": "2.0.0", + "type": "module", + "main": "./lib/index.cjs", "private": false, "description": "Run your tests using Jest & Apache Tinkerpop Docker container", "keywords": [ @@ -18,11 +20,11 @@ "url": "shelf.io" }, "files": [ - "jest-preset.js", + "jest-preset.cjs", "lib/" ], "scripts": { - "build": "rm -rf lib/ && yarn build:types && babel src --out-dir lib --ignore '**/*.test.ts' --extensions '.ts'", + "build": "rm -rf lib/ && yarn build:types && babel src --out-dir lib --ignore '**/*.test.ts' --extensions '.ts' --out-file-extension .cjs", "build:types": "tsc --emitDeclarationOnly --declaration --isolatedModules false --declarationDir lib", "lint": "eslint . --ext .js,.ts,.json --fix", "lint:ci": "eslint . --ext .js,.ts,.json", @@ -35,37 +37,42 @@ "extends": "@shelf/babel-config/backend" }, "prettier": "@shelf/prettier-config", + "exports": { + ".": "./lib/index.cjs", + "./jest-preset": "./jest-preset.cjs", + "./package.json": "./package.json" + }, "jest": { - "preset": "./jest-preset.js" + "preset": "./jest-preset.cjs" }, "dependencies": { - "debug": "4.3.7", - "gremlin": "3.7.0" + "debug": "4.4.3", + "gremlin": "3.8.0" }, "devDependencies": { "@babel/cli": "7.23.9", "@babel/core": "7.23.9", "@shelf/babel-config": "3.0.0", - "@shelf/eslint-config": "3.15.1", + "@shelf/eslint-config": "5.4.0", "@shelf/prettier-config": "1.0.0", "@shelf/tsconfig": "0.1.0", - "@size-limit/preset-small-lib": "11.1.5", + "@size-limit/preset-small-lib": "12.0.0", "@types/cwd": "0.10.2", "@types/debug": "4.1.12", - "@types/dockerode": "^3.3.31", + "@types/dockerode": "^3.3.47", "@types/gremlin": "^3.6.7", - "@types/jest": "29.5.13", + "@types/jest": "30.0.0", "@types/node": "20.16.10", "cwd": "0.10.0", - "eslint": "8.57.1", + "eslint": "9.39.1", "fast-diff": "^1.3.0", - "husky": "9.0.11", - "jest": "29.7.0", - "lint-staged": "15.2.10", - "prettier": "3.3.3", - "size-limit": "11.1.5", + "husky": "9.1.7", + "jest": "30.2.0", + "lint-staged": "16.2.7", + "prettier": "3.7.4", + "size-limit": "12.0.0", "ts-node": "10.9.2", - "typescript": "5.6.2" + "typescript": "5.9.3" }, "engines": { "node": ">=20" diff --git a/readme.md b/readme.md index 4c91d07..d40e26a 100644 --- a/readme.md +++ b/readme.md @@ -13,7 +13,7 @@ This plugin tested with [Docker](https://docs.docker.com/get-docker/) and [Podma $ yarn add @shelf/jest-gremlin --dev ``` -### 3. Create `jest.config.js` +### 3. Create `jest.config.cjs` ```js module.exports = { @@ -21,12 +21,12 @@ module.exports = { }; ``` -If you have a custom `jest.config.js` make sure you remove `testEnvironment` property, otherwise it will conflict with the preset. +If you have a custom `jest.config.cjs` make sure you remove `testEnvironment` property, otherwise it will conflict with the preset. -### 4. Create `jest-gremlin-config.js` +### 4. Create `jest-gremlin-config.cjs` ```js -import cwd from 'cwd'; +const cwd = require('cwd'); module.exports = { port: 8182, @@ -48,23 +48,22 @@ it(); ## Monorepo Support -By default the `jest-gremlin-config.js` is read from `cwd` directory, but this might not be +By default the `jest-gremlin-config.cjs` is read from `cwd` directory, but this might not be suitable for monorepos with nested [jest projects](https://jestjs.io/docs/configuration#projects-arraystring--projectconfig) with nested `jest.config.*` files nested in subdirectories. -If your `jest-gremlin-config.js` file is not located at `{cwd}/jest-gremlin-config.js` or you +If your `jest-gremlin-config.cjs` file is not located at `{cwd}/jest-gremlin-config.cjs` or you are using nested `jest projects`, you can define the environment variable `JEST_GREMLIN_CONFIG` -with the absolute path of the respective `jest-gremlin-config.js` file. +with the absolute path of the respective `jest-gremlin-config.cjs` file. ### Example Using `JEST_GREMLIN_CONFIG` in nested project ```js -// src/nested/project/jest.config.js +// src/nested/project/jest.config.cjs const path = require('path'); -// Define path of project level config - extension not required as file will be imported -// via `require(process.env.JEST_GREMLIN_CONFIG)` -process.env.JEST_GREMLIN_CONFIG = path.resolve(__dirname, './jest-gremlin-config'); +// Define path of project level config +process.env.JEST_GREMLIN_CONFIG = path.resolve(__dirname, './jest-gremlin-config.cjs'); module.exports = { preset: '@shelf/jest-gremlin', diff --git a/src/config.cjs.d.ts b/src/config.cjs.d.ts new file mode 100644 index 0000000..5f30e31 --- /dev/null +++ b/src/config.cjs.d.ts @@ -0,0 +1,2 @@ +export {getConfig} from './config'; +export type {Config} from './config'; diff --git a/src/config.ts b/src/config.ts index 306c692..d9e38e1 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,9 +1,9 @@ import {resolve} from 'path'; import cwd from 'cwd'; -const DEFAULT_CONFIG_FILE_NAME = 'jest-gremlin-config.cjs'; +const DEFAULT_CONFIG_FILE = 'jest-gremlin-config.cjs'; -type Config = { +export type Config = { port: number; protocol: string; containerEngine: 'podman' | 'docker'; @@ -27,8 +27,8 @@ export function getConfig(): Config { }; try { - const path = process.env.JEST_GREMLIN_CONFIG || resolve(cwd(), DEFAULT_CONFIG_FILE_NAME); - // eslint-disable-next-line @typescript-eslint/no-var-requires + const path = process.env.JEST_GREMLIN_CONFIG || resolve(cwd(), DEFAULT_CONFIG_FILE); + const importedConfig = require(path); console.log(`Found config ${path}`, importedConfig); diff --git a/src/index.ts b/src/index.ts index 3da5542..ec53071 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,6 @@ import {resolve} from 'path'; module.exports = { - globalSetup: resolve(__dirname, './setup.js'), - globalTeardown: resolve(__dirname, './teardown.js'), + globalSetup: resolve(__dirname, './setup.cjs'), + globalTeardown: resolve(__dirname, './teardown.cjs'), }; diff --git a/src/setup.ts b/src/setup.ts index 43202ee..392590b 100644 --- a/src/setup.ts +++ b/src/setup.ts @@ -1,6 +1,8 @@ import {execSync} from 'child_process'; import gremlin from 'gremlin'; -import {getConfig} from './config'; +import type {Config} from './config'; + +const {getConfig}: {getConfig: () => Config} = require('./config.cjs'); const {DriverRemoteConnection} = gremlin.driver; const {Graph} = gremlin.structure; @@ -31,7 +33,7 @@ module.exports = async function startGremlin() { await g.V().limit(1).toList(); return true; - } catch (e) { + } catch { return false; } }; diff --git a/src/teardown.ts b/src/teardown.ts index e86d947..2f03c12 100644 --- a/src/teardown.ts +++ b/src/teardown.ts @@ -1,5 +1,7 @@ import {execSync} from 'child_process'; -import {getConfig} from './config'; +import type {Config} from './config'; + +const {getConfig}: {getConfig: () => Config} = require('./config.cjs'); module.exports = function stopGremlin() { const config = getConfig();