forked from vu3th/vue-dapp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request vu3th#102 from chnejohnson/dev
Add test and eslint, and update docs
- Loading branch information
Showing
18 changed files
with
1,012 additions
and
1,342 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module.exports = { | ||
parser: '@typescript-eslint/parser', | ||
env: { | ||
browser: true, | ||
es2021: true, | ||
node: true, | ||
}, | ||
extends: [ | ||
'eslint:recommended', | ||
'plugin:@typescript-eslint/recommended', | ||
'plugin:prettier/recommended', | ||
], | ||
plugins: ['@typescript-eslint', 'prettier'], | ||
rules: { | ||
// eslint | ||
'no-console': 'error', | ||
|
||
// typescript | ||
'@typescript-eslint/no-explicit-any': 'off', | ||
'@typescript-eslint/no-non-null-assertion': 'off', | ||
}, | ||
overrides: [ | ||
{ | ||
files: ['*.test.ts'], | ||
rules: { | ||
'@typescript-eslint/no-empty-function': 'off', | ||
}, | ||
}, | ||
], | ||
ignorePatterns: ['dist'], | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Global compile-time constants | ||
declare var __DEV__: boolean | ||
declare var __BROWSER__: boolean | ||
declare var __CI__: boolean | ||
declare let __DEV__: boolean | ||
declare let __BROWSER__: boolean | ||
declare let __CI__: boolean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
declare module '*.vue' { | ||
import { DefineComponent } from 'vue' | ||
const component: DefineComponent<{}, {}, any> | ||
const component: DefineComponent< | ||
Record<string, any>, | ||
Record<string, any>, | ||
any | ||
> | ||
export default component | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { mount } from '@vue/test-utils' | ||
import Board from '@/components/Board.vue' | ||
import Modal from '@/components/Modal.vue' | ||
import Loader from '@/components/Loader.vue' | ||
import { MetaMaskConnector, Connector } from '@/connectors' | ||
const connectors: Connector[] = [new MetaMaskConnector()] | ||
|
||
describe('Board component', () => { | ||
beforeEach(() => { | ||
// create teleport target | ||
const el = document.createElement('div') | ||
el.id = 'modal' | ||
document.body.appendChild(el) | ||
}) | ||
|
||
afterEach(() => { | ||
// clean up | ||
document.body.outerHTML = '' | ||
}) | ||
it('should work with import on demand', () => { | ||
// mount(Loader) | ||
// mount(Modal, { | ||
// propsData: { | ||
// modalOpen: true, | ||
// }, | ||
// }) | ||
const wrapper = mount(Board, { | ||
attachTo: document.body, | ||
propsData: { | ||
connectors: connectors, | ||
}, | ||
global: { | ||
stubs: { | ||
teleport: true, | ||
}, | ||
}, | ||
// provide: { | ||
// autoConnect() { | ||
// return false | ||
// }, | ||
// }, | ||
}) | ||
// console.warn(wrapper.getComponent(Board).html()) | ||
expect(wrapper.getComponent(Board).html()).toContain('MetaMask') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { mount } from '@vue/test-utils' | ||
import { defineComponent, nextTick, ref } from 'vue' | ||
import { useWallet } from '@/composables' | ||
|
||
// wip: refer to https://github.com/Mini-ghost/vorms/blob/main/packages/core/tests/composiable/useForm.test.ts | ||
|
||
const noop = () => {} | ||
|
||
const setup = (setup: () => unknown) => { | ||
const Comp = defineComponent({ | ||
setup, | ||
template: `<div />`, | ||
}) | ||
|
||
return mount(Comp) | ||
} | ||
|
||
const sleep = (ms?: number) => { | ||
return new Promise((resolve) => setTimeout(resolve, ms)) | ||
} | ||
|
||
describe('useWallet', () => { | ||
it('when initialize wallet state', () => { | ||
setup(() => { | ||
const { wallet } = useWallet() | ||
expect(wallet.connector).toEqual(null) | ||
expect(wallet.error).toEqual('') | ||
expect(wallet.provider).toEqual(null) | ||
expect(wallet.status).toEqual('none') | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { describe, expect, it } from 'vitest' | ||
import { checkChainId } from '@/utils' | ||
|
||
describe('checkChainId', () => { | ||
it('should return true when chain id is in the available network', () => { | ||
expect(checkChainId(1)).toBeTruthy() | ||
expect(checkChainId(5)).toBeTruthy() | ||
}) | ||
it('should return false when chain id is not in the available network', () => { | ||
expect(checkChainId(2)).toBeFalsy() | ||
expect(checkChainId(4)).toBeFalsy() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { defineConfig } from 'vitest/config' | ||
import path from 'path' | ||
import vue from '@vitejs/plugin-vue' | ||
|
||
export default defineConfig({ | ||
plugins: [vue()], | ||
define: { | ||
__DEV__: true, | ||
}, | ||
test: { | ||
globals: true, // no need to import test api like `import { describe, expect, it } from 'vitest'` | ||
environment: 'jsdom', | ||
include: ['tests/**/*.test.ts'], | ||
}, | ||
resolve: { | ||
alias: { | ||
'@': path.resolve(__dirname, './src'), | ||
}, | ||
}, | ||
}) |
Oops, something went wrong.