@naturalcycles/dev-lib 13.3.0 → 13.5.0

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.
@@ -0,0 +1,9 @@
1
+ module.exports = {
2
+ rules: {
3
+ 'jest/prefer-equality-matcher': 2,
4
+ 'jest/prefer-spy-on': 2,
5
+ 'jest/prefer-to-be': 2,
6
+ 'jest/prefer-to-contain': 2,
7
+ 'jest/consistent-test-it': [2, { fn: 'test', withinDescribe: 'test' }],
8
+ },
9
+ }
@@ -297,11 +297,6 @@ module.exports = {
297
297
  'jest/no-export': 0, // conflicts with typescript isolatedModules
298
298
  'jest/no-conditional-expect': 0,
299
299
  'jest/no-disabled-tests': 0,
300
- 'jest/prefer-equality-matcher': 2,
301
- 'jest/prefer-spy-on': 2,
302
- 'jest/prefer-to-be': 2,
303
- 'jest/prefer-to-contain': 2,
304
- 'jest/consistent-test-it': [2, { fn: 'test', withinDescribe: 'test' }],
305
300
  '@typescript-eslint/no-namespace': [
306
301
  2,
307
302
  {
@@ -3,6 +3,11 @@
3
3
  *
4
4
  * Shared eslint config.
5
5
  */
6
+
7
+ // detect if jest is installed
8
+ const hasJest = require('fs').existsSync('./node_modules/jest')
9
+ // console.log({hasJest})
10
+
6
11
  module.exports = {
7
12
  env: {
8
13
  es2020: true,
@@ -33,8 +38,9 @@ module.exports = {
33
38
  // https://github.com/import-js/eslint-plugin-import/blob/main/config/typescript.js
34
39
  // 'plugin:import/typescript',
35
40
  './eslint-rules.js',
41
+ hasJest && './eslint-jest-rules.js',
36
42
  'prettier', // must be last! it only turns off eslint rules that conflict with prettier
37
- ],
43
+ ].filter(Boolean),
38
44
  parser: '@typescript-eslint/parser',
39
45
  parserOptions: {
40
46
  project: ['tsconfig.json'],
@@ -48,9 +54,9 @@ module.exports = {
48
54
  '@typescript-eslint',
49
55
  // https://github.com/sweepline/eslint-plugin-unused-imports
50
56
  'unused-imports',
51
- // 'jest', // add manually if needed!
57
+ hasJest && 'jest',
52
58
  'unicorn',
53
- ],
59
+ ].filter(Boolean),
54
60
  },
55
61
  {
56
62
  files: ['*.vue'],
@@ -56,7 +56,20 @@ if (runInIDE) {
56
56
  module.exports = {
57
57
  transform: {
58
58
  // '^.+\\.js$': 'babel-jest',
59
- '^.+\\.tsx?$': 'ts-jest',
59
+ '^.+\\.tsx?$': [
60
+ 'ts-jest',
61
+ {
62
+ diagnostics: false,
63
+ // compilerHost: true, // disabled, cause its effects are not detected/understood yet
64
+ // incremental: true,
65
+ isolatedModules: true, // faster when run without cache (e.g in CI), 50s vs 83s for NCBackend3 right now
66
+ babelConfig: false, // https://kulshekhar.github.io/ts-jest/user/config/babelConfig
67
+ tsconfig: {
68
+ sourceMap: true,
69
+ allowJs: true,
70
+ },
71
+ },
72
+ ],
60
73
  // example (experimental):
61
74
  // '^.+\\.ts$': '@naturalcycles/dev-lib/cfg/jest.esbuild.transformer.js',
62
75
  },
@@ -72,15 +85,6 @@ module.exports = {
72
85
  '@src/(.*)$': '<rootDir>/src/$1',
73
86
  },
74
87
  skipNodeResolution: true,
75
- globals: {
76
- 'ts-jest': {
77
- diagnostics: false,
78
- // compilerHost: true, // disabled, cause its effects are not detected/understood yet
79
- // incremental: true,
80
- isolatedModules: true, // faster when run without cache (e.g in CI), 50s vs 83s for NCBackend3 right now
81
- babelConfig: false, // https://kulshekhar.github.io/ts-jest/user/config/babelConfig
82
- },
83
- },
84
88
  testEnvironment: 'node',
85
89
  errorOnDeprecated: true,
86
90
  snapshotFormat: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/dev-lib",
3
- "version": "13.3.0",
3
+ "version": "13.5.0",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "tsn-debug": "tsn testScript.ts",
@@ -61,7 +61,7 @@
61
61
  "stylelint-config-prettier": "^9.0.3",
62
62
  "stylelint-config-standard-scss": "^5.0.0",
63
63
  "timekeeper": "^2.2.0",
64
- "ts-jest": "^28.0.0",
64
+ "ts-jest": "^29.0.0",
65
65
  "typescript": "^4.0.2",
66
66
  "yargs": "^17.0.0"
67
67
  },
package/readme.md CHANGED
@@ -102,8 +102,7 @@ adds `--silent` (and `JEST_SILENT` env var) if all tests are run.
102
102
  `jest-junit` reporter. Includes fix for "CircleCI out of memory issue"
103
103
  - `test-integration`: runs `*.integration.test.ts` with `jest.integration-test.config.js` config.
104
104
  - `test-manual`: runs `*.manual.test.ts` with `jest.manual-test.config.js`.
105
- - `test-leaks`: runs Jest with `--logHeapUsage --detectOpenHandles --detectLeaks` (requires `weak`
106
- module to be installed in target project).
105
+ - `test-leaks`: runs Jest with `--logHeapUsage --detectOpenHandles --detectLeaks`.
107
106
 
108
107
  For unit tests (`yarn test`) these `setupFilesAfterEnv` will be used (if found) in that order:
109
108
 
@@ -196,14 +195,9 @@ These files are meant to be extended in target project, so act as _recommended d
196
195
  - `eslint.config.json`
197
196
  - `jest.config.js`
198
197
 
199
- ## Extending eslint config
198
+ ## eslint
200
199
 
201
- ### Jest
200
+ Presence of `jest` is detected by checking if `node_modules/jest` exists.
202
201
 
203
- ```js
204
- // .eslintrc.js
205
- module.exports = {
206
- extends: ['plugin:jest/recommended'],
207
- plugins: ['jest'],
208
- }
209
- ```
202
+ If exists - `eslint-plugin-jest` recommended config (plus opinionated `dev-lib`'s rules) are
203
+ enabled. Otherwise disabled ( to not cause "jest not found" errors)