@naturalcycles/dev-lib 17.2.1 → 18.0.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.
- package/cfg/_cnst.d.ts +7 -0
- package/cfg/_cnst.js +21 -12
- package/cfg/commitlint.config.js +1 -1
- package/cfg/eslint-biome-rules.js +1 -1
- package/cfg/eslint-prettier-rules.js +1 -1
- package/cfg/eslint-rules.js +1 -1
- package/cfg/eslint-vue-rules.js +1 -1
- package/cfg/eslint.config.js +27 -23
- package/cfg/init/commitlint.config.js +4 -2
- package/cfg/init/eslint.config.js +5 -4
- package/cfg/init/lint-staged.config.js +4 -2
- package/cfg/init/prettier.config.js +3 -3
- package/cfg/init/{vitest.config.mts → vitest.config.ts} +1 -1
- package/cfg/lint-staged.config.js +8 -8
- package/cfg/prettier.config.js +1 -1
- package/cfg/stylelint.config.js +1 -1
- package/cfg/tsconfig.json +3 -2
- package/cfg/{vitest.config.mjs → vitest.config.js} +1 -1
- package/dist/bin/dev-lib.js +41 -48
- package/dist/bin/up.js +4 -6
- package/dist/bin/upnc.js +4 -6
- package/dist/build.util.d.ts +0 -1
- package/dist/build.util.js +12 -70
- package/dist/index.js +1 -2
- package/dist/init-from-dev-lib.command.js +5 -8
- package/dist/lint.util.js +56 -76
- package/dist/paths.js +10 -10
- package/dist/test.util.js +8 -127
- package/dist/testing/index.d.ts +2 -4
- package/dist/testing/index.js +5 -7
- package/dist/testing/mockAllKindsOfThings.js +3 -7
- package/dist/testing/{testOffline.util.js → testOffline.js} +3 -7
- package/dist/testing/testing.util.js +7 -11
- package/dist/testing/time.js +12 -0
- package/dist/yarn.util.js +12 -16
- package/package.json +5 -3
- package/readme.md +9 -24
- package/cfg/eslint-jest-rules.js +0 -14
- package/cfg/jest.alphabetic.sequencer.js +0 -13
- package/cfg/jest.config.js +0 -139
- package/cfg/jest.esbuild.transformer.js +0 -37
- package/cfg/jest.integration-test.config.js +0 -41
- package/cfg/jest.manual-test.config.js +0 -25
- package/dist/testing/time.util.js +0 -18
- /package/cfg/{vitest.config.d.mts → vitest.config.d.ts} +0 -0
- /package/cfg/{vitestAlphabeticSequencer.mjs → vitestAlphabeticSequencer.js} +0 -0
- /package/dist/testing/{testOffline.util.d.ts → testOffline.d.ts} +0 -0
- /package/dist/testing/{time.util.d.ts → time.d.ts} +0 -0
package/readme.md
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
- ESLint
|
|
18
18
|
- Biome
|
|
19
19
|
- Stylelint
|
|
20
|
-
-
|
|
20
|
+
- Vitest
|
|
21
21
|
- ktlint
|
|
22
22
|
- actionlint
|
|
23
23
|
- lint-staged
|
|
@@ -46,7 +46,7 @@ UPD: these tools/linters would use default configs if absent:
|
|
|
46
46
|
|
|
47
47
|
These tools require a respective config to run, otherwise they're not run. List of configs:
|
|
48
48
|
|
|
49
|
-
- `
|
|
49
|
+
- `vitest.config.js`
|
|
50
50
|
- `prettier.config.js`
|
|
51
51
|
- `eslint.config.js` (eslint FLAT config)
|
|
52
52
|
- `stylelint.config.js`
|
|
@@ -112,7 +112,7 @@ automatically in any environment. They're useful to run tests manually every now
|
|
|
112
112
|
|
|
113
113
|
All test commands set `TZ=UTC`. You can override it by providing `TZ` env variable **before**
|
|
114
114
|
running a test command. Adds `APP_ENV=test` env var (for all runs except integration). Automatically
|
|
115
|
-
adds `--silent` (and `
|
|
115
|
+
adds `--silent` (and `TEST_SILENT` env var) if all tests are run.
|
|
116
116
|
|
|
117
117
|
- `test`: runs unit tests (all tests _except_ `*.integration.test.ts` and `*.manual.test.ts`).
|
|
118
118
|
Detects `CI` env variable, adds `--coverage` if in CI. Uses `default` reporter in `!CI`, otherwise
|
|
@@ -123,34 +123,19 @@ adds `--silent` (and `JEST_SILENT` env var) if all tests are run.
|
|
|
123
123
|
|
|
124
124
|
For unit tests (`yarn test`) these `setupFilesAfterEnv` will be used (if found) in that order:
|
|
125
125
|
|
|
126
|
-
- `<rootDir>/src/test/
|
|
127
|
-
- `<rootDir>/src/test/
|
|
126
|
+
- `<rootDir>/src/test/setupVitest.ts`
|
|
127
|
+
- `<rootDir>/src/test/setupVitest.unit.ts`
|
|
128
128
|
|
|
129
129
|
For integration tests (`yarn test-integration`) these `setupFilesAfterEnv` will be used (if found)
|
|
130
130
|
in that order:
|
|
131
131
|
|
|
132
|
-
- `<rootDir>/src/test/
|
|
133
|
-
- `<rootDir>/src/test/
|
|
132
|
+
- `<rootDir>/src/test/setupVitest.ts`
|
|
133
|
+
- `<rootDir>/src/test/setupVitest.integration.ts`
|
|
134
134
|
|
|
135
135
|
For manual tests:
|
|
136
136
|
|
|
137
|
-
- `<rootDir>/src/test/
|
|
138
|
-
- `<rootDir>/src/test/
|
|
139
|
-
|
|
140
|
-
`yarn dev-lib test` runs tests in alphabetic order by default (internally it points
|
|
141
|
-
`--testSequencer` to a pre-defined sequencer file that sorts all filenames alphabetically). Set
|
|
142
|
-
`JEST_NO_ALPHABETIC` env variable to disable it.
|
|
143
|
-
|
|
144
|
-
##### Shard support
|
|
145
|
-
|
|
146
|
-
Jest 28 introduced [--shard](https://jestjs.io/docs/cli#--shard) feature.
|
|
147
|
-
|
|
148
|
-
Set `JEST_SHARDS` environment variable (e.g `export JEST_SHARDS=3`), so that your `yarn test*`
|
|
149
|
-
commands will automatically split your tests by N number of shards and execute them **one after
|
|
150
|
-
another** (serially, **not** in parallel). Might be helpful to avoid Jest's notorious memory leaks.
|
|
151
|
-
|
|
152
|
-
If you need to execute shards **in parallel**, you can follow e.g
|
|
153
|
-
[this instruction](https://medium.com/@mfreundlich1/speed-up-your-jest-tests-with-shards-776e9f02f637).
|
|
137
|
+
- `<rootDir>/src/test/setupVitest.ts`
|
|
138
|
+
- `<rootDir>/src/test/setupVitest.manual.ts`
|
|
154
139
|
|
|
155
140
|
#### Lint commands
|
|
156
141
|
|
package/cfg/eslint-jest-rules.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
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
|
-
'jest/expect-expect': 0,
|
|
9
|
-
'jest/no-commented-out-tests': 0,
|
|
10
|
-
'jest/no-export': 2,
|
|
11
|
-
'jest/no-conditional-expect': 0,
|
|
12
|
-
'jest/no-disabled-tests': 0,
|
|
13
|
-
},
|
|
14
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
const Sequencer = require('@jest/test-sequencer').default
|
|
2
|
-
|
|
3
|
-
class CustomSequencer extends Sequencer {
|
|
4
|
-
sort(tests) {
|
|
5
|
-
// console.log('jest.alphabetic.sequencer.js is used')
|
|
6
|
-
// Test structure information
|
|
7
|
-
// https://github.com/facebook/jest/blob/6b8b1404a1d9254e7d5d90a8934087a9c9899dab/packages/jest-runner/src/types.ts#L17-L21
|
|
8
|
-
const copyTests = Array.from(tests)
|
|
9
|
-
return copyTests.sort((testA, testB) => (testA.path > testB.path ? 1 : -1))
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
module.exports = CustomSequencer
|
package/cfg/jest.config.js
DELETED
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Default config for jest.
|
|
3
|
-
* Extendable.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
const fs = require('node:fs')
|
|
7
|
-
|
|
8
|
-
const runInIDE = process.argv.some(
|
|
9
|
-
a => a === '--runTestsByPath' || a.includes('IDEA') || a.includes('Visual Studio'),
|
|
10
|
-
)
|
|
11
|
-
const ideIntegrationTest = runInIDE && process.argv.some(a => a.endsWith('.integration.test.ts'))
|
|
12
|
-
const ideManualTest = runInIDE && process.argv.some(a => a.endsWith('.manual.test.ts'))
|
|
13
|
-
const { CI, GITHUB_ACTIONS } = process.env
|
|
14
|
-
const cwd = process.cwd()
|
|
15
|
-
|
|
16
|
-
// Set 'setupFilesAfterEnv' only if it exists
|
|
17
|
-
const setupFilesAfterEnv = []
|
|
18
|
-
if (fs.existsSync(`${cwd}/src/test/setupJest.ts`)) {
|
|
19
|
-
setupFilesAfterEnv.push('<rootDir>/src/test/setupJest.ts')
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if (ideIntegrationTest) {
|
|
23
|
-
if (fs.existsSync(`${cwd}/src/test/setupJest.integration.ts`)) {
|
|
24
|
-
setupFilesAfterEnv.push('<rootDir>/src/test/setupJest.integration.ts')
|
|
25
|
-
}
|
|
26
|
-
} else if (ideManualTest) {
|
|
27
|
-
if (fs.existsSync(`${cwd}/src/test/setupJest.manual.ts`)) {
|
|
28
|
-
setupFilesAfterEnv.push('<rootDir>/src/test/setupJest.manual.ts')
|
|
29
|
-
}
|
|
30
|
-
} else {
|
|
31
|
-
if (fs.existsSync(`${cwd}/src/test/setupJest.unit.ts`)) {
|
|
32
|
-
setupFilesAfterEnv.push('<rootDir>/src/test/setupJest.unit.ts')
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const testMatch = ['<rootDir>/src/**/*.test.ts?(x)']
|
|
37
|
-
const roots = ['<rootDir>/src']
|
|
38
|
-
const scriptDirExists = fs.existsSync(`${cwd}/scripts`)
|
|
39
|
-
if (scriptDirExists) {
|
|
40
|
-
testMatch.push('<rootDir>/scripts/**/*.test.ts?(x)')
|
|
41
|
-
roots.push('<rootDir>/scripts')
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const testPathIgnorePatterns = ['<rootDir>/.*/__exclude/', '<rootDir>/src/environments/']
|
|
45
|
-
|
|
46
|
-
// console.log({argv: process.argv})
|
|
47
|
-
|
|
48
|
-
if (runInIDE) {
|
|
49
|
-
console.log({ runInIDE, ideIntegrationTest, ideManualTest })
|
|
50
|
-
process.env.APP_ENV = process.env.APP_ENV || 'test'
|
|
51
|
-
process.env.TZ = process.env.TZ || 'UTC'
|
|
52
|
-
} else {
|
|
53
|
-
// This allows to run integration/manual tests in IDE
|
|
54
|
-
testPathIgnorePatterns.push('\\.integration\\.test\\.ts$', '\\.manual\\.test\\.ts$')
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/** @typedef {import('ts-jest/dist/types')} */
|
|
58
|
-
module.exports = {
|
|
59
|
-
transform: {
|
|
60
|
-
// '^.+\\.js$': 'babel-jest',
|
|
61
|
-
'^.+\\.tsx?$': [
|
|
62
|
-
'ts-jest',
|
|
63
|
-
{
|
|
64
|
-
diagnostics: false,
|
|
65
|
-
// compilerHost: true, // disabled, cause its effects are not detected/understood yet
|
|
66
|
-
// incremental: true,
|
|
67
|
-
isolatedModules: true, // faster when run without cache (e.g in CI), 50s vs 83s for NCBackend3 right now
|
|
68
|
-
babelConfig: false, // https://kulshekhar.github.io/ts-jest/user/config/babelConfig
|
|
69
|
-
tsconfig: {
|
|
70
|
-
sourceMap: true,
|
|
71
|
-
allowJs: true,
|
|
72
|
-
},
|
|
73
|
-
},
|
|
74
|
-
],
|
|
75
|
-
// example (experimental):
|
|
76
|
-
// '^.+\\.ts$': '@naturalcycles/dev-lib/cfg/jest.esbuild.transformer.js',
|
|
77
|
-
},
|
|
78
|
-
transformIgnorePatterns: ['/node_modules/'], // Jest default value
|
|
79
|
-
testMatch,
|
|
80
|
-
roots,
|
|
81
|
-
rootDir: cwd,
|
|
82
|
-
testPathIgnorePatterns,
|
|
83
|
-
moduleFileExtensions: ['js', 'jsx', 'ts', 'tsx', 'd.ts', 'json'],
|
|
84
|
-
moduleNameMapper: {
|
|
85
|
-
// should match aliases from tsconfig.json
|
|
86
|
-
// as explained here: https://alexjoverm.github.io/2017/10/07/Enhance-Jest-configuration-with-Module-Aliases/
|
|
87
|
-
'@src/(.*)$': '<rootDir>/src/$1',
|
|
88
|
-
},
|
|
89
|
-
skipNodeResolution: true,
|
|
90
|
-
testEnvironment: 'node',
|
|
91
|
-
errorOnDeprecated: true,
|
|
92
|
-
restoreMocks: true,
|
|
93
|
-
unmockedModulePathPatterns: [],
|
|
94
|
-
setupFilesAfterEnv,
|
|
95
|
-
workerIdleMemoryLimit: '800MB', // workaround for this: https://github.com/facebook/jest/issues/11956
|
|
96
|
-
collectCoverageFrom: [
|
|
97
|
-
'src/**/*.{ts,tsx}',
|
|
98
|
-
'!**/__exclude/**',
|
|
99
|
-
'!src/index.{ts,tsx}',
|
|
100
|
-
'!src/test/**',
|
|
101
|
-
'!src/typings/**',
|
|
102
|
-
'!scripts/**',
|
|
103
|
-
'!src/env/**',
|
|
104
|
-
'!src/environment/**',
|
|
105
|
-
'!src/environments/**',
|
|
106
|
-
'!src/env/**',
|
|
107
|
-
'!src/bin/**',
|
|
108
|
-
'!src/vendor/**',
|
|
109
|
-
'!public/**',
|
|
110
|
-
'!**/*.test.ts',
|
|
111
|
-
'!**/*.script.ts',
|
|
112
|
-
'!**/*.module.ts',
|
|
113
|
-
'!**/*.mock.ts',
|
|
114
|
-
'!**/*.page.{ts,tsx}',
|
|
115
|
-
'!**/*.component.{ts,tsx}',
|
|
116
|
-
'!**/*.modal.{ts,tsx}',
|
|
117
|
-
],
|
|
118
|
-
// default: ["clover", "json", "lcov", "text"]
|
|
119
|
-
coverageReporters: ['clover', 'json', 'json-summary', 'lcov', !CI && 'text'].filter(Boolean),
|
|
120
|
-
// CI: only jest-junit reporter (no default)
|
|
121
|
-
// not-CI: only default reporter, but not jest-junit
|
|
122
|
-
reporters: [
|
|
123
|
-
'default',
|
|
124
|
-
CI && [
|
|
125
|
-
'jest-junit',
|
|
126
|
-
{
|
|
127
|
-
suiteName: 'jest tests',
|
|
128
|
-
outputDirectory: './tmp/jest',
|
|
129
|
-
outputName: 'unit.xml',
|
|
130
|
-
suiteNameTemplate: '{filepath}',
|
|
131
|
-
classNameTemplate: '{filename} - {classname}',
|
|
132
|
-
titleTemplate: '{title}',
|
|
133
|
-
ancestorSeparator: ' ',
|
|
134
|
-
},
|
|
135
|
-
],
|
|
136
|
-
GITHUB_ACTIONS && 'github-actions', // https://jestjs.io/blog/2022/04/25/jest-28#github-actions-reporter
|
|
137
|
-
].filter(Boolean),
|
|
138
|
-
prettierPath: null, // todo: remove when jest has fixed it https://github.com/jestjs/jest/issues/14305
|
|
139
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
const { transformSync } = require('esbuild')
|
|
2
|
-
|
|
3
|
-
const debug = !!process.env.DEBUG_ESBUILD
|
|
4
|
-
|
|
5
|
-
// https://esbuild.github.io/api/
|
|
6
|
-
module.exports = {
|
|
7
|
-
process(src, filename) {
|
|
8
|
-
if (debug) {
|
|
9
|
-
console.log(filename)
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const result = transformSync(src, {
|
|
13
|
-
sourcefile: filename,
|
|
14
|
-
loader: 'ts',
|
|
15
|
-
// platform: 'node',
|
|
16
|
-
format: 'cjs',
|
|
17
|
-
target: 'es2020',
|
|
18
|
-
sourcemap: true,
|
|
19
|
-
// tsconfigRaw: `{
|
|
20
|
-
// "compilerOptions": {
|
|
21
|
-
// "esModuleInterop": false,
|
|
22
|
-
// },
|
|
23
|
-
// }`,
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
// console.log(result.code)
|
|
27
|
-
|
|
28
|
-
if (result.warnings.length) {
|
|
29
|
-
console.log(...result.warnings)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return {
|
|
33
|
-
code: result.code,
|
|
34
|
-
map: result.map,
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* "Integration test" config for jest.
|
|
3
|
-
* Extendable.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
const fs = require('node:fs')
|
|
7
|
-
const { CI, GITHUB_ACTIONS } = process.env
|
|
8
|
-
const cwd = process.cwd()
|
|
9
|
-
|
|
10
|
-
// Set 'setupFilesAfterEnv' only if it exists
|
|
11
|
-
const setupFilesAfterEnv = []
|
|
12
|
-
if (fs.existsSync(`${cwd}/src/test/setupJest.ts`)) {
|
|
13
|
-
setupFilesAfterEnv.push('<rootDir>/src/test/setupJest.ts')
|
|
14
|
-
}
|
|
15
|
-
if (fs.existsSync(`${cwd}/src/test/setupJest.integration.ts`)) {
|
|
16
|
-
setupFilesAfterEnv.push('<rootDir>/src/test/setupJest.integration.ts')
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/** @typedef {import('ts-jest/dist/types')} */
|
|
20
|
-
module.exports = {
|
|
21
|
-
...require('./jest.config'),
|
|
22
|
-
testMatch: ['<rootDir>/src/**/*.integration.test.ts'],
|
|
23
|
-
testPathIgnorePatterns: ['<rootDir>/.*/__exclude/'],
|
|
24
|
-
setupFilesAfterEnv,
|
|
25
|
-
reporters: [
|
|
26
|
-
'default',
|
|
27
|
-
CI && [
|
|
28
|
-
'jest-junit',
|
|
29
|
-
{
|
|
30
|
-
suiteName: 'jest tests',
|
|
31
|
-
outputDirectory: './tmp/jest',
|
|
32
|
-
outputName: 'integration.xml',
|
|
33
|
-
suiteNameTemplate: '{filepath}',
|
|
34
|
-
classNameTemplate: '{classname}',
|
|
35
|
-
titleTemplate: '{title}',
|
|
36
|
-
ancestorSeparator: ' ',
|
|
37
|
-
},
|
|
38
|
-
],
|
|
39
|
-
GITHUB_ACTIONS && 'github-actions',
|
|
40
|
-
].filter(Boolean),
|
|
41
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* "Manual test" config for jest.
|
|
3
|
-
* Extendable.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
const fs = require('node:fs')
|
|
7
|
-
const cwd = process.cwd()
|
|
8
|
-
|
|
9
|
-
// Set 'setupFilesAfterEnv' only if it exists
|
|
10
|
-
const setupFilesAfterEnv = []
|
|
11
|
-
if (fs.existsSync(`${cwd}/src/test/setupJest.ts`)) {
|
|
12
|
-
setupFilesAfterEnv.push('<rootDir>/src/test/setupJest.ts')
|
|
13
|
-
}
|
|
14
|
-
if (fs.existsSync(`${cwd}/src/test/setupJest.manual.ts`)) {
|
|
15
|
-
setupFilesAfterEnv.push('<rootDir>/src/test/setupJest.manual.ts')
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/** @typedef {import('ts-jest/dist/types')} */
|
|
19
|
-
module.exports = {
|
|
20
|
-
...require('./jest.config'),
|
|
21
|
-
testMatch: ['<rootDir>/src/**/*.manual.test.ts'],
|
|
22
|
-
testPathIgnorePatterns: ['<rootDir>/.*/__exclude/'],
|
|
23
|
-
setupFilesAfterEnv,
|
|
24
|
-
reporters: ['default'],
|
|
25
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MOCK_TS_2018_06_21 = void 0;
|
|
4
|
-
exports.mockTime = mockTime;
|
|
5
|
-
exports.resetTime = resetTime;
|
|
6
|
-
exports.MOCK_TS_2018_06_21 = 1_529_539_200;
|
|
7
|
-
/**
|
|
8
|
-
* Locks time-related functions to return always same time.
|
|
9
|
-
* For deterministic tests.
|
|
10
|
-
*/
|
|
11
|
-
function mockTime(ts = exports.MOCK_TS_2018_06_21) {
|
|
12
|
-
const timekeeper = require('timekeeper');
|
|
13
|
-
timekeeper.freeze(ts * 1000);
|
|
14
|
-
}
|
|
15
|
-
function resetTime() {
|
|
16
|
-
const timekeeper = require('timekeeper');
|
|
17
|
-
timekeeper.reset();
|
|
18
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|