Skip to content

Commit

Permalink
feat: new jest mocking optimized export
Browse files Browse the repository at this point in the history
  • Loading branch information
stipsan committed Mar 23, 2021
1 parent 1ac8225 commit 0feef19
Show file tree
Hide file tree
Showing 155 changed files with 202 additions and 159 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,6 @@ jobs:
run: |
yarn --frozen-lockfile --ignore-engines
yarn test
- name: E2E test generated jest.js mock
run: yarn test:jest.js
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ junit
lib
node_modules
npm-debug.log

jest.js
package-lock.json
npm-debug.log*
yarn-debug.log*
Expand Down
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ package-lock.json
lib
.nyc_output
coverage
junit
junit
jest.js
6 changes: 6 additions & 0 deletions jest.config.jest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict';

module.exports = {
...require('./jest.config'),
setupFiles: ['<rootDir>/testSetupJest.js'],
};
8 changes: 8 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

module.exports = {
testRunner: 'jest-circus/runner',
testMatch: ['**/test/**/*.js'],
coverageDirectory: 'coverage',
setupFiles: ['<rootDir>/testSetupBabel.js'],
};
15 changes: 7 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"main": "./lib",
"files": [
"example.js",
"jest.js",
"lib/"
],
"scripts": {
Expand All @@ -22,9 +23,13 @@
"coverage": "yarn test --coverage",
"coveralls": "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
"lint": "eslint .",
"prepublishOnly": "npx rimraf lib && npx mkdirp lib && babel src --out-dir lib",
"build:babel": "npx rimraf lib && npx mkdirp lib && babel src --out-dir lib",
"build:jest": "esbuild src/index.js --bundle --external:cluster-key-slot --external:debug --external:denque --external:lodash.defaults --external:lodash.flatten --external:p-map --external:redis-commands --external:redis-errors --external:redis-parser --external:array-from --external:es6-map --external:es6-set --external:fengari --external:fengari-interop --external:lodash --external:minimatch --external:standard-as-callback --outfile=jest.js --platform=node --target=node10",
"prepublishOnly": "yarn build:babel && yarn build:jest",
"semantic-release": "semantic-release pre && npm publish && semantic-release post",
"test": "jest",
"pretest:jest.js": "yarn build:jest",
"test:jest.js": "jest --config jest.config.jest.js",
"update-compat": "node scripts/update-compat && git add compat.md README.md && git commit --quiet -m \"docs: Update feature compat table\" &> /dev/null || true"
},
"dependencies": {
Expand All @@ -50,6 +55,7 @@
"chance": "^1.1.7",
"codeclimate-test-reporter": "^0.5.1",
"coveralls": "^3.1.0",
"esbuild": "^0.9.6",
"eslint": "^7.13.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-config-prettier": "^8.0.0",
Expand Down Expand Up @@ -93,13 +99,6 @@
"pre-commit": "lint-staged"
}
},
"jest": {
"testRunner": "jest-circus/runner",
"testMatch": [
"**/test/**/*.js"
],
"coverageDirectory": "coverage"
},
"lint-staged": {
"*.js": [
"eslint --fix",
Expand Down
4 changes: 1 addition & 3 deletions renovate.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{
"extends": [
"github>stipsan/renovate-presets:auto"
]
"extends": ["github>stipsan/renovate-presets:auto"]
}
4 changes: 2 additions & 2 deletions src/commands/hset.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export function hset(key, ...keyValuePairs) {
let reply = 0;

for (let i = 0; i < keyValuePairs.length; i += 2) {
const field = keyValuePairs[i]
const value = keyValuePairs[i + 1]
const field = keyValuePairs[i];
const value = keyValuePairs[i + 1];

if (!{}.hasOwnProperty.call(hash, field)) {
reply++;
Expand Down
2 changes: 1 addition & 1 deletion src/commands/linsert.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function linsert(key, position, pivot, element) {
);
}
list.splice(elementIndex, 0, element);
const {length} = list;
const { length } = list;
this.data.set(key, list);
return length;
}
2 changes: 1 addition & 1 deletion test/commands/append.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MockRedis from '../../src';
import MockRedis from 'ioredis';

describe('append', () => {
it('should append to exiting string and return new length', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/commands/auth.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MockRedis from '../../src';
import MockRedis from 'ioredis';

describe('auth', () => {
it('should return OK', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/commands/bgrewriteaof.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MockRedis from '../../src';
import MockRedis from 'ioredis';

describe('bgrewriteaof', () => {
it('should return OK', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/commands/bgsave.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MockRedis from '../../src';
import MockRedis from 'ioredis';

describe('bgsave', () => {
it('should return OK', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/commands/brpoplpush.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MockRedis from '../../src';
import MockRedis from 'ioredis';

describe('brpoplpush', () => {
it('should remove one item from the tail of the source list', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/commands/brpoplpushBuffer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import createBuffer from '../../src/buffer';
import MockRedis from '../../src';
import MockRedis from 'ioredis';

describe('brpoplpushBuffer', () => {
it('should remove one item from the tail of the source list', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/commands/connect.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MockRedis from '../../src';
import MockRedis from 'ioredis';

describe('connect', () => {
it('should throw if redis has already connected in ctor', (done) => {
Expand Down
2 changes: 1 addition & 1 deletion test/commands/dbsize.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MockRedis from '../../src';
import MockRedis from 'ioredis';

describe('dbsize', () => {
it('should return how many keys exists in db', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/commands/decr.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MockRedis from '../../src';
import MockRedis from 'ioredis';

describe('decr', () => {
it('should decrement an integer', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/commands/decrby.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MockRedis from '../../src';
import MockRedis from 'ioredis';

describe('decrby', () => {
it('should decrement an integer with passed decrement', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/commands/defineCommand.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MockRedis from '../../src';
import MockRedis from 'ioredis';
import { init, dispose } from '../../src/lua';

describe('defineCommand', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/commands/del.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MockRedis from '../../src';
import MockRedis from 'ioredis';

describe('del', () => {
const redis = new MockRedis({
Expand Down
2 changes: 1 addition & 1 deletion test/commands/discard.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MockRedis from '../../src';
import MockRedis from 'ioredis';

describe('discard', () => {
it('should discard any batch queue ', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/commands/echo.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MockRedis from '../../src';
import MockRedis from 'ioredis';

describe('echo', () => {
it('should return message', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/commands/eval.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MockRedis from '../../src';
import MockRedis from 'ioredis';

describe('eval', () => {
it('should execute a lua script through eval and get the return value', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/commands/exists.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MockRedis from '../../src';
import MockRedis from 'ioredis';

describe('exists', () => {
const redis = new MockRedis({
Expand Down
2 changes: 1 addition & 1 deletion test/commands/expire.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Promise from 'bluebird';

import MockRedis from '../../src';
import MockRedis from 'ioredis';

describe('expire', () => {
it('should delete key on get', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/commands/expireat.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MockRedis from '../../src';
import MockRedis from 'ioredis';

describe('expireat', () => {
it('should set expire status on key', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/commands/flushall.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MockRedis from '../../src';
import MockRedis from 'ioredis';

describe('flushall', () => {
const redis = new MockRedis({
Expand Down
2 changes: 1 addition & 1 deletion test/commands/flushdb.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MockRedis from '../../src';
import MockRedis from 'ioredis';

describe('flushdb', () => {
const redis = new MockRedis({
Expand Down
2 changes: 1 addition & 1 deletion test/commands/get.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MockRedis from '../../src';
import MockRedis from 'ioredis';

describe('get', () => {
it('should return null on keys that do not exist', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/commands/getBuffer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import createBuffer from '../../src/buffer';
import MockRedis from '../../src';
import MockRedis from 'ioredis';

describe('getBuffer', () => {
it('should return null on keys that do not exist', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/commands/getbit.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MockRedis from '../../src';
import MockRedis from 'ioredis';

describe('getbit', () => {
it('should return 0 on keys that do not exist', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/commands/getrange.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MockRedis from '../../src';
import MockRedis from 'ioredis';

describe('getrange', () => {
const redis = new MockRedis({
Expand Down
2 changes: 1 addition & 1 deletion test/commands/getset.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MockRedis from '../../src';
import MockRedis from 'ioredis';

describe('getset', () => {
it('should set the new value and return the old value', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/commands/hdel.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MockRedis from '../../src';
import MockRedis from 'ioredis';

describe('hdel', () => {
const redis = new MockRedis({
Expand Down
2 changes: 1 addition & 1 deletion test/commands/hexists.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MockRedis from '../../src';
import MockRedis from 'ioredis';

describe('hexists', () => {
describe('hash exists', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/commands/hget.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MockRedis from '../../src';
import MockRedis from 'ioredis';

describe('hget', () => {
it('should fetch a property in a hash', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/commands/hgetBuffer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MockRedis from '../../src';
import MockRedis from 'ioredis';
import createBuffer from '../../src/buffer';

describe('hgetBuffer', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/commands/hgetall.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MockRedis from '../../src';
import MockRedis from 'ioredis';

describe('hgetall', () => {
it('should return all the keys and values in a hash map', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/commands/hgetallBuffer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import createBuffer from '../../src/buffer';

import MockRedis from '../../src';
import MockRedis from 'ioredis';

describe('hgetallBuffer', () => {
it('should return all the keys and values in a hash map as buffer', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/commands/hincrby.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MockRedis from '../../src';
import MockRedis from 'ioredis';

describe('hincrby', () => {
it('should increment an integer with passed increment in hash', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/commands/hincrbyfloat.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MockRedis from '../../src';
import MockRedis from 'ioredis';

describe('hincrbyfloat', () => {
it('should increment an float with passed increment', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/commands/hkeys.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MockRedis from '../../src';
import MockRedis from 'ioredis';

describe('hkeys', () => {
it('should return an empty array if there are no keys', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/commands/hlen.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MockRedis from '../../src';
import MockRedis from 'ioredis';

describe('hlen', () => {
it('should return an empty array if there are no keys', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/commands/hmget.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MockRedis from '../../src';
import MockRedis from 'ioredis';

describe('hmget', () => {
it('should return the values of specified keys in a hash map', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/commands/hmgetBuffer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import createBuffer from '../../src/buffer';
import MockRedis from '../../src';
import MockRedis from 'ioredis';

describe('hmgetBuffer', () => {
it('should return the values as buffers of specified keys in a hash map', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/commands/hmset.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MockRedis from '../../src';
import MockRedis from 'ioredis';

describe('hmset', () => {
it('should let you set multiple hash map keys and values in a single command', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/commands/hscan.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Chance from 'chance';
import MockRedis from '../../src';
import MockRedis from 'ioredis';

const chance = new Chance();

Expand Down
2 changes: 1 addition & 1 deletion test/commands/hscanStream.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ObjectWritableMock } from 'stream-mock';
import Chance from 'chance';
import _ from 'lodash';
import MockRedis from '../../src';
import MockRedis from 'ioredis';

const chance = new Chance();

Expand Down
2 changes: 1 addition & 1 deletion test/commands/hset.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MockRedis from '../../src';
import MockRedis from 'ioredis';

describe('hset', () => {
const redis = new MockRedis();
Expand Down
2 changes: 1 addition & 1 deletion test/commands/hsetnx.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MockRedis from '../../src';
import MockRedis from 'ioredis';

describe('hsetnx', () => {
it('should set a key in a hash map if it does not exist already', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/commands/hstrlen.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MockRedis from '../../src';
import MockRedis from 'ioredis';

describe('hstrlen', () => {
it('should return 0 on keys that do not exist', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/commands/hvals.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MockRedis from '../../src';
import MockRedis from 'ioredis';

describe('hvals', () => {
it('should return an array over all the values in a hash map', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/commands/incr.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MockRedis from '../../src';
import MockRedis from 'ioredis';

describe('incr', () => {
it('should increment an integer', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/commands/incrby.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MockRedis from '../../src';
import MockRedis from 'ioredis';

describe('incrby', () => {
it('should initialize the key with 0 if there is no key', () => {
Expand Down
Loading

0 comments on commit 0feef19

Please sign in to comment.