-
Notifications
You must be signed in to change notification settings - Fork 16
refactor: common vitest configurations #1107
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
Open
poltorak
wants to merge
13
commits into
main
Choose a base branch
from
refactor/vitest-configurations
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
5fb5436
feat(): create common vitest config setup
db63fa1
refactor(): wip use common vitest on few files
45055f5
refactor(): change coverage reports directory
a4275cf
refactor(): simplify vitest factory and split abstract logic
998e8c0
docs(): update new tools readme
d853753
test(): add unit tests for new tools
fec5f10
refactor(): fix circular dependency by creating new internal library
7b831c3
fix: path resolution
dd45d45
fix: path resolution #2
413f9d7
fix: path resolution #3
1f9d9a5
fix: path resolution #4
96cb4b0
fix: path resolution #5
7008a48
refactor(testing): improve vitest config factory and test coverage
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,22 +1,17 @@ | ||
/// <reference types="vitest" /> | ||
import { defineConfig } from 'vite'; | ||
import { tsconfigPathAliases } from '../../tools/vitest-tsconfig-path-aliases.js'; | ||
import { createE2eConfig } from '../../testing/test-setup-config/src/lib/vitest-setup-presets.js'; | ||
|
||
export default defineConfig({ | ||
cacheDir: '../../node_modules/.vite/ci-e2e', | ||
test: { | ||
reporters: ['basic'], | ||
testTimeout: 60_000, | ||
globals: true, | ||
alias: tsconfigPathAliases(), | ||
pool: 'threads', | ||
poolOptions: { threads: { singleThread: true } }, | ||
cache: { | ||
dir: '../../node_modules/.vitest', | ||
export default createE2eConfig( | ||
'ci-e2e', | ||
{ | ||
projectRoot: new URL('../../', import.meta.url), | ||
cacheKey: 'ci-e2e', | ||
}, | ||
{ | ||
test: { | ||
testTimeout: 60_000, | ||
globalSetup: ['./global-setup.ts'], | ||
coverage: { enabled: false }, | ||
}, | ||
environment: 'node', | ||
include: ['tests/**/*.e2e.test.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'], | ||
globalSetup: './global-setup.ts', | ||
setupFiles: ['../../testing/test-setup/src/lib/reset.mocks.ts'], | ||
BioPhoton marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
}); | ||
); |
This file contains hidden or 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,26 +1,16 @@ | ||
/// <reference types="vitest" /> | ||
import { defineConfig } from 'vite'; | ||
import { tsconfigPathAliases } from '../../tools/vitest-tsconfig-path-aliases.js'; | ||
import { createE2eConfig } from '../../testing/test-setup-config/src/lib/vitest-setup-presets.js'; | ||
|
||
export default defineConfig({ | ||
cacheDir: '../../node_modules/.vite/plugin-typescript-e2e', | ||
test: { | ||
reporters: ['basic'], | ||
testTimeout: 20_000, | ||
globals: true, | ||
alias: tsconfigPathAliases(), | ||
pool: 'threads', | ||
poolOptions: { threads: { singleThread: true } }, | ||
coverage: { | ||
reporter: ['text', 'lcov'], | ||
reportsDirectory: '../../coverage/plugin-typescript-e2e/e2e-tests', | ||
exclude: ['mocks/**', '**/types.ts'], | ||
}, | ||
cache: { | ||
dir: '../../node_modules/.vitest', | ||
export default createE2eConfig( | ||
'plugin-typescript-e2e', | ||
{ | ||
projectRoot: new URL('../../', import.meta.url), | ||
cacheKey: 'plugin-typescript-e2e', | ||
}, | ||
{ | ||
test: { | ||
testTimeout: 20_000, | ||
coverage: { enabled: true }, | ||
}, | ||
environment: 'node', | ||
include: ['tests/**/*.e2e.test.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'], | ||
setupFiles: ['../../testing/test-setup/src/lib/reset.mocks.ts'], | ||
}, | ||
}); | ||
); |
This file contains hidden or 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,30 +1,17 @@ | ||
/// <reference types="vitest" /> | ||
import { defineConfig } from 'vite'; | ||
import { tsconfigPathAliases } from '../../tools/vitest-tsconfig-path-aliases.js'; | ||
import { | ||
createIntConfig, | ||
setupPresets, | ||
} from '../../testing/test-setup-config/src/lib/vitest-setup-presets.js'; | ||
|
||
export default defineConfig({ | ||
cacheDir: '../../node_modules/.vite/core', | ||
test: { | ||
reporters: ['basic'], | ||
globals: true, | ||
cache: { | ||
dir: '../../node_modules/.vitest', | ||
}, | ||
alias: tsconfigPathAliases(), | ||
pool: 'threads', | ||
poolOptions: { threads: { singleThread: true } }, | ||
coverage: { | ||
reporter: ['text', 'lcov'], | ||
reportsDirectory: '../../coverage/core/int-tests', | ||
exclude: ['mocks/**', '**/types.ts'], | ||
export default createIntConfig( | ||
'core', | ||
{ | ||
projectRoot: new URL('../../', import.meta.url), | ||
}, | ||
{ | ||
test: { | ||
setupFiles: [...setupPresets.int.base, ...setupPresets.int.portalClient], | ||
}, | ||
environment: 'node', | ||
include: ['src/**/*.int.test.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'], | ||
globalSetup: ['../../global-setup.ts'], | ||
setupFiles: [ | ||
'../../testing/test-setup/src/lib/console.mock.ts', | ||
'../../testing/test-setup/src/lib/reset.mocks.ts', | ||
'../../testing/test-setup/src/lib/portal-client.mock.ts', | ||
], | ||
}, | ||
}); | ||
); |
This file contains hidden or 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,36 +1,22 @@ | ||
/// <reference types="vitest" /> | ||
import { defineConfig } from 'vite'; | ||
import { tsconfigPathAliases } from '../../tools/vitest-tsconfig-path-aliases.js'; | ||
import { | ||
createUnitConfig, | ||
setupPresets, | ||
} from '../../testing/test-setup-config/src/lib/vitest-setup-presets.js'; | ||
|
||
export default defineConfig({ | ||
cacheDir: '../../node_modules/.vite/core', | ||
test: { | ||
reporters: ['basic'], | ||
globals: true, | ||
cache: { | ||
dir: '../../node_modules/.vitest', | ||
}, | ||
alias: tsconfigPathAliases(), | ||
pool: 'threads', | ||
poolOptions: { threads: { singleThread: true } }, | ||
coverage: { | ||
reporter: ['text', 'lcov'], | ||
reportsDirectory: '../../coverage/core/unit-tests', | ||
exclude: ['mocks/**', '**/types.ts'], | ||
export default createUnitConfig( | ||
'core', | ||
{ | ||
projectRoot: new URL('../../', import.meta.url), | ||
}, | ||
{ | ||
test: { | ||
setupFiles: [ | ||
...setupPresets.unit.base, | ||
...setupPresets.unit.git, | ||
...setupPresets.unit.portalClient, | ||
...setupPresets.unit.matchersCore, | ||
], | ||
}, | ||
environment: 'node', | ||
include: ['src/**/*.unit.test.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'], | ||
globalSetup: ['../../global-setup.ts'], | ||
setupFiles: [ | ||
'../../testing/test-setup/src/lib/cliui.mock.ts', | ||
'../../testing/test-setup/src/lib/fs.mock.ts', | ||
'../../testing/test-setup/src/lib/git.mock.ts', | ||
'../../testing/test-setup/src/lib/console.mock.ts', | ||
'../../testing/test-setup/src/lib/reset.mocks.ts', | ||
'../../testing/test-setup/src/lib/portal-client.mock.ts', | ||
'../../testing/test-setup/src/lib/extend/ui-logger.matcher.ts', | ||
'../../testing/test-setup/src/lib/extend/markdown-table.matcher.ts', | ||
'../../testing/test-setup/src/lib/extend/jest-extended.matcher.ts', | ||
], | ||
}, | ||
}); | ||
); |
This file contains hidden or 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,30 +1,18 @@ | ||
/// <reference types="vitest" /> | ||
import { defineConfig } from 'vite'; | ||
import { tsconfigPathAliases } from '../../tools/vitest-tsconfig-path-aliases.js'; | ||
import { | ||
createIntConfig, | ||
setupPresets, | ||
} from '../../testing/test-setup-config/src/lib/vitest-setup-presets.js'; | ||
|
||
export default defineConfig({ | ||
cacheDir: '../../node_modules/.vite/utils', | ||
test: { | ||
reporters: ['basic'], | ||
globals: true, | ||
cache: { | ||
dir: '../../node_modules/.vitest', | ||
}, | ||
alias: tsconfigPathAliases(), | ||
pool: 'threads', | ||
poolOptions: { threads: { singleThread: true } }, | ||
coverage: { | ||
reporter: ['text', 'lcov'], | ||
reportsDirectory: '../../coverage/utils/int-tests', | ||
exclude: ['mocks/**', 'perf/**', '**/types.ts'], | ||
export default createIntConfig( | ||
'utils', | ||
{ | ||
projectRoot: new URL('../../', import.meta.url), | ||
}, | ||
{ | ||
test: { | ||
coverage: { exclude: ['perf/**'] }, | ||
setupFiles: [...setupPresets.int.base, ...setupPresets.int.cliui], | ||
}, | ||
environment: 'node', | ||
include: ['src/**/*.int.test.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'], | ||
globalSetup: ['../../global-setup.ts'], | ||
setupFiles: [ | ||
'../../testing/test-setup/src/lib/cliui.mock.ts', | ||
'../../testing/test-setup/src/lib/console.mock.ts', | ||
'../../testing/test-setup/src/lib/reset.mocks.ts', | ||
], | ||
}, | ||
}); | ||
); |
This file contains hidden or 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,38 +1,24 @@ | ||
/// <reference types="vitest" /> | ||
import { defineConfig } from 'vite'; | ||
import { tsconfigPathAliases } from '../../tools/vitest-tsconfig-path-aliases.js'; | ||
import { | ||
createUnitConfig, | ||
setupPresets, | ||
} from '../../testing/test-setup-config/src/lib/vitest-setup-presets.js'; | ||
|
||
export default defineConfig({ | ||
cacheDir: '../../node_modules/.vite/utils', | ||
test: { | ||
reporters: ['basic'], | ||
globals: true, | ||
cache: { | ||
dir: '../../node_modules/.vitest', | ||
}, | ||
alias: tsconfigPathAliases(), | ||
pool: 'threads', | ||
poolOptions: { threads: { singleThread: true } }, | ||
coverage: { | ||
reporter: ['text', 'lcov'], | ||
reportsDirectory: '../../coverage/utils/unit-tests', | ||
exclude: ['mocks/**', 'perf/**', '**/types.ts'], | ||
}, | ||
environment: 'node', | ||
include: ['src/**/*.{unit,type}.test.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'], | ||
typecheck: { | ||
include: ['**/*.type.test.ts'], | ||
export default createUnitConfig( | ||
'utils', | ||
{ | ||
projectRoot: new URL('../../', import.meta.url), | ||
}, | ||
{ | ||
test: { | ||
include: ['src/**/*.{unit,type}.test.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'], | ||
typecheck: { include: ['**/*.type.test.ts'] }, | ||
coverage: { exclude: ['perf/**'] }, | ||
setupFiles: [ | ||
...setupPresets.unit.base, | ||
...setupPresets.unit.matchersCore, | ||
...setupPresets.unit.matcherPath, | ||
], | ||
}, | ||
globalSetup: ['../../global-setup.ts'], | ||
setupFiles: [ | ||
'../../testing/test-setup/src/lib/cliui.mock.ts', | ||
'../../testing/test-setup/src/lib/fs.mock.ts', | ||
'../../testing/test-setup/src/lib/console.mock.ts', | ||
'../../testing/test-setup/src/lib/reset.mocks.ts', | ||
'../../testing/test-setup/src/lib/extend/ui-logger.matcher.ts', | ||
'../../testing/test-setup/src/lib/extend/markdown-table.matcher.ts', | ||
'../../testing/test-setup/src/lib/extend/path.matcher.ts', | ||
'../../testing/test-setup/src/lib/extend/jest-extended.matcher.ts', | ||
], | ||
}, | ||
}); | ||
); |
This file contains hidden or 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,24 @@ | ||
## Vitest config factory and setup presets | ||
|
||
Utilities to centralize and standardize Vitest configuration across the monorepo. | ||
|
||
- `vitest-config-factory.ts`: builds typed Vitest configs with sensible defaults | ||
- `vitest-setup-presets.ts`: provides create functions and exportable setup file groups | ||
|
||
The create functions (`createUnitConfig`, `createIntConfig`, `createE2eConfig`) automatically include appropriate setup files for each test type. See the unit tests for detailed documentation of defaults, coverage settings, and setup file presets. | ||
|
||
### Examples | ||
|
||
**Using defaults:** | ||
|
||
```ts | ||
export default createUnitConfig('my-package', import.meta.url); | ||
``` | ||
|
||
**Extending default setup files:** | ||
|
||
```ts | ||
export default createIntConfig('my-package', import.meta.url, { | ||
setupFiles: [...setupPresets.int.base, ...setupPresets.int.git, './custom-setup.ts'], | ||
}); | ||
``` |
This file contains hidden or 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,12 @@ | ||
import tseslint from 'typescript-eslint'; | ||
import baseConfig from '../../eslint.config.js'; | ||
|
||
export default tseslint.config(...baseConfig, { | ||
files: ['**/*.ts'], | ||
languageOptions: { | ||
parserOptions: { | ||
projectService: true, | ||
tsconfigRootDir: import.meta.dirname, | ||
}, | ||
}, | ||
}); |
This file contains hidden or 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,12 @@ | ||
{ | ||
"name": "test-setup-config", | ||
"$schema": "../../node_modules/nx/schemas/project-schema.json", | ||
"sourceRoot": "testing/test-setup/src", | ||
"projectType": "library", | ||
"targets": { | ||
"build": {}, | ||
"lint": {}, | ||
"unit-test": {} | ||
}, | ||
"tags": ["scope:shared", "type:testing"] | ||
} |
This file contains hidden or 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 @@ | ||
export { | ||
createVitestConfig, | ||
type TestKind, | ||
type VitestConfigFactoryOptions, | ||
type VitestOverrides, | ||
type ConfigRestParams, | ||
} from './lib/vitest-config-factory.js'; | ||
|
||
export { | ||
setupPresets, | ||
createUnitConfig, | ||
createIntConfig, | ||
createE2eConfig, | ||
} from './lib/vitest-setup-presets.js'; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this could be a default for the e2e target
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked other files and there are many different values, like 20k, 40k, 80k, 60k, 120k.
Just making sure that we want to have 60k as default?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm.... I would put 20 as default. Or if there are more projects with 40 lets go with 40. And for the projects with higher or lower times go with a override.
Did not realise this is already an overwrite..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked that and:
I suggest then use 20s as default (20_000ms)