@naturalcycles/dev-lib 16.0.2 → 16.1.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.
@@ -35,15 +35,15 @@ const commands = [
35
35
  desc: 'Clean ./dist and ./dist-esm, then run "tsc" in CJS and ESM modes, with --emit and --noCheck',
36
36
  },
37
37
  new prompts_1.Separator(), // test
38
- { name: 'test', fn: test_util_1.runJest, desc: 'Run jest for *.test.ts files.' },
38
+ { name: 'test', fn: test_util_1.runTest, desc: 'Run vitest/jest for *.test.ts files.' },
39
39
  {
40
40
  name: 'test-integration',
41
- fn: () => (0, test_util_1.runJest)({ integration: true }),
41
+ fn: () => (0, test_util_1.runTest)({ integration: true }),
42
42
  desc: 'Run jest for *.integration.test.ts files.',
43
43
  },
44
44
  {
45
45
  name: 'test-leaks',
46
- fn: () => (0, test_util_1.runJest)({ leaks: true }),
46
+ fn: () => (0, test_util_1.runTest)({ leaks: true }),
47
47
  desc: 'Run jest --detectLeaks for *.test.ts files.',
48
48
  },
49
49
  new prompts_1.Separator(), // lint
@@ -136,7 +136,7 @@ async function lbt() {
136
136
  }
137
137
  async function bt() {
138
138
  await tscAll();
139
- (0, test_util_1.runJest)();
139
+ (0, test_util_1.runTest)();
140
140
  }
141
141
  async function tscAll() {
142
142
  await (0, build_util_1.runTSCInFolders)(['.', 'scripts', 'e2e'], ['--noEmit']);
@@ -1,10 +1,7 @@
1
- interface RunJestOpt {
1
+ interface RunTestOptions {
2
2
  integration?: boolean;
3
3
  manual?: boolean;
4
4
  leaks?: boolean;
5
5
  }
6
- /**
7
- * 1. Adds `--silent` if running all tests at once.
8
- */
9
- export declare function runJest(opt?: RunJestOpt): void;
6
+ export declare function runTest(opt?: RunTestOptions): void;
10
7
  export {};
package/dist/test.util.js CHANGED
@@ -1,19 +1,46 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.runJest = runJest;
3
+ exports.runTest = runTest;
4
4
  const tslib_1 = require("tslib");
5
5
  const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
6
6
  const js_lib_1 = require("@naturalcycles/js-lib");
7
7
  const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
8
8
  const paths_1 = require("./paths");
9
+ function runTest(opt = {}) {
10
+ if (nodeModuleExists('vitest')) {
11
+ runVitest(opt);
12
+ return;
13
+ }
14
+ if (nodeModuleExists('jest')) {
15
+ runJest(opt);
16
+ return;
17
+ }
18
+ console.log((0, nodejs_lib_1.dimGrey)(`vitest/jest not found, skipping tests`));
19
+ }
20
+ function runVitest(opt) {
21
+ const { integration, manual } = opt;
22
+ const processArgs = process.argv.slice(3);
23
+ const args = [...processArgs];
24
+ const { TZ = 'UTC', APP_ENV } = process.env;
25
+ const env = {
26
+ TZ,
27
+ };
28
+ if (!integration && !manual && !APP_ENV) {
29
+ Object.assign(env, {
30
+ APP_ENV: 'test',
31
+ });
32
+ }
33
+ nodejs_lib_1.exec2.spawn('vitest', {
34
+ args: (0, js_lib_1._uniq)(args),
35
+ logFinish: false,
36
+ shell: false,
37
+ env,
38
+ });
39
+ }
9
40
  /**
10
41
  * 1. Adds `--silent` if running all tests at once.
11
42
  */
12
- function runJest(opt = {}) {
13
- if (!nodeModuleExists('jest')) {
14
- console.log((0, nodejs_lib_1.dimGrey)(`node_modules/${(0, nodejs_lib_1.white)('jest')} not found, skipping tests`));
15
- return;
16
- }
43
+ function runJest(opt) {
17
44
  const { CI, CPU_LIMIT, TZ = 'UTC', APP_ENV, JEST_NO_ALPHABETIC, JEST_SHARDS } = process.env;
18
45
  const cpuLimit = Number(CPU_LIMIT) || undefined;
19
46
  const { integration, manual, leaks } = opt;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/dev-lib",
3
- "version": "16.0.2",
3
+ "version": "16.1.0",
4
4
  "scripts": {
5
5
  "prepare": "husky",
6
6
  "tsn-debug": "tsn testScript.ts",
@@ -47,13 +47,10 @@
47
47
  "yargs": "^17"
48
48
  },
49
49
  "devDependencies": {
50
- "@types/jest": "^29",
51
- "eslint-plugin-jest": "^28",
52
- "jest": "^29",
53
- "jest-junit": "^16",
50
+ "@vitest/coverage-v8": "^3",
54
51
  "stylelint": "^16",
55
52
  "stylelint-config-standard-scss": "^14",
56
- "ts-jest": "^29"
53
+ "vitest": "^3"
57
54
  },
58
55
  "files": [
59
56
  "dist",