@naturalcycles/dev-lib 18.0.1 → 18.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -31,7 +31,7 @@ export default {
31
31
  },
32
32
  },
33
33
  ],
34
- '@typescript-eslint/consistent-type-imports': 0, // too noisy
34
+ '@typescript-eslint/consistent-type-imports': 2,
35
35
  '@typescript-eslint/consistent-type-exports': 2,
36
36
  '@typescript-eslint/consistent-type-assertions': 2,
37
37
  '@typescript-eslint/consistent-type-definitions': [2, 'interface'],
@@ -0,0 +1,34 @@
1
+ export default {
2
+ rules: {
3
+ 'vitest/consistent-test-filename': 2,
4
+ 'vitest/consistent-test-it': [
5
+ 2,
6
+ {
7
+ fn: 'test',
8
+ withinDescribe: 'test',
9
+ },
10
+ ],
11
+ 'vitest/expect-expect': 0,
12
+ 'vitest/max-nested-describe': [2, { max: 3 }],
13
+ 'vitest/no-alias-methods': 2,
14
+ 'vitest/no-commented-out-tests': 0,
15
+ 'vitest/no-duplicate-hooks': 2,
16
+ 'vitest/no-test-return-statement': 2,
17
+ 'vitest/padding-around-before-all-blocks': 2,
18
+ 'vitest/padding-around-after-all-blocks': 2,
19
+ 'vitest/padding-around-before-each-blocks': 2,
20
+ 'vitest/padding-around-after-each-blocks': 2,
21
+ 'vitest/padding-around-describe-blocks': 2,
22
+ 'vitest/prefer-hooks-in-order': 2,
23
+ 'vitest/prefer-hooks-on-top': 2,
24
+ 'vitest/prefer-mock-promise-shorthand': 2,
25
+ 'vitest/prefer-spy-on': 2,
26
+ 'vitest/prefer-strict-boolean-matchers': 2,
27
+ 'vitest/prefer-to-be': 2,
28
+ 'vitest/prefer-to-contain': 2,
29
+ 'vitest/prefer-to-have-length': 2,
30
+ 'vitest/prefer-vi-mocked': 2,
31
+ 'vitest/require-to-throw-message': 2,
32
+ 'vitest/valid-expect-in-promise': 2,
33
+ },
34
+ }
@@ -9,16 +9,19 @@ import eslint from '@eslint/js'
9
9
  import tseslint from 'typescript-eslint'
10
10
  import eslintPluginUnicorn from 'eslint-plugin-unicorn'
11
11
  import eslintPluginVue from 'eslint-plugin-vue'
12
+ import eslintPluginVitest from '@vitest/eslint-plugin'
12
13
  import eslintPluginImportX from 'eslint-plugin-import-x'
13
14
  import eslintPluginSimpleImportSort from 'eslint-plugin-simple-import-sort'
14
15
  import eslintPluginJsdoc from 'eslint-plugin-jsdoc'
15
16
  import eslintPluginStylistic from '@stylistic/eslint-plugin'
16
17
  import eslintRules from './eslint-rules.js'
17
18
  import eslintVueRules from './eslint-vue-rules.js'
19
+ import eslintVitestRules from './eslint-vitest-rules.js'
18
20
  import eslintPrettierRules from './eslint-prettier-rules.js'
19
21
  import eslintBiomeRules from './eslint-biome-rules.js'
20
22
 
21
23
  const defaultFiles = ['**/*.ts', '**/*.tsx', '**/*.cts', '**/*.mts']
24
+ const testFiles = ['**/*.test.ts', '**/*.test.tsx', '**/*.test.cts', '**/*.test.mts']
22
25
 
23
26
  export default [
24
27
  {
@@ -46,6 +49,21 @@ export default [
46
49
  ...c,
47
50
  files: defaultFiles,
48
51
  })),
52
+ {
53
+ files: testFiles,
54
+ plugins: {
55
+ vitest: eslintPluginVitest,
56
+ },
57
+ settings: {
58
+ vitest: {
59
+ typecheck: true,
60
+ },
61
+ },
62
+ rules: {
63
+ ...eslintPluginVitest.configs.recommended.rules,
64
+ ...eslintVitestRules.rules,
65
+ },
66
+ },
49
67
  {
50
68
  files: defaultFiles,
51
69
  ...getConfig(),
@@ -64,7 +82,6 @@ function getConfig() {
64
82
  'simple-import-sort': eslintPluginSimpleImportSort,
65
83
  jsdoc: eslintPluginJsdoc,
66
84
  '@stylistic': eslintPluginStylistic,
67
- // ...(hasJest ? { jest: require('eslint-plugin-jest') } : {}), // todo: eslint-plugin-vitest
68
85
  },
69
86
  languageOptions: {
70
87
  ecmaVersion: 'latest',
@@ -88,7 +105,6 @@ function getConfig() {
88
105
  rules: {
89
106
  ...eslintRules.rules,
90
107
  ...eslintVueRules.rules,
91
- // ...(hasJest ? require('./eslint-jest-rules').rules : {}), // todo: vitest-rules
92
108
  ...eslintPrettierRules.rules, // disable eslint rules already covered by prettier
93
109
  ...eslintBiomeRules.rules, // disable eslint rules already covered by biome
94
110
  },
@@ -1,8 +1,5 @@
1
- import { defineConfig } from 'vitest/config'
2
- import { sharedConfig } from '@naturalcycles/dev-lib/cfg/vitest.config.js'
1
+ import { defineVitestConfig } from '@naturalcycles/dev-lib/cfg/vitest.config.js'
3
2
 
4
- export default defineConfig({
5
- test: {
6
- ...sharedConfig,
7
- },
3
+ export default defineVitestConfig({
4
+ // override here
8
5
  })
package/cfg/tsconfig.json CHANGED
@@ -20,7 +20,7 @@
20
20
  // specifying these explicitly for better IDE compatibility (but they're on by default with module=nodenext)
21
21
  "esModuleInterop": true,
22
22
  "allowSyntheticDefaultImports": true,
23
- // "verbatimModuleSyntax": true, // not enabled, since we'll need a lint rule to enforce `import type`
23
+ "verbatimModuleSyntax": true,
24
24
  // Faster compilation in general
25
25
  // Support for external compilers (e.g esbuild)
26
26
  // Speedup in Jest by using "isolatedModules" in 'ts-jest' config
@@ -1,3 +1,15 @@
1
1
  import type { InlineConfig } from 'vitest/node'
2
2
 
3
+ /**
4
+
5
+ Usage example:
6
+
7
+ export default defineVitestConfig({
8
+ // overrides here, e.g:
9
+ // bail: 1,
10
+ })
11
+
12
+ */
13
+ export function defineVitestConfig(config?: Partial<InlineConfig>): InlineConfig
14
+
3
15
  export const sharedConfig: InlineConfig
@@ -1,12 +1,14 @@
1
1
  import fs from 'node:fs'
2
-
3
2
  import { VitestAlphabeticSequencer } from './vitestAlphabeticSequencer.js'
3
+ import { defineConfig } from 'vitest/config'
4
+
4
5
  const runsInIDE = doesItRunInIDE()
5
6
  const testType = getTestType(runsInIDE)
6
7
  const silent = shouldBeSilent(runsInIDE)
7
8
  const setupFiles = getSetupFiles(testType)
8
9
  const { include, exclude } = getIncludeAndExclude(testType)
9
10
  const isCI = !!process.env['CI']
11
+ const coverageEnabled = isCI && testType === 'unit'
10
12
  const junitReporterEnabled = isCI && testType !== 'manual'
11
13
  const maxWorkers = getMaxWorkers()
12
14
  const minWorkers = maxWorkers
@@ -14,6 +16,7 @@ const minWorkers = maxWorkers
14
16
  // UPD: it was not statistically significant, so, reverting back to forks which is more stable
15
17
  // UPD2: in a different experiment, threads show ~10% faster locally, consistently
16
18
  const pool = 'threads'
19
+
17
20
  process.env.TZ ||= 'UTC'
18
21
 
19
22
  if (testType === 'unit') {
@@ -24,16 +27,37 @@ if (silent) {
24
27
  process.env['TEST_SILENT'] = 'true'
25
28
  }
26
29
 
27
- console.log('shared vitest config', {
28
- testType,
29
- silent,
30
- isCI,
31
- runsInIDE,
32
- include,
33
- exclude,
34
- pool,
35
- maxWorkers,
36
- })
30
+ /**
31
+ * Use it like this in your vitest.config.ts:
32
+ *
33
+ * export default defineVitestConfig({
34
+ * // overrides here, e.g:
35
+ * // bail: 1,
36
+ * })
37
+ */
38
+ export function defineVitestConfig(config) {
39
+ const mergedConfig = defineConfig({
40
+ test: {
41
+ ...sharedConfig,
42
+ ...config,
43
+ },
44
+ })
45
+
46
+ const { silent, include, exclude, pool, maxWorkers } = mergedConfig.test
47
+
48
+ console.log({
49
+ testType,
50
+ silent,
51
+ isCI,
52
+ runsInIDE,
53
+ include,
54
+ exclude,
55
+ pool,
56
+ maxWorkers,
57
+ })
58
+
59
+ return mergedConfig
60
+ }
37
61
 
38
62
  /**
39
63
  * Shared config for Vitest.
@@ -73,7 +97,7 @@ export const sharedConfig = {
73
97
  // outputFile location is specified for compatibility with the previous jest config
74
98
  outputFile: junitReporterEnabled ? `./tmp/jest/${testType}.xml` : undefined,
75
99
  coverage: {
76
- enabled: isCI && testType === 'unit',
100
+ enabled: coverageEnabled,
77
101
  reporter: ['html', 'lcov', 'json', 'json-summary', !isCI && 'text'].filter(Boolean),
78
102
  include: ['src/**/*.{ts,tsx}'],
79
103
  exclude: [
@@ -22,7 +22,7 @@ export async function runTSCInFolders(tsconfigPaths, args = [], parallel = true)
22
22
  */
23
23
  export async function runTSCInFolder(tsconfigPath, args = []) {
24
24
  if (!fs2.pathExists(tsconfigPath)) {
25
- console.log(`Skipping to run tsc for ${tsconfigPath}, as it doesn't exist`);
25
+ // console.log(`Skipping to run tsc for ${tsconfigPath}, as it doesn't exist`)
26
26
  return;
27
27
  }
28
28
  await exec2.spawnAsync(`tsc`, {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/dev-lib",
3
3
  "type": "module",
4
- "version": "18.0.1",
4
+ "version": "18.1.1",
5
5
  "scripts": {
6
6
  "prepare": "husky",
7
7
  "tsx-debug": "tsx scripts/testScript.ts",
@@ -28,6 +28,8 @@
28
28
  "@naturalcycles/nodejs-lib": "^14",
29
29
  "@stylistic/eslint-plugin": "^4",
30
30
  "@types/node": "^22",
31
+ "@vitest/coverage-v8": "^3",
32
+ "@vitest/eslint-plugin": "^1",
31
33
  "eslint": "^9",
32
34
  "eslint-plugin-import-x": "^4",
33
35
  "eslint-plugin-jsdoc": "^50",
@@ -47,7 +49,6 @@
47
49
  },
48
50
  "devDependencies": {
49
51
  "@types/mitm": "^1.3.8",
50
- "@vitest/coverage-v8": "^3",
51
52
  "stylelint": "^16",
52
53
  "stylelint-config-standard-scss": "^14",
53
54
  "tsx": "^4",