@knapsack-pro/jest 7.4.0 → 8.0.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.
package/lib/env-config.js CHANGED
@@ -1,10 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.EnvConfig = void 0;
4
- var EnvConfig = (function () {
5
- function EnvConfig() {
6
- }
7
- EnvConfig.loadEnvironmentVariables = function () {
4
+ class EnvConfig {
5
+ static loadEnvironmentVariables() {
8
6
  if (process.env.KNAPSACK_PRO_TEST_SUITE_TOKEN_JEST) {
9
7
  process.env.KNAPSACK_PRO_TEST_SUITE_TOKEN =
10
8
  process.env.KNAPSACK_PRO_TEST_SUITE_TOKEN_JEST;
@@ -12,31 +10,18 @@ var EnvConfig = (function () {
12
10
  if (process.env.NODE_ENV == null) {
13
11
  process.env.NODE_ENV = 'test';
14
12
  }
15
- };
16
- Object.defineProperty(EnvConfig, "testFilePattern", {
17
- get: function () {
18
- if (process.env.KNAPSACK_PRO_TEST_FILE_PATTERN) {
19
- return process.env.KNAPSACK_PRO_TEST_FILE_PATTERN;
20
- }
21
- return '{**/__tests__/**/*.js?(x),**/?(*.)(spec|test).js?(x)}';
22
- },
23
- enumerable: false,
24
- configurable: true
25
- });
26
- Object.defineProperty(EnvConfig, "testFileExcludePattern", {
27
- get: function () {
28
- return process.env.KNAPSACK_PRO_TEST_FILE_EXCLUDE_PATTERN;
29
- },
30
- enumerable: false,
31
- configurable: true
32
- });
33
- Object.defineProperty(EnvConfig, "coverageDirectory", {
34
- get: function () {
35
- return process.env.KNAPSACK_PRO_COVERAGE_DIRECTORY;
36
- },
37
- enumerable: false,
38
- configurable: true
39
- });
40
- return EnvConfig;
41
- }());
13
+ }
14
+ static get testFilePattern() {
15
+ if (process.env.KNAPSACK_PRO_TEST_FILE_PATTERN) {
16
+ return process.env.KNAPSACK_PRO_TEST_FILE_PATTERN;
17
+ }
18
+ return '{**/__tests__/**/*.js?(x),**/?(*.)(spec|test).js?(x)}';
19
+ }
20
+ static get testFileExcludePattern() {
21
+ return process.env.KNAPSACK_PRO_TEST_FILE_EXCLUDE_PATTERN;
22
+ }
23
+ static get coverageDirectory() {
24
+ return process.env.KNAPSACK_PRO_COVERAGE_DIRECTORY;
25
+ }
26
+ }
42
27
  exports.EnvConfig = EnvConfig;
package/lib/jest-cli.js CHANGED
@@ -1,14 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.JestCLI = void 0;
4
- var minimist = require('minimist');
5
- var JestCLI = (function () {
6
- function JestCLI() {
7
- }
8
- JestCLI.argvToOptions = function () {
9
- var argv = process.argv.slice(2);
4
+ const minimist = require('minimist');
5
+ class JestCLI {
6
+ static argvToOptions() {
7
+ const argv = process.argv.slice(2);
10
8
  return minimist(argv);
11
- };
12
- return JestCLI;
13
- }());
9
+ }
10
+ }
14
11
  exports.JestCLI = JestCLI;
@@ -1,99 +1,46 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
- var __assign = (this && this.__assign) || function () {
4
- __assign = Object.assign || function(t) {
5
- for (var s, i = 1, n = arguments.length; i < n; i++) {
6
- s = arguments[i];
7
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
8
- t[p] = s[p];
9
- }
10
- return t;
11
- };
12
- return __assign.apply(this, arguments);
13
- };
14
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
15
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16
- return new (P || (P = Promise))(function (resolve, reject) {
17
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
18
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
19
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
20
- step((generator = generator.apply(thisArg, _arguments || [])).next());
21
- });
22
- };
23
- var __generator = (this && this.__generator) || function (thisArg, body) {
24
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
25
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
26
- function verb(n) { return function (v) { return step([n, v]); }; }
27
- function step(op) {
28
- if (f) throw new TypeError("Generator is already executing.");
29
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
30
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
31
- if (y = 0, t) op = [op[0] & 2, t.value];
32
- switch (op[0]) {
33
- case 0: case 1: t = op; break;
34
- case 4: _.label++; return { value: op[1], done: false };
35
- case 5: _.label++; y = op[1]; op = [0]; continue;
36
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
37
- default:
38
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
39
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
40
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
41
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
42
- if (t[2]) _.ops.pop();
43
- _.trys.pop(); continue;
44
- }
45
- op = body.call(thisArg, _);
46
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
47
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
48
- }
49
- };
50
3
  Object.defineProperty(exports, "__esModule", { value: true });
51
- var core_1 = require("@knapsack-pro/core");
52
- var env_config_1 = require("./env-config");
53
- var test_files_finder_1 = require("./test-files-finder");
54
- var jest_cli_1 = require("./jest-cli");
55
- var jest = require('jest');
56
- var uuidv4 = require('uuid').v4;
57
- var _a = require('../package.json'), clientName = _a.name, clientVersion = _a.version;
58
- var jestCLIOptions = jest_cli_1.JestCLI.argvToOptions();
59
- var knapsackProLogger = new core_1.KnapsackProLogger();
60
- knapsackProLogger.debug("Jest CLI options:\n".concat(core_1.KnapsackProLogger.objectInspect(jestCLIOptions)));
4
+ const core_1 = require("@knapsack-pro/core");
5
+ const env_config_1 = require("./env-config");
6
+ const test_files_finder_1 = require("./test-files-finder");
7
+ const jest_cli_1 = require("./jest-cli");
8
+ const jest = require('jest');
9
+ const { v4: uuidv4 } = require('uuid');
10
+ const { name: clientName, version: clientVersion } = require('../package.json');
11
+ const jestCLIOptions = jest_cli_1.JestCLI.argvToOptions();
12
+ const knapsackProLogger = new core_1.KnapsackProLogger();
13
+ knapsackProLogger.debug(`Jest CLI options:\n${core_1.KnapsackProLogger.objectInspect(jestCLIOptions)}`);
61
14
  env_config_1.EnvConfig.loadEnvironmentVariables();
62
- var projectPath = process.cwd();
63
- var testFilesToExecute = function () {
64
- return test_files_finder_1.TestFilesFinder.allTestFiles();
65
- };
66
- var knapsackPro = new core_1.KnapsackProCore(clientName, clientVersion, testFilesToExecute);
67
- var onSuccess = function (queueTestFiles) { return __awaiter(void 0, void 0, void 0, function () {
68
- var testFilePaths, jestCLICoverage, _a, isTestSuiteGreen, testResults, recordedTestFiles;
69
- return __generator(this, function (_b) {
70
- switch (_b.label) {
71
- case 0:
72
- testFilePaths = queueTestFiles.map(function (testFile) { return testFile.path; });
73
- jestCLICoverage = env_config_1.EnvConfig.coverageDirectory
74
- ? { coverageDirectory: "".concat(env_config_1.EnvConfig.coverageDirectory, "/").concat(uuidv4()) }
75
- : {};
76
- return [4, jest.runCLI(__assign(__assign(__assign({}, jestCLIOptions), jestCLICoverage), { runTestsByPath: true, _: testFilePaths }), [projectPath])];
77
- case 1:
78
- _a = (_b.sent()).results, isTestSuiteGreen = _a.success, testResults = _a.testResults;
79
- recordedTestFiles = testResults.map(function (_a) {
80
- var testFilePath = _a.testFilePath, _b = _a.perfStats, start = _b.start, end = _b.end;
81
- var path = process.platform === 'win32'
82
- ? testFilePath.replace("".concat(projectPath, "\\"), '').replace(/\\/g, '/')
83
- : testFilePath.replace("".concat(projectPath, "/"), '');
84
- var timeExecutionMiliseconds = end - start;
85
- var timeExecution = timeExecutionMiliseconds > 0 ? timeExecutionMiliseconds / 1000 : 0.0;
86
- return {
87
- path: path,
88
- time_execution: timeExecution,
89
- };
90
- });
91
- return [2, {
92
- recordedTestFiles: recordedTestFiles,
93
- isTestSuiteGreen: isTestSuiteGreen,
94
- }];
95
- }
15
+ const projectPath = process.cwd();
16
+ const testFilesToExecute = () => test_files_finder_1.TestFilesFinder.allTestFiles();
17
+ const knapsackPro = new core_1.KnapsackProCore(clientName, clientVersion, testFilesToExecute);
18
+ const onSuccess = async (queueTestFiles) => {
19
+ const testFilePaths = queueTestFiles.map((testFile) => testFile.path);
20
+ const jestCLICoverage = env_config_1.EnvConfig.coverageDirectory
21
+ ? { coverageDirectory: `${env_config_1.EnvConfig.coverageDirectory}/${uuidv4()}` }
22
+ : {};
23
+ const { results: { success: isTestSuiteGreen, testResults }, } = await jest.runCLI({
24
+ ...jestCLIOptions,
25
+ ...jestCLICoverage,
26
+ runTestsByPath: true,
27
+ _: testFilePaths,
28
+ }, [projectPath]);
29
+ const recordedTestFiles = testResults.map(({ testFilePath, perfStats: { start, end }, }) => {
30
+ const path = process.platform === 'win32'
31
+ ? testFilePath.replace(`${projectPath}\\`, '').replace(/\\/g, '/')
32
+ : testFilePath.replace(`${projectPath}/`, '');
33
+ const timeExecutionMiliseconds = end - start;
34
+ const timeExecution = timeExecutionMiliseconds > 0 ? timeExecutionMiliseconds / 1000 : 0.0;
35
+ return {
36
+ path,
37
+ time_execution: timeExecution,
38
+ };
96
39
  });
97
- }); };
98
- var onError = function (error) { };
40
+ return {
41
+ recordedTestFiles,
42
+ isTestSuiteGreen,
43
+ };
44
+ };
45
+ const onError = (error) => { };
99
46
  knapsackPro.runQueueMode(onSuccess, onError);
@@ -1,37 +1,55 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
26
  exports.TestFilesFinder = void 0;
4
- var glob = require("glob");
5
- var minimatch = require("minimatch");
6
- var core_1 = require("@knapsack-pro/core");
7
- var env_config_1 = require("./env-config");
8
- var Urls = require("./urls");
9
- var TestFilesFinder = (function () {
10
- function TestFilesFinder() {
11
- }
12
- TestFilesFinder.allTestFiles = function () {
13
- var testFiles = glob
27
+ const glob_1 = require("glob");
28
+ const minimatch_1 = require("minimatch");
29
+ const core_1 = require("@knapsack-pro/core");
30
+ const env_config_1 = require("./env-config");
31
+ const Urls = __importStar(require("./urls"));
32
+ class TestFilesFinder {
33
+ static allTestFiles() {
34
+ const testFiles = glob_1.glob
14
35
  .sync(env_config_1.EnvConfig.testFilePattern)
15
- .filter(function (testFilePath) {
36
+ .filter((testFilePath) => {
16
37
  if (env_config_1.EnvConfig.testFileExcludePattern) {
17
- return !minimatch(testFilePath, env_config_1.EnvConfig.testFileExcludePattern, {
38
+ return !(0, minimatch_1.minimatch)(testFilePath, env_config_1.EnvConfig.testFileExcludePattern, {
18
39
  matchBase: true,
19
40
  });
20
41
  }
21
42
  return true;
22
43
  })
23
- .filter(function (testFilePath) {
24
- return !testFilePath.match(/node_modules/);
25
- })
26
- .map(function (testFilePath) { return ({ path: testFilePath }); });
44
+ .filter((testFilePath) => !testFilePath.match(/node_modules/))
45
+ .map((testFilePath) => ({ path: testFilePath }));
27
46
  if (testFiles.length === 0) {
28
- var knapsackProLogger = new core_1.KnapsackProLogger();
29
- var errorMessage = "Test files cannot be found.\nPlease set KNAPSACK_PRO_TEST_FILE_PATTERN matching your test directory structure.\nLearn more: ".concat(Urls.NO_TESTS_FOUND);
47
+ const knapsackProLogger = new core_1.KnapsackProLogger();
48
+ const errorMessage = `Test files cannot be found.\nPlease set KNAPSACK_PRO_TEST_FILE_PATTERN matching your test directory structure.\nLearn more: ${Urls.NO_TESTS_FOUND}`;
30
49
  knapsackProLogger.error(errorMessage);
31
50
  throw errorMessage;
32
51
  }
33
52
  return testFiles;
34
- };
35
- return TestFilesFinder;
36
- }());
53
+ }
54
+ }
37
55
  exports.TestFilesFinder = TestFilesFinder;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knapsack-pro/jest",
3
- "version": "7.4.0",
3
+ "version": "8.0.1",
4
4
  "description": "Knapsack Pro Jest splits Jest tests across CI nodes and makes sure that tests will run in optimal time on each CI node.",
5
5
  "keywords": [
6
6
  "knapsack",
@@ -29,8 +29,8 @@
29
29
  ],
30
30
  "license": "MIT",
31
31
  "scripts": {
32
- "start": "gulp",
33
- "build": "gulp build",
32
+ "start": "nodemon --ext ts --watch src/ --exec \"npm run build\"",
33
+ "build": "rm -rf lib && tsc && chmod u+x lib/knapsack-pro-jest.js",
34
34
  "lint": "npm run eslint:check && npm run prettier:check",
35
35
  "eslint:check": "eslint . --ext .ts",
36
36
  "eslint:format": "eslint . --ext .ts --fix",
@@ -52,37 +52,29 @@
52
52
  "knapsack-pro-jest": "lib/knapsack-pro-jest.js"
53
53
  },
54
54
  "dependencies": {
55
- "@knapsack-pro/core": "^6.4.0",
56
- "glob": "^8.0.3",
57
- "minimatch": "^5.1.0",
55
+ "@knapsack-pro/core": "^7.0.0",
56
+ "glob": "^10.3.4",
57
+ "minimatch": "^9.0.3",
58
58
  "minimist": "^1.2.6",
59
- "uuid": "^9.0.0"
59
+ "uuid": "^9.0.1"
60
60
  },
61
61
  "peerDependencies": {
62
62
  "jest": ">=22.0.0"
63
63
  },
64
64
  "devDependencies": {
65
- "@babel/core": "^7.22.5",
66
- "@babel/preset-env": "^7.22.10",
67
- "@babel/register": "^7.22.5",
68
- "@types/glob": "^7.2.0",
69
- "@types/jest": "^28.1.1",
70
- "@types/node": "^20.3.1",
71
- "@typescript-eslint/eslint-plugin": "^5.27.1",
72
- "@typescript-eslint/parser": "^5.27.1",
73
- "del": "^6.1.1",
74
- "eslint": "^7.32.0",
65
+ "@types/jest": "^29.5.5",
66
+ "@types/node": "^20.6.2",
67
+ "@typescript-eslint/eslint-plugin": "^6.7.2",
68
+ "@typescript-eslint/parser": "^6.7.2",
69
+ "eslint": "^8.49.0",
75
70
  "eslint-config-airbnb-base": "^15.0.0",
76
- "eslint-config-prettier": "^8.5.0",
77
- "eslint-plugin-import": "^2.26.0",
78
- "eslint-plugin-prettier": "^4.0.0",
79
- "gulp": "^4.0.2",
80
- "gulp-chmod": "^3.0.0",
81
- "gulp-filter": "^7.0.0",
82
- "gulp-typescript": "^5.0.1",
83
- "jest": "^29.4.3",
84
- "prettier": "^2.6.2",
85
- "ts-jest": "^29.0.5",
86
- "typescript": "^4.7.3"
71
+ "eslint-config-prettier": "^9.0.0",
72
+ "eslint-plugin-import": "^2.28.1",
73
+ "eslint-plugin-prettier": "^5.0.0",
74
+ "jest": "^29.7.0",
75
+ "nodemon": "^3.0.1",
76
+ "prettier": "^3.0.3",
77
+ "ts-jest": "^29.1.1",
78
+ "typescript": "^5.2.2"
87
79
  }
88
80
  }