Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .eslintignore

This file was deleted.

6 changes: 0 additions & 6 deletions .eslintrc

This file was deleted.

20 changes: 20 additions & 0 deletions eslint.config.cjs
Original file line number Diff line number Diff line change
@@ -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',
},
},
];
3 changes: 3 additions & 0 deletions jest-preset.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const preset = require('./lib/index.cjs');

module.exports = preset;
5 changes: 2 additions & 3 deletions jest-preset.js
Original file line number Diff line number Diff line change
@@ -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;
39 changes: 23 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand All @@ -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",
Expand All @@ -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"
Expand Down
21 changes: 10 additions & 11 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ 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 = {
preset: '@shelf/jest-gremlin',
};
```

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,
Expand All @@ -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',
Expand Down
2 changes: 2 additions & 0 deletions src/config.cjs.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export {getConfig} from './config';
export type {Config} from './config';
8 changes: 4 additions & 4 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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'),
};
6 changes: 4 additions & 2 deletions src/setup.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -31,7 +33,7 @@ module.exports = async function startGremlin() {
await g.V().limit(1).toList();

return true;
} catch (e) {
} catch {
return false;
}
};
Expand Down
4 changes: 3 additions & 1 deletion src/teardown.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
Loading