-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: extract common internal config
- Loading branch information
1 parent
4756be0
commit 8788f2e
Showing
11 changed files
with
158 additions
and
106 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
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,45 +1,4 @@ | ||
import { defineConfig, configDefaults } from 'vitest/config'; | ||
import tsconfigPaths from 'vite-tsconfig-paths'; | ||
import baseViteConfig from '../tools/vite.config'; | ||
import { mergeConfig } from 'vitest/config'; | ||
|
||
const exclude = [...configDefaults.exclude, '**/dist/*.*', '**/.*', '**/*.setup.*']; | ||
|
||
export default defineConfig({ | ||
plugins: [tsconfigPaths()], | ||
test: { | ||
maxConcurrency: 20, | ||
pool: 'vmThreads', | ||
poolOptions: { | ||
threads: { | ||
singleThread: true, | ||
}, | ||
}, | ||
isolate: false, // only safe with the poolOptions above | ||
css: false, | ||
deps: { | ||
optimizer: { | ||
web: { | ||
enabled: true, | ||
}, | ||
}, | ||
}, | ||
globals: true, | ||
watch: false, | ||
environment: 'happy-dom', | ||
setupFiles: ['./vitest.setup'], | ||
include: ['./src/**/*(*.)?{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'], | ||
name: 'bridge', | ||
exclude, | ||
reporters: ['junit', 'default'], | ||
outputFile: { | ||
junit: './jest-report.xml', | ||
}, | ||
coverage: { | ||
all: false, | ||
enabled: true, | ||
provider: 'v8', | ||
exclude: [...exclude, '**/__tests__/*.*'], | ||
reportsDirectory: './coverage', | ||
reporter: [['json', { file: 'coverage-summary.json' }], ['text']], | ||
}, | ||
}, | ||
}); | ||
export default mergeConfig(baseViteConfig, {}); |
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,60 +1,2 @@ | ||
import '@testing-library/jest-dom'; | ||
import { cleanup } from '@testing-library/react'; | ||
import { afterEach, beforeAll, vi } from 'vitest'; | ||
|
||
beforeAll(() => { | ||
global.ResizeObserver = class ResizeObserver { | ||
observe() { | ||
// do nothing | ||
} | ||
unobserve() { | ||
// do nothing | ||
} | ||
disconnect() { | ||
// do nothing | ||
} | ||
}; | ||
}); | ||
|
||
afterEach(() => { | ||
cleanup(); | ||
}); | ||
|
||
// https://jestjs.io/docs/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom | ||
if (typeof window !== 'undefined') { | ||
Object.defineProperty(window, 'matchMedia', { | ||
writable: true, | ||
value: vi.fn().mockImplementation((query) => ({ | ||
matches: false, | ||
media: query, | ||
onchange: null, | ||
addListener: vi.fn(), // deprecated | ||
removeListener: vi.fn(), // deprecated | ||
addEventListener: vi.fn(), | ||
removeEventListener: vi.fn(), | ||
dispatchEvent: vi.fn(), | ||
})), | ||
}); | ||
} | ||
|
||
import { type TChainId } from '@aelf-web-login/wallet-adapter-base'; | ||
vi.mock('@aelf-web-login/wallet-adapter-portkey-aa', () => ({ | ||
PortkeyAAWallet: vi.fn(), | ||
})); | ||
vi.mock('@portkey/did-ui-react', () => ({ | ||
getChainInfo: (c: TChainId) => (!c ? null : {}), | ||
did: { | ||
didWallet: { | ||
managementAccount: { | ||
privateKey: '', | ||
}, | ||
}, | ||
}, | ||
})); | ||
vi.mock('lottie-web'); | ||
vi.mock('@portkey/utils'); | ||
vi.mock('node-fetch'); | ||
import { TextEncoder, TextDecoder } from 'util'; | ||
global.TextEncoder = TextEncoder; | ||
// @ts-expect-error TextDecoder | ||
global.TextDecoder = TextDecoder; | ||
import '../tools/__mocks__/setupGlobal'; | ||
import '../tools/__mocks__/setupLocal'; |
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,5 @@ | ||
# Why another package? | ||
|
||
During migration to vitest, there's a need to both provide common config and mocks without polluting workspace root, and establish clear boundary to import/export such configs. | ||
|
||
This package is _meant_ to be internally consumed, thus `private: true` in package.json and not to be published. |
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 '@testing-library/jest-dom'; | ||
import { cleanup } from '@testing-library/react'; | ||
import { afterEach, beforeAll, vi } from 'vitest'; | ||
|
||
beforeAll(() => { | ||
global.ResizeObserver = class ResizeObserver { | ||
observe() { | ||
// do nothing | ||
} | ||
unobserve() { | ||
// do nothing | ||
} | ||
disconnect() { | ||
// do nothing | ||
} | ||
}; | ||
}); | ||
|
||
afterEach(() => { | ||
cleanup(); | ||
}); | ||
|
||
// https://jestjs.io/docs/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom | ||
if (typeof window !== 'undefined') { | ||
Object.defineProperty(window, 'matchMedia', { | ||
writable: true, | ||
value: vi.fn().mockImplementation((query) => ({ | ||
matches: false, | ||
media: query, | ||
onchange: null, | ||
addListener: vi.fn(), // deprecated | ||
removeListener: vi.fn(), // deprecated | ||
addEventListener: vi.fn(), | ||
removeEventListener: vi.fn(), | ||
dispatchEvent: vi.fn(), | ||
})), | ||
}); | ||
} | ||
|
||
import { TextEncoder, TextDecoder } from 'util'; | ||
global.TextEncoder = TextEncoder; | ||
// @ts-expect-error TextDecoder | ||
global.TextDecoder = TextDecoder; | ||
|
||
vi.mock('lottie-web'); | ||
vi.mock('node-fetch'); |
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,17 @@ | ||
import { vi } from 'vitest'; | ||
import { type TChainId } from '@aelf-web-login/wallet-adapter-base'; | ||
|
||
vi.mock('@portkey/utils'); | ||
vi.mock('@aelf-web-login/wallet-adapter-portkey-aa', () => ({ | ||
PortkeyAAWallet: vi.fn(), | ||
})); | ||
vi.mock('@portkey/did-ui-react', () => ({ | ||
getChainInfo: (c: TChainId) => (!c ? null : {}), | ||
did: { | ||
didWallet: { | ||
managementAccount: { | ||
privateKey: '', | ||
}, | ||
}, | ||
}, | ||
})); |
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 { resolve } from 'path'; | ||
// relative path is still required here before aliases are enabled | ||
import baseTSConfig from '../../tsconfig.base.json'; | ||
|
||
export const getTSConfigPaths = () => { | ||
const aliases: Record<string, string> = {}; | ||
for (const [key, value] of Object.entries<string[]>(baseTSConfig.compilerOptions.paths)) { | ||
aliases[key] = resolve(__dirname, value[0]); | ||
} | ||
return aliases; | ||
}; | ||
|
||
export default {}; |
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,14 @@ | ||
{ | ||
"name": "@aelf-web-login/tools", | ||
"private": true, | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.ts", | ||
"files": [ | ||
"*" | ||
], | ||
"scripts": {}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "UNLICENSED" | ||
} |
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,4 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"include": ["*.ts", "**/*.ts"] | ||
} |
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,48 @@ | ||
import { defineConfig, configDefaults } from 'vitest/config'; | ||
import tsconfigPaths from 'vite-tsconfig-paths'; | ||
|
||
const exclude = [...configDefaults.exclude, '**/dist/*.*', '**/.*', '**/*.setup.*']; | ||
|
||
export default defineConfig({ | ||
plugins: [tsconfigPaths()], | ||
test: { | ||
maxConcurrency: 20, | ||
pool: 'vmThreads', | ||
poolOptions: { | ||
threads: { | ||
singleThread: true, | ||
}, | ||
}, | ||
isolate: false, // only safe with the poolOptions above | ||
css: false, | ||
deps: { | ||
optimizer: { | ||
web: { | ||
enabled: true, | ||
}, | ||
}, | ||
}, | ||
globals: true, | ||
watch: false, | ||
environment: 'happy-dom', | ||
// expect a relative vitest.setup.[js|ts] file where this is initiated | ||
// due to nature of mocks being hoisted during evaluation, consumers need | ||
// to provide individual vitest setup files | ||
setupFiles: ['./vitest.setup'], | ||
include: ['./src/**/*(*.)?{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'], | ||
name: 'bridge', | ||
exclude, | ||
reporters: ['junit', 'default'], | ||
outputFile: { | ||
junit: './jest-report.xml', | ||
}, | ||
coverage: { | ||
all: false, | ||
enabled: true, | ||
provider: 'v8', | ||
exclude: [...exclude, '**/__tests__/*.*'], | ||
reportsDirectory: './coverage', | ||
reporter: [['json', { file: 'coverage-summary.json' }], ['text']], | ||
}, | ||
}, | ||
}); |
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