Skip to content

Commit

Permalink
fix(vitest): updated config - project separated test calls
Browse files Browse the repository at this point in the history
  • Loading branch information
StephanGerbeth committed Nov 28, 2024
1 parent 749d027 commit 9b69b72
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 6 deletions.
1 change: 1 addition & 0 deletions .cache/vitest/results.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"version":"2.1.5","results":[["packages/playground:packages/playground/src/demo/index.test.js",{"duration":0,"failed":false}]]}
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@
"release": "npm run release --workspaces",
"release:proof": "npx dotenv-cli -- npm run release -- -- --dry-run",
"test": "vitest",
"test:observables": "vitest --project packages/observables",
"test:operators": "vitest --project packages/operators",
"test:playground": "vitest --project packages/playground",
"coverage": "vitest run --coverage"
},
"workspaces": [
"packages/operators",
"packages/observables"
"packages/observables",
"packages/playground"
],
"devDependencies": {
"@commitlint/config-conventional": "19.6.0",
Expand Down
3 changes: 3 additions & 0 deletions packages/observables/vitest.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { defineProject } from 'vitest/config';

export default defineProject({
cacheDir: '../.cache/vitest-observables',
test: {
cacheDir: '../.cache/vitest',
setupFiles: ['../../setup.js'],
environment: 'happy-dom'
}
});
4 changes: 3 additions & 1 deletion packages/operators/vitest.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { defineProject } from 'vitest/config';
import { defineProject, configDefaults } from 'vitest/config';

Check warning on line 1 in packages/operators/vitest.config.js

View workflow job for this annotation

GitHub Actions / Install (ubuntu-latest, 20)

'configDefaults' is defined but never used

export default defineProject({
cacheDir: '../.cache/vitest-operators',
test: {
cacheDir: '../.cache/vitest',
setupFiles: ['../../setup.js'],
testTimeout: 10000,
environment: 'happy-dom'
Expand Down
34 changes: 34 additions & 0 deletions packages/playground/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "@rxjs-collection/playground",
"version": "1.0.12",
"description": "rxjs playground",
"license": "MIT",
"contributors": [
{
"name": "Stephan Gerbeth",
"email": "[email protected]"
}
],
"type": "module",
"main": "src/index.js",
"files": [
"./src/*"
],
"scripts": {
"release": "npx semantic-release",
"dev": "npx vitest"
},
"imports": {
"#observables/*": "../observables/src/*",
"#operators/*": "../operators/src/*",
"#mocks/*": "../mocks/*"
},
"dependencies": {
"@rxjs-collection/observables": "*",
"@rxjs-collection/operators": "*",
"rxjs": "7.8.1"
},
"devDependencies": {
"node-fetch": "3.3.2"
}
}
14 changes: 14 additions & 0 deletions packages/playground/src/demo/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { delay, from } from 'rxjs';
import { describe, test } from 'vitest';

describe('playground stephan', () => {
test('basics', async () => {
const s = from([1, 2, 3, 4, 5, 6, 7, 8, 9])

Check warning on line 6 in packages/playground/src/demo/index.test.js

View workflow job for this annotation

GitHub Actions / Install (ubuntu-latest, 20)

's' is assigned a value but never used
.pipe(delay(4000))
.subscribe(e => {
console.log(e);

Check warning on line 9 in packages/playground/src/demo/index.test.js

View workflow job for this annotation

GitHub Actions / Install (ubuntu-latest, 20)

Unexpected console statement
// s.unsubscribe();
});
await new Promise(done => setTimeout(done, 5000));
});
});
11 changes: 11 additions & 0 deletions packages/playground/vitest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { defineProject } from 'vitest/config';

export default defineProject({
cacheDir: '../.cache/vitest-playground',
test: {
cacheDir: '../.cache/vitest',
setupFiles: ['../../setup.js'],
testTimeout: 10000,
environment: 'happy-dom'
}
});
8 changes: 5 additions & 3 deletions vitest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { defineConfig, configDefaults } from 'vitest/config';

export default defineConfig({
test: {
cacheDir: './.cache/vitest',

coverage: {
provider: 'v8',
reporter: ['text', 'json', 'lcov', 'html'],
Expand All @@ -11,10 +13,10 @@ export default defineConfig({
'commitlint.config.js',
'eslint.ignores.js',
'vitest.workspace.js',
'./packages/observables/src/index.js',
'./packages/operators/src/index.js'
'./packages/mocks/',
'./packages/*/src/index.js'
]
},
include: ['**/packages/**/*.test.js']
include: ['./packages/**/*.test.js']
}
});
19 changes: 18 additions & 1 deletion vitest.workspace.js
Original file line number Diff line number Diff line change
@@ -1 +1,18 @@
export default ['packages/**/vitest.config.js'];
// export default ['packages/**/vitest.config.js'];

import { readFileSync } from 'node:fs';
import { defineWorkspace } from 'vitest/config';

const pkg = JSON.parse(readFileSync('./package.json', 'utf-8'));

export default defineWorkspace([
...pkg.workspaces
.filter(name => !['scripts'].includes(name))
.map(name => ({
extends: `./${name}/vitest.config.js`,
test: {
root: `./${name}`,
name
}
}))
]);

0 comments on commit 9b69b72

Please sign in to comment.