Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

poku

Package Overview
Dependencies
Maintainers
0
Versions
83
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

poku - npm Package Compare versions

Comparing version 1.17.1 to 1.18.0

15

lib/bin/index.js

@@ -13,3 +13,7 @@ #! /usr/bin/env node

};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const node_process_1 = __importDefault(require("process"));
const list_files_js_1 = require("../modules/list-files.js");

@@ -104,4 +108,5 @@ const get_arg_js_1 = require("../helpers/get-arg.js");

};
node_process_1.default.removeListener('SIGINT', poku_js_1.onSigint);
resultsClear();
(0, map_tests_js_1.mapTests)('.', dirs).then((mappedTests) => [
(0, map_tests_js_1.mapTests)('.', dirs, options.filter, options.exclude).then((mappedTests) => {
Array.from(mappedTests.keys()).forEach((mappedTest) => {

@@ -118,3 +123,3 @@ (0, watch_js_1.watch)(mappedTest, (file, event) => {

return;
(0, poku_js_1.poku)(tests, options).then(() => {
(0, poku_js_1.poku)(Array.from(tests), options).then(() => {
setTimeout(() => {

@@ -126,4 +131,4 @@ executing.delete(filePath);

});
}),
]);
});
});
dirs.forEach((dir) => {

@@ -145,5 +150,5 @@ (0, watch_js_1.watch)(dir, (file, event) => {

(0, hr_js_1.hr)();
(0, logs_js_1.write)(`Watching: ${dirs.join(', ')}`);
(0, logs_js_1.write)(`${format_js_1.format.bold('Watching:')} ${format_js_1.format.underline(dirs.join(', '))}`);
}
}))();
/* c8 ignore stop */

@@ -5,3 +5,3 @@ import type { Configs } from '../@types/list-files.js';

export declare const escapeRegExp: (string: string) => string;
export declare const getAllFiles: (dirPath: string, files?: string[], configs?: Configs) => Promise<string[]>;
export declare const getAllFiles: (dirPath: string, files?: Set<string>, configs?: Configs) => Promise<Set<string>>;
export declare const listFiles: (targetDir: string, configs?: Configs) => Promise<string[]>;

@@ -45,3 +45,3 @@ "use strict";

/* c8 ignore stop */
const getAllFiles = (dirPath_1, ...args_1) => __awaiter(void 0, [dirPath_1, ...args_1], void 0, function* (dirPath, files = [], configs) {
const getAllFiles = (dirPath_1, ...args_1) => __awaiter(void 0, [dirPath_1, ...args_1], void 0, function* (dirPath, files = new Set(), configs) {
const currentFiles = yield (0, fs_js_1.readdir)((0, exports.sanitizePath)(dirPath));

@@ -77,3 +77,3 @@ const defaultRegExp = /\.(test|spec)\./i;

if (filter.test(fullPath))
return files.push(fullPath);
return files.add(fullPath);
if (stat.isDirectory())

@@ -86,4 +86,4 @@ yield (0, exports.getAllFiles)(fullPath, files, configs);

/* c8 ignore start */
const listFiles = (targetDir, configs) => __awaiter(void 0, void 0, void 0, function* () { return yield (0, exports.getAllFiles)((0, exports.sanitizePath)(targetDir), [], configs); });
const listFiles = (targetDir, configs) => __awaiter(void 0, void 0, void 0, function* () { return Array.from(yield (0, exports.getAllFiles)((0, exports.sanitizePath)(targetDir), new Set(), configs)); });
exports.listFiles = listFiles;
/* c8 ignore stop */
import type { Code } from '../@types/code.js';
import type { Configs } from '../@types/poku.js';
export declare const onSigint: () => void;
export declare function poku(targetPaths: string | string[], configs: Configs & {

@@ -4,0 +5,0 @@ noExit: true;

@@ -16,3 +16,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.poku = void 0;
exports.poku = exports.onSigint = void 0;
/**

@@ -30,5 +30,7 @@ * Both CLI, API, noExit, sequential and parallel runs are strictly tested, but these tests use deep child process for it

const indentation_js_1 = require("../configs/indentation.js");
node_process_1.default.once('SIGINT', () => {
const onSigint = () => {
node_process_1.default.stdout.write('\u001B[?25h');
});
};
exports.onSigint = onSigint;
node_process_1.default.once('SIGINT', exports.onSigint);
function poku(targetPaths, configs) {

@@ -35,0 +37,0 @@ return __awaiter(this, void 0, void 0, function* () {

export declare const normalizePath: (filePath: string) => string;
export declare const mapTests: (srcDir: string, testPaths: string[]) => Promise<Map<string, string[]>>;
export declare const getDeepImports: (content: string) => Set<string>;
export declare const findMatchingFiles: (srcFilesWithoutExt: Set<string>, srcFilesWithExt: Set<string>) => Set<string>;
export declare const mapTests: (srcDir: string, testPaths: string[], testFilter?: RegExp, exclude?: RegExp | RegExp[]) => Promise<Map<string, Set<string>>>;

@@ -12,3 +12,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.mapTests = exports.normalizePath = void 0;
exports.mapTests = exports.findMatchingFiles = exports.getDeepImports = exports.normalizePath = void 0;
/* c8 ignore next */

@@ -18,3 +18,5 @@ const node_path_1 = require("path");

const list_files_js_1 = require("../modules/list-files.js");
const filter = /\.(js|cjs|mjs|ts|cts|mts)$/;
const importMap = new Map();
const processedFiles = new Set();
const extFilter = /\.(js|cjs|mjs|ts|cts|mts|jsx|tsx)$/;
const normalizePath = (filePath) => filePath

@@ -26,33 +28,95 @@ .replace(/(\.\/)/g, '')

exports.normalizePath = normalizePath;
/* c8 ignore next */
const mapTests = (srcDir, testPaths) => __awaiter(void 0, void 0, void 0, function* () {
const allTestFiles = [];
const allSrcFiles = yield (0, list_files_js_1.listFiles)(srcDir, { filter });
const importMap = new Map();
for (const testPath of testPaths) {
const stats = yield (0, fs_js_1.stat)(testPath);
if (stats.isDirectory()) {
const testFiles = yield (0, list_files_js_1.listFiles)(testPath, { filter });
allTestFiles.push(...testFiles);
const getDeepImports = (content) => {
const paths = new Set();
const lines = content.split('\n');
for (const line of lines) {
if (line.includes('import') || line.includes('require')) {
const path = line.match(/['"](\.{1,2}\/[^'"]+)['"]/);
if (path)
paths.add((0, exports.normalizePath)(path[1].replace(extFilter, '')));
}
else if (stats.isFile() && filter.test(testPath))
allTestFiles.push(testPath);
}
for (const testFile of allTestFiles) {
return paths;
};
exports.getDeepImports = getDeepImports;
const findMatchingFiles = (srcFilesWithoutExt, srcFilesWithExt) => {
const matchingFiles = new Set();
srcFilesWithoutExt.forEach((srcFile) => {
const normalizedSrcFile = (0, exports.normalizePath)(srcFile);
srcFilesWithExt.forEach((fileWithExt) => {
const normalizedFileWithExt = (0, exports.normalizePath)(fileWithExt);
if (normalizedFileWithExt.includes(normalizedSrcFile))
matchingFiles.add(fileWithExt);
});
});
return matchingFiles;
};
exports.findMatchingFiles = findMatchingFiles;
/* c8 ignore start */
const collectTestFiles = (testPaths, testFilter, exclude) => __awaiter(void 0, void 0, void 0, function* () {
const statsPromises = testPaths.map((testPath) => (0, fs_js_1.stat)(testPath));
const stats = yield Promise.all(statsPromises);
const listFilesPromises = stats.map((stat, index) => {
const testPath = testPaths[index];
if (stat.isDirectory())
return (0, list_files_js_1.listFiles)(testPath, {
filter: testFilter,
exclude,
});
if (stat.isFile() && extFilter.test(testPath))
return [testPath];
else
return [];
});
const nestedTestFiles = yield Promise.all(listFilesPromises);
return new Set(nestedTestFiles.flat());
});
/* c8 ignore stop */
/* c8 ignore start */
const processDeepImports = (srcFile, testFile, intersectedSrcFiles) => __awaiter(void 0, void 0, void 0, function* () {
if (processedFiles.has(srcFile))
return;
processedFiles.add(srcFile);
const srcContent = yield (0, fs_js_1.readFile)(srcFile, 'utf-8');
const deepImports = (0, exports.getDeepImports)(srcContent);
const matchingFiles = (0, exports.findMatchingFiles)(deepImports, intersectedSrcFiles);
for (const deepImport of matchingFiles) {
if (!importMap.has(deepImport))
importMap.set(deepImport, new Set());
importMap.get(deepImport).add((0, exports.normalizePath)(testFile));
yield processDeepImports(deepImport, testFile, intersectedSrcFiles);
}
});
/* c8 ignore stop */
const createImportMap = (allTestFiles, allSrcFiles) => __awaiter(void 0, void 0, void 0, function* () {
const intersectedSrcFiles = new Set(Array.from(allSrcFiles).filter((srcFile) => !allTestFiles.has(srcFile)));
yield Promise.all(Array.from(allTestFiles).map((testFile) => __awaiter(void 0, void 0, void 0, function* () {
const content = yield (0, fs_js_1.readFile)(testFile, 'utf-8');
for (const srcFile of allSrcFiles) {
for (const srcFile of intersectedSrcFiles) {
const relativePath = (0, exports.normalizePath)((0, node_path_1.relative)((0, node_path_1.dirname)(testFile), srcFile));
const normalizedSrcFile = (0, exports.normalizePath)(srcFile);
/* c8 ignore start */
if (content.includes(relativePath.replace(filter, '')) ||
if (content.includes(relativePath.replace(extFilter, '')) ||
content.includes(normalizedSrcFile)) {
if (!importMap.has(normalizedSrcFile))
importMap.set(normalizedSrcFile, []);
importMap.get(normalizedSrcFile).push((0, exports.normalizePath)(testFile));
importMap.set(normalizedSrcFile, new Set());
importMap.get(normalizedSrcFile).add((0, exports.normalizePath)(testFile));
yield processDeepImports(srcFile, testFile, intersectedSrcFiles);
}
/* c8 ignore stop */
}
}
})));
});
/* c8 ignore next */
const mapTests = (srcDir, testPaths, testFilter, exclude) => __awaiter(void 0, void 0, void 0, function* () {
const [allTestFiles, allSrcFiles] = yield Promise.all([
collectTestFiles(testPaths, testFilter, exclude),
(0, list_files_js_1.listFiles)(srcDir, {
filter: extFilter,
exclude,
}),
]);
yield createImportMap(allTestFiles, new Set(allSrcFiles));
return importMap;
});
exports.mapTests = mapTests;

@@ -54,2 +54,3 @@ "use strict";

return __awaiter(this, void 0, void 0, function* () {
/* c8 ignore next */
if (this.dirWatchers.has(dir))

@@ -100,5 +101,3 @@ return;

}
catch (err) {
throw new Error(`Path does not exist or is not accessible: ${this.rootDir}`);
}
catch (_a) { }
/* c8 ignore stop */

@@ -105,0 +104,0 @@ });

{
"name": "poku",
"version": "1.17.1",
"version": "1.18.0",
"description": "🐷 Poku makes testing easy for Node.js, Bun, Deno and you at the same time.",

@@ -127,5 +127,5 @@ "main": "./lib/index.js",

"devDependencies": {
"@types/node": "^20.14.2",
"@typescript-eslint/eslint-plugin": "^7.13.0",
"@typescript-eslint/parser": "^7.13.0",
"@types/node": "^20.14.6",
"@typescript-eslint/eslint-plugin": "^7.13.1",
"@typescript-eslint/parser": "^7.13.1",
"c8": "^10.1.2",

@@ -132,0 +132,0 @@ "esbuild": "^0.21.5",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc