Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use TypeScript; update deps; refactor exports #58

Merged
merged 16 commits into from
May 2, 2022
Merged
Show file tree
Hide file tree
Changes from 8 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
7 changes: 6 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ module.exports = {
},

{
files: ['*.test.js'],
files: ['*.ts'],
extends: ['@metamask/eslint-config-typescript'],
},

{
files: ['*.test.ts'],
extends: ['@metamask/eslint-config-jest'],
},
],
Expand Down
11 changes: 8 additions & 3 deletions jest.config.js → jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
* https://jestjs.io/docs/configuration
*/

module.exports = {
import type { Config } from '@jest/types';

const config: Config.InitialOptions = {
// All imported modules in your tests should be mocked automatically
// automock: false,

Expand All @@ -22,7 +24,7 @@ module.exports = {
collectCoverage: true,

// An array of glob patterns indicating a set of files for which coverage information should be collected
collectCoverageFrom: ['./src/**/*.js'],
collectCoverageFrom: ['./src/**/*.ts'],

// The directory where Jest should output its coverage files
coverageDirectory: 'coverage',
Expand All @@ -39,6 +41,7 @@ module.exports = {
coverageReporters: ['text', 'html'],

// An object that configures minimum threshold enforcement for coverage results
// TODO: Fix lack of coverage and restore to 100%
coverageThreshold: {
global: {
branches: 80,
Expand Down Expand Up @@ -97,7 +100,7 @@ module.exports = {
// notifyMode: "failure-change",

// A preset that is used as a base for Jest's configuration
// preset: undefined,
preset: 'ts-jest',

// Run tests from one or more projects
// projects: undefined,
Expand Down Expand Up @@ -202,3 +205,5 @@ module.exports = {
// Whether to use watchman for file crawling
// watchman: true,
};

export default config;
29 changes: 20 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
"url": "https://github.com/MetaMask/eth-json-rpc-infura.git"
},
"license": "ISC",
"main": "src/index.js",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"src/*.js"
"dist/"
],
"scripts": {
"build": "echo 'nothing to build yet'",
"build": "tsc --project tsconfig.build.json",
"build:clean": "rimraf dist && yarn build",
"lint": "yarn lint:eslint && yarn lint:misc --check",
"lint:eslint": "eslint . --cache --ext js,ts",
Expand All @@ -24,9 +25,9 @@
"test:watch": "jest --watch"
},
"dependencies": {
"eth-json-rpc-middleware": "^6.0.0",
"eth-rpc-errors": "^3.0.0",
"json-rpc-engine": "^5.3.0",
"eth-json-rpc-middleware": "^8.0.1",
"eth-rpc-errors": "^4.0.3",
"json-rpc-engine": "^6.1.0",
"node-fetch": "^2.6.7"
},
"devDependencies": {
Expand All @@ -35,8 +36,15 @@
"@metamask/eslint-config": "^9.0.0",
"@metamask/eslint-config-jest": "^9.0.0",
"@metamask/eslint-config-nodejs": "^9.0.0",
"@metamask/eslint-config-typescript": "^9.0.1",
"@types/jest": "^26.0.13",
"@types/node": "^17.0.23",
"@types/node-fetch": "^2.6.1",
"@typescript-eslint/eslint-plugin": "^4.21.0",
"@typescript-eslint/parser": "^4.21.0",
"eslint": "^7.23.0",
"eslint-config-prettier": "^8.5.0",
"eslint-import-resolver-typescript": "^2.7.0",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-jest": "^24.3.4",
"eslint-plugin-jsdoc": "^36.1.0",
Expand All @@ -45,7 +53,10 @@
"jest": "^26.4.2",
"prettier": "^2.6.1",
"prettier-plugin-packagejson": "^2.2.17",
"rimraf": "^3.0.2"
"rimraf": "^3.0.2",
"ts-jest": "^26.3.0",
"ts-node": "^10.7.0",
"typescript": "~4.4.0"
},
"engines": {
"node": ">=12.0.0"
Expand All @@ -57,8 +68,8 @@
"lavamoat": {
"allowScripts": {
"@lavamoat/preinstall-always-fail": false,
"eth-json-rpc-middleware>ethereumjs-util>ethereum-cryptography>keccak": true,
"eth-json-rpc-middleware>ethereumjs-util>ethereum-cryptography>secp256k1": true
"eth-json-rpc-middleware>eth-sig-util>ethereumjs-util>ethereum-cryptography>keccak": true,
"eth-json-rpc-middleware>eth-sig-util>ethereumjs-util>ethereum-cryptography>secp256k1": true
}
}
}
51 changes: 51 additions & 0 deletions src/create-infura-middleware.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { createInfuraMiddleware } from '.';

describe('createInfuraMiddleware', () => {
it('throws when an empty set of options is given', () => {
expect(() => createInfuraMiddleware({} as any)).toThrow(
/Invalid value for 'projectId'/u,
);
});

it('throws when the projectId is null', () => {
expect(() => createInfuraMiddleware({ projectId: null } as any)).toThrow(
/Invalid value for 'projectId'/u,
);
});

it('throws when the projectId is undefined', () => {
expect(() =>
createInfuraMiddleware({ projectId: undefined } as any),
).toThrow(/Invalid value for 'projectId'/u);
});

it('throws when the projectId is an empty string', () => {
expect(() => createInfuraMiddleware({ projectId: '' })).toThrow(
/Invalid value for 'projectId'/u,
);
});

it('throws when the projectId is not a string', () => {
expect(() => createInfuraMiddleware({ projectId: 42 } as any)).toThrow(
/Invalid value for 'projectId'/u,
);
});

it('throws when headers is null', () => {
expect(() =>
createInfuraMiddleware({ projectId: 'foo', headers: null } as any),
).toThrow(/Invalid value for 'headers'/u);
});

it('throws when headers is an empty string', () => {
expect(() =>
createInfuraMiddleware({ projectId: 'foo', headers: '' } as any),
).toThrow(/Invalid value for 'headers'/u);
});

it('throws when headers is not an object', () => {
expect(() =>
createInfuraMiddleware({ projectId: 'foo', headers: 42 } as any),
).toThrow(/Invalid value for 'headers'/u);
});
});
Loading