@naturalcycles/dev-lib 12.13.4 → 12.14.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/jest.config.js +8 -5
- package/dist/bin/bt.js +3 -2
- package/dist/bin/btl.d.ts +2 -0
- package/dist/bin/btl.js +17 -0
- package/dist/bin/build.js +3 -2
- package/dist/bin/test-ci.js +2 -1
- package/dist/bin/test-integration-ci.js +2 -1
- package/dist/cmd/build-prod-esm-cjs.command.js +6 -3
- package/dist/cmd/build-prod.command.js +3 -2
- package/dist/util/jest.util.d.ts +3 -4
- package/dist/util/jest.util.js +21 -20
- package/package.json +3 -1
- package/readme.md +4 -4
package/cfg/jest.config.js
CHANGED
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
* Extendable.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
const fs = require('fs')
|
|
7
|
+
|
|
6
8
|
const runInIDE = process.argv.includes('--runTestsByPath')
|
|
7
9
|
const ideIntegrationTest = runInIDE && process.argv.some(a => a.endsWith('.integration.test.ts'))
|
|
8
10
|
const ideManualTest = runInIDE && process.argv.some(a => a.endsWith('.manual.test.ts'))
|
|
9
|
-
|
|
10
|
-
const fs = require('fs')
|
|
11
|
+
const { CI } = process.env
|
|
11
12
|
const cwd = process.cwd()
|
|
12
13
|
|
|
13
14
|
// Set 'setupFilesAfterEnv' only if it exists
|
|
@@ -106,9 +107,11 @@ module.exports = {
|
|
|
106
107
|
'!**/*.component.ts',
|
|
107
108
|
'!**/*.modal.ts',
|
|
108
109
|
],
|
|
110
|
+
// CI: only jest-junit reporter (no default)
|
|
111
|
+
// not-CI: only default reporter, but not jest-junit
|
|
109
112
|
reporters: [
|
|
110
|
-
'default',
|
|
111
|
-
[
|
|
113
|
+
!CI && 'default',
|
|
114
|
+
CI && [
|
|
112
115
|
'jest-junit',
|
|
113
116
|
{
|
|
114
117
|
suiteName: 'jest tests',
|
|
@@ -120,5 +123,5 @@ module.exports = {
|
|
|
120
123
|
ancestorSeparator: ' ',
|
|
121
124
|
},
|
|
122
125
|
],
|
|
123
|
-
],
|
|
126
|
+
].filter(Boolean),
|
|
124
127
|
}
|
package/dist/bin/bt.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
const fs = require("fs");
|
|
4
|
+
const fs = require("fs-extra");
|
|
5
5
|
const script_1 = require("@naturalcycles/nodejs-lib/dist/script");
|
|
6
6
|
const tsc_scripts_command_1 = require("../cmd/tsc-scripts.command");
|
|
7
7
|
const jest_util_1 = require("../util/jest.util");
|
|
8
8
|
const tsc_util_1 = require("../util/tsc.util");
|
|
9
9
|
(0, script_1.runScript)(async () => {
|
|
10
|
-
fs.
|
|
10
|
+
fs.emptyDirSync('./dist'); // it doesn't delete the dir itself, to prevent IDE jumping
|
|
11
|
+
// fs.rmSync('./dist', { recursive: true, force: true })
|
|
11
12
|
await (0, tsc_util_1.tsc)();
|
|
12
13
|
await (0, tsc_scripts_command_1.tscScriptsCommand)();
|
|
13
14
|
await (0, jest_util_1.runJest)();
|
package/dist/bin/btl.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const fs = require("fs-extra");
|
|
5
|
+
const script_1 = require("@naturalcycles/nodejs-lib/dist/script");
|
|
6
|
+
const lint_all_command_1 = require("../cmd/lint-all.command");
|
|
7
|
+
const tsc_scripts_command_1 = require("../cmd/tsc-scripts.command");
|
|
8
|
+
const jest_util_1 = require("../util/jest.util");
|
|
9
|
+
const tsc_util_1 = require("../util/tsc.util");
|
|
10
|
+
(0, script_1.runScript)(async () => {
|
|
11
|
+
await (0, lint_all_command_1.lintAllCommand)();
|
|
12
|
+
fs.emptyDirSync('./dist'); // it doesn't delete the dir itself, to prevent IDE jumping
|
|
13
|
+
// fs.rmSync('./dist', { recursive: true, force: true })
|
|
14
|
+
await (0, tsc_util_1.tsc)();
|
|
15
|
+
await (0, tsc_scripts_command_1.tscScriptsCommand)();
|
|
16
|
+
await (0, jest_util_1.runJest)();
|
|
17
|
+
});
|
package/dist/bin/build.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
const fs = require("fs");
|
|
4
|
+
const fs = require("fs-extra");
|
|
5
5
|
const script_1 = require("@naturalcycles/nodejs-lib/dist/script");
|
|
6
6
|
const tsc_scripts_command_1 = require("../cmd/tsc-scripts.command");
|
|
7
7
|
const tsc_util_1 = require("../util/tsc.util");
|
|
8
8
|
(0, script_1.runScript)(async () => {
|
|
9
|
-
fs.
|
|
9
|
+
fs.emptyDirSync('./dist'); // it doesn't delete the dir itself, to prevent IDE jumping
|
|
10
|
+
// fs.rmSync('./dist', { recursive: true, force: true })
|
|
10
11
|
await (0, tsc_util_1.tsc)();
|
|
11
12
|
await (0, tsc_scripts_command_1.tscScriptsCommand)();
|
|
12
13
|
});
|
package/dist/bin/test-ci.js
CHANGED
|
@@ -4,5 +4,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
const script_1 = require("@naturalcycles/nodejs-lib/dist/script");
|
|
5
5
|
const jest_util_1 = require("../util/jest.util");
|
|
6
6
|
(0, script_1.runScript)(async () => {
|
|
7
|
-
|
|
7
|
+
console.log('! "yarn test-ci" is deprecated, use plain `yarn test` instead !');
|
|
8
|
+
await (0, jest_util_1.runJest)();
|
|
8
9
|
});
|
|
@@ -4,5 +4,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
const script_1 = require("@naturalcycles/nodejs-lib/dist/script");
|
|
5
5
|
const jest_util_1 = require("../util/jest.util");
|
|
6
6
|
(0, script_1.runScript)(async () => {
|
|
7
|
-
|
|
7
|
+
console.log('! "yarn test-integration-ci" is deprecated, use plain `yarn test-integration` instead !');
|
|
8
|
+
await (0, jest_util_1.runJest)({ integration: true });
|
|
8
9
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.buildProdESMCJSCommand = void 0;
|
|
4
|
-
const fs = require("fs");
|
|
4
|
+
const fs = require("fs-extra");
|
|
5
5
|
const exec_1 = require("@naturalcycles/nodejs-lib/dist/exec");
|
|
6
6
|
// You cannot have a shared `tsconfig.prod.json` because of relative paths for `include`
|
|
7
7
|
const TSCONF_CJS_PATH = `./tsconfig.cjs.prod.json`;
|
|
@@ -11,8 +11,11 @@ async function buildProdESMCJSCommand() {
|
|
|
11
11
|
const [cjsExists, esmExists] = [
|
|
12
12
|
fs.existsSync(TSCONF_CJS_PATH),
|
|
13
13
|
fs.existsSync(TSCONF_ESM_PATH),
|
|
14
|
-
|
|
15
|
-
fs.
|
|
14
|
+
// it doesn't delete the dir itself, to prevent IDE jumping
|
|
15
|
+
fs.emptyDirSync('./dist'),
|
|
16
|
+
fs.emptyDirSync('./dist-esm'),
|
|
17
|
+
// fs.rmSync('./dist', { recursive: true, force: true }),
|
|
18
|
+
// fs.rmSync('./dist-esm', { recursive: true, force: true }),
|
|
16
19
|
];
|
|
17
20
|
const cjsPath = cjsExists ? TSCONF_CJS_PATH : TSCONF_PATH;
|
|
18
21
|
const esmPath = esmExists ? TSCONF_ESM_PATH : TSCONF_PATH;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.buildProdCommand = void 0;
|
|
4
|
-
const fs = require("fs");
|
|
4
|
+
const fs = require("fs-extra");
|
|
5
5
|
const build_copy_command_1 = require("./build-copy.command");
|
|
6
6
|
const tsc_prod_command_1 = require("./tsc-prod.command");
|
|
7
7
|
async function buildProdCommand() {
|
|
8
|
-
fs.
|
|
8
|
+
fs.emptyDirSync('./dist'); // it doesn't delete the dir itself, to prevent IDE jumping
|
|
9
|
+
// fs.rmSync('./dist', { recursive: true, force: true })
|
|
9
10
|
(0, build_copy_command_1.buildCopyCommand)();
|
|
10
11
|
await (0, tsc_prod_command_1.tscProdCommand)();
|
|
11
12
|
}
|
package/dist/util/jest.util.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
export declare function getJestConfigPath(): string
|
|
2
|
-
export declare function getJestIntegrationConfigPath(): string
|
|
3
|
-
export declare function getJestManualConfigPath(): string
|
|
1
|
+
export declare function getJestConfigPath(): string;
|
|
2
|
+
export declare function getJestIntegrationConfigPath(): string;
|
|
3
|
+
export declare function getJestManualConfigPath(): string;
|
|
4
4
|
/**
|
|
5
5
|
* Detects if jest is run with all tests, or with specific tests.
|
|
6
6
|
*/
|
|
7
7
|
export declare function isRunningAllTests(): boolean;
|
|
8
8
|
interface RunJestOpt {
|
|
9
|
-
ci?: boolean;
|
|
10
9
|
integration?: boolean;
|
|
11
10
|
manual?: boolean;
|
|
12
11
|
leaks?: boolean;
|
package/dist/util/jest.util.js
CHANGED
|
@@ -8,7 +8,7 @@ const exec_1 = require("@naturalcycles/nodejs-lib/dist/exec");
|
|
|
8
8
|
const paths_cnst_1 = require("../cnst/paths.cnst");
|
|
9
9
|
const test_util_1 = require("./test.util");
|
|
10
10
|
function getJestConfigPath() {
|
|
11
|
-
return fs.existsSync(`./jest.config.js`) ?
|
|
11
|
+
return fs.existsSync(`./jest.config.js`) ? './jest.config.js' : `${paths_cnst_1.cfgDir}/jest.config.js`;
|
|
12
12
|
}
|
|
13
13
|
exports.getJestConfigPath = getJestConfigPath;
|
|
14
14
|
function getJestIntegrationConfigPath() {
|
|
@@ -41,16 +41,9 @@ async function runJest(opt = {}) {
|
|
|
41
41
|
console.log((0, colors_1.dimGrey)(`node_modules/${(0, colors_1.white)('jest')} not found, skipping tests`));
|
|
42
42
|
return;
|
|
43
43
|
}
|
|
44
|
-
const {
|
|
44
|
+
const { CI, TZ = 'UTC', APP_ENV, JEST_NO_ALPHABETIC, NODE_OPTIONS } = process.env;
|
|
45
|
+
const { integration, manual, leaks } = opt;
|
|
45
46
|
const processArgs = process.argv.slice(2);
|
|
46
|
-
// console.log(processArgs) // todo: solve to run it in dev-lib
|
|
47
|
-
// Allow to override --maxWorkers
|
|
48
|
-
let maxWorkers = processArgs.find(a => a.startsWith('--maxWorkers'));
|
|
49
|
-
const args = ['--logHeapUsage', '--passWithNoTests', ...processArgs];
|
|
50
|
-
const env = {
|
|
51
|
-
TZ: process.env.TZ || 'UTC',
|
|
52
|
-
DEBUG_COLORS: '1',
|
|
53
|
-
};
|
|
54
47
|
let jestConfig;
|
|
55
48
|
if (manual) {
|
|
56
49
|
jestConfig = getJestManualConfigPath();
|
|
@@ -61,20 +54,29 @@ async function runJest(opt = {}) {
|
|
|
61
54
|
else {
|
|
62
55
|
jestConfig = getJestConfigPath();
|
|
63
56
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
57
|
+
// Allow to override --maxWorkers
|
|
58
|
+
let maxWorkers = processArgs.find(a => a.startsWith('--maxWorkers'));
|
|
59
|
+
const args = [
|
|
60
|
+
`--config=${jestConfig}`,
|
|
61
|
+
'--logHeapUsage',
|
|
62
|
+
'--passWithNoTests',
|
|
63
|
+
...processArgs,
|
|
64
|
+
];
|
|
65
|
+
const env = {
|
|
66
|
+
TZ,
|
|
67
|
+
DEBUG_COLORS: '1',
|
|
68
|
+
};
|
|
69
|
+
if (CI) {
|
|
68
70
|
args.push('--ci', '--coverage');
|
|
69
|
-
maxWorkers
|
|
71
|
+
maxWorkers || (maxWorkers = '--maxWorkers=2');
|
|
70
72
|
}
|
|
71
73
|
// Running all tests - will use `--silent` to suppress console-logs, will also set process.env.JEST_SILENT=1
|
|
72
|
-
if (
|
|
74
|
+
if (CI || isRunningAllTests()) {
|
|
73
75
|
args.push('--silent');
|
|
74
76
|
}
|
|
75
77
|
if (leaks) {
|
|
76
78
|
args.push('--detectOpenHandles', '--detectLeaks');
|
|
77
|
-
maxWorkers
|
|
79
|
+
maxWorkers || (maxWorkers = '--maxWorkers=1');
|
|
78
80
|
}
|
|
79
81
|
if (maxWorkers)
|
|
80
82
|
args.push(maxWorkers);
|
|
@@ -83,15 +85,14 @@ async function runJest(opt = {}) {
|
|
|
83
85
|
JEST_SILENT: '1',
|
|
84
86
|
});
|
|
85
87
|
}
|
|
86
|
-
if (!integration && !manual && !
|
|
88
|
+
if (!integration && !manual && !APP_ENV) {
|
|
87
89
|
Object.assign(env, {
|
|
88
90
|
APP_ENV: 'test',
|
|
89
91
|
});
|
|
90
92
|
}
|
|
91
|
-
if (!
|
|
93
|
+
if (!JEST_NO_ALPHABETIC) {
|
|
92
94
|
args.push(`--testSequencer=${paths_cnst_1.cfgDir}/jest.alphabetic.sequencer.js`);
|
|
93
95
|
}
|
|
94
|
-
const { NODE_OPTIONS } = process.env;
|
|
95
96
|
if (NODE_OPTIONS) {
|
|
96
97
|
console.log(`${(0, colors_1.dimGrey)('NODE_OPTIONS: ' + NODE_OPTIONS)}`);
|
|
97
98
|
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/dev-lib",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.14.0",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"prepare": "husky install",
|
|
6
6
|
"tsn-debug": "tsn testScript.ts",
|
|
7
7
|
"bt": "tsn ./src/bin/bt.ts",
|
|
8
|
+
"btl": "tsn ./src/bin/btl.ts",
|
|
8
9
|
"build": "tsn ./src/bin/build.ts",
|
|
9
10
|
"tsc-prod": "tsn ./src/bin/tsc-prod.ts",
|
|
10
11
|
"tsc-scripts": "tsn ./src/bin/tsc-scripts.ts",
|
|
@@ -77,6 +78,7 @@
|
|
|
77
78
|
"types": "dist/index.d.ts",
|
|
78
79
|
"bin": {
|
|
79
80
|
"bt": "dist/bin/bt.js",
|
|
81
|
+
"btl": "dist/bin/btl.js",
|
|
80
82
|
"build": "dist/bin/build.js",
|
|
81
83
|
"build-copy": "dist/bin/build-copy.js",
|
|
82
84
|
"build-prod": "dist/bin/build-prod.js",
|
package/readme.md
CHANGED
|
@@ -67,6 +67,7 @@ These commands are available to be called as `yarn <command>`, because they are
|
|
|
67
67
|
- `build`: "Development build". Checks that "everything compiles". Does
|
|
68
68
|
`del ./dist && tsc && tsc-scripts`
|
|
69
69
|
- `bt`: "Build & Test". Does `del ./dist && tsc && tsc-scripts && test`
|
|
70
|
+
- `btl`: "Build, Test & Lint". Does `lint-all && tsc && test`
|
|
70
71
|
|
|
71
72
|
- `build-copy`: copies _additional files_ into `dist` folder (e.g `*.json`)
|
|
72
73
|
- `build-prod`: "Production build". Does `del ./dist && build-copy && tsc-prod`
|
|
@@ -96,11 +97,10 @@ All test commands set `TZ=UTC`. You can override it by providing `TZ` env variab
|
|
|
96
97
|
running a test command. Adds `APP_ENV=test` env var (for all runs except integration). Automatically
|
|
97
98
|
adds `--silent` (and `JEST_SILENT` env var) if all tests are run.
|
|
98
99
|
|
|
99
|
-
- `test`: runs unit tests (all tests _except_ `*.integration.test.ts` and `*.manual.test.ts`)
|
|
100
|
-
|
|
101
|
-
issue"
|
|
100
|
+
- `test`: runs unit tests (all tests _except_ `*.integration.test.ts` and `*.manual.test.ts`).
|
|
101
|
+
Detects `CI` env variable, adds `--coverage` if in CI. Uses `default` reporter in `!CI`, otherwise
|
|
102
|
+
`jest-junit` reporter. Includes fix for "CircleCI out of memory issue"
|
|
102
103
|
- `test-integration`: runs `*.integration.test.ts` with `jest.integration-test.config.js` config.
|
|
103
|
-
- `test-integration-ci`
|
|
104
104
|
- `test-manual`: runs `*.manual.test.ts` with `jest.manual-test.config.js`.
|
|
105
105
|
- `test-leaks`: runs Jest with `--logHeapUsage --detectOpenHandles --detectLeaks` (requires `weak`
|
|
106
106
|
module to be installed in target project).
|