Skip to content

Commit e037fcb

Browse files
authored
Merge pull request #503 from shelfio/feature/fix-ci-build-job
Enable CircleCI runs, move to complete pnpm usage
2 parents 5d5fb9a + c0e832e commit e037fcb

File tree

8 files changed

+53
-29
lines changed

8 files changed

+53
-29
lines changed

.circleci/config.yml

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: 2.1
22

33
orbs:
4-
node: circleci/node@7.0.0
4+
node: circleci/node@7.1.0
55

66
parameters:
77
node_version:
@@ -12,24 +12,31 @@ commands:
1212
install_deps:
1313
steps:
1414
- run: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> .npmrc
15+
- node/install-pnpm:
16+
version: 9.15.4
1517
- node/install-packages:
16-
pkg-manager: yarn
17-
cache-version: v1-all
18+
pkg-manager: pnpm
1819
cache-only-lockfile: true
19-
app-dir: ~/repo
20-
override-ci-command: yarn install --pure-lockfile --no-progress
20+
# Default command is 'pnpm install --frozen-lockfile'.
21+
# 'pnpm install' fails with --frozen-lockfile option because it can't find the lockfile
22+
override-ci-command: pnpm install
2123

2224
jobs:
23-
build:
25+
build_and_test:
2426
executor:
25-
name: cimg/node
27+
name: node/default
2628
tag: << pipeline.parameters.node_version >>
2729
working_directory: ~/repo
2830
steps:
2931
- checkout
3032
- install_deps
31-
- run: yarn build
32-
- run: yarn test
33-
- run: yarn test:repl
34-
- run: yarn lint:ci
35-
- run: yarn type-check
33+
- run: pnpm run type-check
34+
- run: pnpm run lint:ci
35+
- run: pnpm run build
36+
- run: pnpm run test
37+
- run: pnpm run test:repl
38+
39+
workflows:
40+
build_test:
41+
jobs:
42+
- build_and_test

.husky/pre-commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/bin/sh
22
. "$(dirname "$0")/_/husky.sh"
3-
yarn lint-staged
3+
pnpm exec lint-staged

eslint.config.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ import rules from '@shelf/eslint-config/typescript.js';
22

33
export default [
44
...rules,
5+
{
6+
rules: {
7+
'@typescript-eslint/no-var-requires': 'off',
8+
},
9+
},
510
{files: ['**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx', '**/*.json']},
611
{
712
ignores: [

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@
2121
"lib/"
2222
],
2323
"scripts": {
24-
"build": "rm -rf lib/ && yarn build:types && babel src --out-dir lib --ignore '**/*.test.ts' --extensions '.ts'",
24+
"build": "rm -rf lib/ && pnpm run build:types && babel src --out-dir lib --ignore '**/*.test.ts' --extensions '.ts'",
2525
"build:types": "tsc --emitDeclarationOnly --declaration --isolatedModules false --declarationDir lib",
26-
"lint": "yarn lint:ci --fix",
26+
"lint": "pnpm run lint:ci --fix",
2727
"lint:ci": "eslint . --quiet",
28-
"prepack": "yarn build",
28+
"prepack": "pnpm run build",
2929
"test": "jest",
3030
"test:repl": "MONGO_MEMORY_SERVER_FILE=jest-mongodb-config-repl.js jest",
3131
"type-check": "tsc --noEmit",
32-
"type-check:watch": "npm run type-check -- --watch"
32+
"type-check:watch": "pnpm run type-check --watch"
3333
},
3434
"lint-staged": {
3535
"*.{html,md,yml}": [
@@ -53,6 +53,7 @@
5353
"devDependencies": {
5454
"@babel/cli": "7.27.0",
5555
"@babel/core": "7.26.10",
56+
"@jest/environment": "29.7.0",
5657
"@shelf/babel-config": "1.2.0",
5758
"@shelf/eslint-config": "4.2.1",
5859
"@shelf/prettier-config": "1.0.0",

readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,8 @@ module.exports = {
196196

197197
```sh
198198
$ git checkout master
199-
$ yarn version
200-
$ yarn publish
199+
$ pnpm version
200+
$ pnpm publish
201201
$ git push origin master --tags
202202
```
203203

src/environment.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ import {TestEnvironment} from 'jest-environment-node';
55
import {MongoMemoryReplSet, MongoMemoryServer} from 'mongodb-memory-server';
66
import type {EnvironmentContext} from '@jest/environment';
77
import type {JestEnvironmentConfig} from '@jest/environment';
8-
import {getMongodbMemoryOptions} from './helpers';
8+
import {getMongodbMemoryOptions, isMongoMemoryReplSetOptions} from './helpers';
99

10-
// eslint-disable-next-line import/order
1110
const debug = require('debug')('jest-mongodb:environment');
1211

1312
module.exports = class MongoEnvironment extends TestEnvironment {
@@ -18,7 +17,7 @@ module.exports = class MongoEnvironment extends TestEnvironment {
1817
this.globalConfigPath = pathJoin(config.globalConfig.rootDir, 'globalConfig.json');
1918

2019
const options = getMongodbMemoryOptions(config.globalConfig.rootDir);
21-
const isReplSet = Boolean(options.replSet);
20+
const isReplSet = isMongoMemoryReplSetOptions(options);
2221
debug(`isReplSet`, isReplSet);
2322

2423
this.mongo = isReplSet ? new MongoMemoryReplSet(options) : new MongoMemoryServer(options);

src/helpers.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,30 @@
11
import {resolve} from 'path';
2-
import {Config} from './types';
2+
import type {MongoMemoryReplSet, MongoMemoryServer} from 'mongodb-memory-server';
3+
import type {Config} from './types';
34

45
const configFile = process.env.MONGO_MEMORY_SERVER_FILE || 'jest-mongodb-config.js';
56

6-
export function getMongodbMemoryOptions(cwd: string) {
7+
type MongoMemoryReplSetOpts = NonNullable<ConstructorParameters<typeof MongoMemoryReplSet>[0]>;
8+
type MongoMemoryServerOpts = NonNullable<ConstructorParameters<typeof MongoMemoryServer>[0]>;
9+
10+
export function isMongoMemoryReplSetOptions(
11+
options?: MongoMemoryReplSetOpts | MongoMemoryServerOpts
12+
): options is MongoMemoryReplSetOpts {
13+
return Boolean((options as MongoMemoryReplSetOpts).replSet);
14+
}
15+
16+
export function getMongodbMemoryOptions(
17+
cwd: string
18+
): MongoMemoryReplSetOpts | MongoMemoryServerOpts | undefined {
719
try {
820
const {mongodbMemoryServerOptions}: Config = require(resolve(cwd, configFile));
921

1022
return mongodbMemoryServerOptions;
11-
} catch (e) {
23+
} catch {
1224
return {
1325
binary: {
14-
skipMD5: true,
26+
checkMD5: false,
1527
},
16-
autoStart: false,
1728
instance: {},
1829
};
1930
}

src/setup.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ import {
99
getMongodbMemoryOptions,
1010
shouldUseSharedDBForAllJestWorkers,
1111
} from './helpers';
12+
import {isMongoMemoryReplSetOptions} from './helpers';
1213

1314
const debug = require('debug')('jest-mongodb:setup');
1415

1516
module.exports = async (config: JestEnvironmentConfig['globalConfig']) => {
1617
const globalConfigPath = join(config.rootDir, 'globalConfig.json');
1718

1819
const mongoMemoryServerOptions = getMongodbMemoryOptions(config.rootDir);
19-
const isReplSet = Boolean(mongoMemoryServerOptions.replSet);
20+
const isReplSet = isMongoMemoryReplSetOptions(mongoMemoryServerOptions);
2021

2122
debug(`isReplSet ${isReplSet}`);
2223

@@ -48,7 +49,7 @@ module.exports = async (config: JestEnvironmentConfig['globalConfig']) => {
4849
global.__MONGOD__ = mongo;
4950
}
5051

51-
mongoConfig.mongoDBName = options.instance.dbName;
52+
mongoConfig.mongoDBName = isMongoMemoryReplSetOptions(options) ? '' : options?.instance?.dbName;
5253

5354
// Write global config to disk because all tests run in different contexts.
5455
writeFileSync(globalConfigPath, JSON.stringify(mongoConfig));

0 commit comments

Comments
 (0)