Skip to content

Commit

Permalink
feat: prepare for release (#36)
Browse files Browse the repository at this point in the history
* feat: rename setup function, update README

* feat: create main workflow
  • Loading branch information
VGLoic authored Mar 3, 2022
1 parent 42fe832 commit 0826cfd
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 21 deletions.
74 changes: 74 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Main Build
on:
push:
branches:
- main
jobs:
setup:
runs-on: ubuntu-latest
strategy:
matrix:
node: [ '14', '16' ]
name: Node ${{ matrix.node }} - Setup
steps:
- uses: actions/checkout@v2
- name: Setup node
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node }}
cache: npm
- run: npm ci
example-tests:
runs-on: ubuntu-latest
needs: [setup]
strategy:
matrix:
node: [ '14', '16' ]
name: Node ${{ matrix.node }} - Example Test
steps:
- uses: actions/checkout@v2
- name: Setup node
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node }}
cache: npm
- run: npm ci
- run: npm run build
- run: npm run install:examples
- run: npm run test:examples
test:
runs-on: ubuntu-latest
needs: [setup]
strategy:
matrix:
node: [ '14', '16' ]
name: Node ${{ matrix.node }} - Test
steps:
- uses: actions/checkout@v2
- name: Setup node
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node }}
cache: npm
- run: npm ci
- run: npm run build
- run: npm test
- run: npm run test:cover
publish:
runs-on: ubuntu-latest
name: Versionning and Publish
needs: [example-tests, test]
steps:
- uses: actions/checkout@v2
- name: Setup node
uses: actions/setup-node@v2
with:
node-version: '16.x'
cache: npm
- run: npm ci
- run: npm run build
- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npx semantic-release
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ The recommended way to use Eth-Testing with an application is to install it a de

Using `npm`
```console
npm install eth-testing@alpha --save-dev
npm install eth-testing --save-dev
```
Or using `yarn`
```console
yarn add eth-testing@alpha --dev
yarn add eth-testing --dev
```

As a very simple example, let us consider a React app using [metamask-react](https://github.com/VGLoic/metamask-react) for handling MetaMask and tested using [React Testing Library](https://testing-library.com/docs/react-testing-library/intro).
Expand All @@ -33,13 +33,13 @@ function App() {
}

// app.test.tsx
import { setupEthTesting } from "eth-testing";
import { generateTestingUtils } from "eth-testing";
import { render, screen, waitForElementToBeRemoved } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import App from "App";
...
describe("app connection", () => {
const testingUtils = setupEthTesting({ providerType: "MetaMask" });
const testingUtils = generateTestingUtils({ providerType: "MetaMask" });
beforeAll(() => {
// Manually inject the mocked provider in the window as MetaMask does
global.window.ethereum = testingUtils.getProvider();
Expand Down Expand Up @@ -86,7 +86,7 @@ For a more serious application with more complete features and tests, one can ta

The first step is to generate the utils
```ts
const testingUtils = setupEthTesting({ providerType: "MetaMask" });
const testingUtils = generateTestingUtils({ providerType: "MetaMask" });
```
The argument is only the provider type, the three choices for now are `"MetaMask"`, `"WalletConnect"` or `"default"`.

Expand Down Expand Up @@ -255,7 +255,7 @@ type MockOptions = {

It is sometimes handy to display which JSON-RPC requests are triggered and for each, show the associated mock if it exists. For that, the setup function allows to set the utils in *verbose* mode
```ts
const testingUtils = setupEthTesting({ verbose: true });
const testingUtils = generateTestingUtils({ verbose: true });
```

## Contributing :rocket:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { render, screen, waitFor, act } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { setupEthTesting } from "eth-testing";
import { generateTestingUtils } from "eth-testing";
import { ABI } from "constants/storage-contract";
import EthersContractBox from "../contract-box/ethers-contract-box";
import Web3JsContractBox from "../contract-box/web3js-contract-box";

describe("ContractBox", () => {
let originalEthereum: any;
const testingUtils = setupEthTesting({
const testingUtils = generateTestingUtils({
providerType: "MetaMask",
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { render, screen, } from "@testing-library/react";
import { setupEthTesting } from "eth-testing";
import { generateTestingUtils } from "eth-testing";
import { DumbResolver } from "..";

describe("ContractBox", () => {
let originalEthereum: any;
const testingUtils = setupEthTesting({
const testingUtils = generateTestingUtils({
providerType: "MetaMask",
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import {
waitForElementToBeRemoved,
} from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { setupEthTesting } from "eth-testing";
import { generateTestingUtils } from "eth-testing";
import WalletConnection from "..";

describe("Connect wallet", () => {
let originalEthereum: any;
const testingUtils = setupEthTesting({
const testingUtils = generateTestingUtils({
providerType: "MetaMask",
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import {
waitForElementToBeRemoved,
} from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { setupEthTesting } from "eth-testing";
import { generateTestingUtils } from "eth-testing";
import WalletConnection from "..";
import * as walletConnectProvider from '../provider';

describe("Connect wallet", () => {
const testingUtils = setupEthTesting({
const testingUtils = generateTestingUtils({
providerType: "WalletConnect",
});

Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/internal-event.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { setupEthTesting } from "../setup";
import { generateTestingUtils } from "../setup";

describe("internal events handling", () => {
test("subscriber callbacks should be triggered when associated event is received", () => {
const testingUtils = setupEthTesting();
const testingUtils = generateTestingUtils();
const provider = testingUtils.getProvider();

const firstCallback = jest.fn();
Expand Down
10 changes: 5 additions & 5 deletions src/setup.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import { MetaMaskProvider, WalletConnectProvider, Provider } from "./providers";
import { TestingUtils } from "./testing-utils";

type SetupOptions = {
type GenerateOptions = {
providerType?: "MetaMask" | "WalletConnect" | "default";
verbose?: boolean;
};

const defaultSetupOptions: SetupOptions = {
const defaultGenerationOptions: GenerateOptions = {
providerType: "default",
verbose: false,
};

/**
* Set up the testing utils associated with a mock provider
* Generate the testing utils associated with a mock provider
* @param options.providerType Type of the provider to mock, default to `default`
* @param options.verbose If true, the JSON-RPC request will be logged
* @returns The testing utils for one provider
*/
export function setupEthTesting({
export function generateTestingUtils({
providerType,
verbose,
}: SetupOptions = defaultSetupOptions) {
}: GenerateOptions = defaultGenerationOptions) {
const provider =
providerType === "MetaMask"
? new MetaMaskProvider({ verbose })
Expand Down

0 comments on commit 0826cfd

Please sign in to comment.