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

@betterer/betterer

Package Overview
Dependencies
Maintainers
1
Versions
77
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@betterer/betterer - npm Package Compare versions

Comparing version 0.5.1 to 0.5.2

dist/files/file-betterer.d.ts

3

dist/betterer/betterer.d.ts

@@ -21,5 +21,4 @@ import { BettererGoal, BettererGoalFunction, BettererTest, BettererConstraint, BettererDiff } from './types';

constructor({ test, constraint, goal, diff, isOnly, isSkipped }: BettererOptions<Base, Serialised>);
only(): Betterer<Base, Serialised>;
skip(): Betterer<Base, Serialised>;
only(): Betterer<Base, Serialised>;
private _createGoal;
}

@@ -11,11 +11,7 @@ "use strict";

this.diff = diff;
this.goal = this._createGoal(goal);
this.goal = createGoal(goal);
this.test = test;
this.isOnly = isOnly;
this.isSkipped = isSkipped;
this.isOnly = isOnly;
}
Betterer.prototype.skip = function () {
this.isSkipped = true;
return this;
};
Betterer.prototype.only = function () {

@@ -25,7 +21,5 @@ this.isOnly = true;

};
Betterer.prototype._createGoal = function (goal) {
if (typeof goal === 'function') {
return goal;
}
return function (value) { return value === goal; };
Betterer.prototype.skip = function () {
this.isSkipped = true;
return this;
};

@@ -35,2 +29,8 @@ return Betterer;

exports.Betterer = Betterer;
function createGoal(goal) {
if (typeof goal === 'function') {
return goal;
}
return function (value) { return value === goal; };
}
function defaultDiff(_, serialisedCurrent, serialisedPrevious) {

@@ -37,0 +37,0 @@ var diffStr = logDiff(serialisedPrevious, serialisedCurrent, {

@@ -1,10 +0,4 @@

import { ConstraintResult } from '@betterer/constraints';
import { Betterer } from '../betterer';
import { MaybeAsync } from '../types';
import { BettererFile } from './file';
import { BettererFileMarksMap, BettererFileInfo } from './types';
export declare type FileBetterer = Betterer<BettererFile, BettererFileMarksMap>;
import { FileBetterer } from './file-betterer';
import { BettererFileInfo } from './types';
export declare function createFileBetterer(test: () => MaybeAsync<Array<BettererFileInfo>>): FileBetterer;
export declare function constraint(serialisedCurrent: BettererFileMarksMap, serialisedPrevious: BettererFileMarksMap): ConstraintResult;
export declare function goal(value: BettererFileMarksMap): boolean;
export declare function diff(current: BettererFile, serialisedCurrent: BettererFileMarksMap, serialisedPrevious: BettererFileMarksMap | null): void;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var logger_1 = require("@betterer/logger");
var betterer_1 = require("../betterer");
var file_1 = require("./file");
var file_betterer_1 = require("./file-betterer");
function createFileBetterer(test) {
var _this = this;
return betterer_1.createBetterer({
test: function (config) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
var _a, _b, _c;
return tslib_1.__generator(this, function (_d) {
switch (_d.label) {
case 0:
_b = (_a = file_1.BettererFile).fromInfo;
_c = [config];
return [4 /*yield*/, test()];
case 1: return [2 /*return*/, _b.apply(_a, _c.concat([_d.sent()]))];
}
});
}); },
constraint: constraint,
goal: goal,
diff: diff
});
return new file_betterer_1.FileBetterer(test);
}
exports.createFileBetterer = createFileBetterer;
function constraint(serialisedCurrent, serialisedPrevious) {
var deserialisedCurrent = file_1.BettererFile.fromSerialised(serialisedCurrent);
var deserialisedPrevious = file_1.BettererFile.fromSerialised(serialisedPrevious);
var currentFiles = deserialisedCurrent.getFilePaths();
var previousFiles = deserialisedPrevious.getFilePaths();
var newOrMovedUnchangedFiles = currentFiles.filter(function (file) {
return !previousFiles.includes(file);
});
var movedUnchangedFiles = newOrMovedUnchangedFiles.filter(function (file) {
var fileHash = deserialisedCurrent.getHash(file);
return deserialisedPrevious.hasHash(fileHash);
});
var newFiles = newOrMovedUnchangedFiles.filter(function (file) {
return !movedUnchangedFiles.includes(file);
});
var existingFiles = currentFiles.filter(function (file) {
return !newOrMovedUnchangedFiles.includes(file);
});
// If there are any new files, then it's worse:
if (newFiles.length > 0) {
return "worse" /* worse */;
}
var filesWithMore = existingFiles.filter(function (filePath) {
var currentMarks = deserialisedCurrent.getFileMarks(filePath);
var previousMarks = deserialisedPrevious.getFileMarks(filePath);
return currentMarks.length > previousMarks.length;
});
// If any file has new entries, then it's worse:
if (filesWithMore.length > 0) {
return "worse" /* worse */;
}
var filesWithSame = existingFiles.filter(function (filePath) {
var currentMarks = deserialisedCurrent.getFileMarks(filePath);
var previousMarks = deserialisedPrevious.getFileMarks(filePath);
return currentMarks.length === previousMarks.length;
});
// If all the files have the same number of entries as before, then it's the same:
var unchangedFiles = tslib_1.__spreadArrays(filesWithSame, movedUnchangedFiles);
if (unchangedFiles.length === previousFiles.length) {
return "same" /* same */;
}
// If all the files have the same number of entries as before or fewer, then it's better!
return "better" /* better */;
}
exports.constraint = constraint;
function goal(value) {
return Object.keys(value).length === 0;
}
exports.goal = goal;
function diff(current, serialisedCurrent, serialisedPrevious) {
var deserialisedCurrent = file_1.BettererFile.fromSerialised(serialisedCurrent);
var deserialisedPrevious = file_1.BettererFile.fromSerialised(serialisedPrevious);
var filePaths = current.getFilePaths();
if (serialisedPrevious === null) {
filePaths.forEach(function (filePath) {
var fileInfo = current.getFileInfo(filePath);
var length = fileInfo.length;
logger_1.error(length + " new " + getIssues(length) + " in \"" + filePath + "\":");
fileInfo.forEach(function (info) { return logger_1.code(info); });
});
return;
}
var filesWithChanges = filePaths.filter(function (filePath) {
var currentMarks = deserialisedCurrent.getFileMarks(filePath);
var previousMarks = deserialisedPrevious.getFileMarks(filePath);
if (!currentMarks ||
!previousMarks ||
currentMarks.length !== previousMarks.length) {
return true;
}
return currentMarks.some(function (_a, index) {
var cLine = _a[0], cColumn = _a[1], cLength = _a[2];
var _b = previousMarks[index], pLine = _b[0], pColumn = _b[1], pLength = _b[2];
return pLine !== cLine || pColumn !== cColumn || pLength !== cLength;
});
});
filesWithChanges.forEach(function (filePath) {
var currentMarks = deserialisedCurrent.getFileMarks(filePath);
var previousMarks = deserialisedPrevious.getFileMarks(filePath);
var fileInfo = current.getFileInfo(filePath);
var changed = fileInfo.filter(function (_, index) {
var _a = currentMarks[index], cLine = _a[0], cColumn = _a[1], cLength = _a[2];
return (!previousMarks ||
!previousMarks.find(function (_a) {
var pLine = _a[0], pColumn = _a[1], pLength = _a[2];
return pLine === cLine && pColumn === cColumn && pLength === cLength;
}));
});
var length = changed.length;
logger_1.error(length + " new " + getIssues(length) + " in \"" + filePath + "\":");
changed.forEach(function (info) { return logger_1.code(info); });
});
return;
}
exports.diff = diff;
function getIssues(count) {
return count === 1 ? 'issue' : 'issues';
}
//# sourceMappingURL=create-file-betterer.js.map

@@ -6,2 +6,3 @@ import { BettererConfig } from '../config';

export declare class BettererFile implements Serialisable<BettererFileMarksMap>, Printable {
private _excluded;
private _fileInfoMap;

@@ -13,2 +14,3 @@ private _fileHashMap;

static fromSerialised(serialised: BettererFileMarksMap | null): BettererFile;
exclude(excluded: Array<RegExp>): void;
getFilePaths(): Array<string>;

@@ -15,0 +17,0 @@ getFileInfo(filePath: string): Array<BettererFileInfo>;

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

function BettererFile() {
this._excluded = [];
this._fileInfoMap = null;

@@ -53,2 +54,5 @@ this._fileHashMap = {};

};
BettererFile.prototype.exclude = function (excluded) {
this._excluded = excluded;
};
BettererFile.prototype.getFilePaths = function () {

@@ -77,2 +81,3 @@ return Object.keys(this._fileHashMap);

.filter(function (filePath) { return !!_this._fileMarkMap[filePath]; })
.filter(function (filePath) { return !_this._excluded.some(function (exclude) { return exclude.test(filePath); }); })
.map(function (filePath) {

@@ -79,0 +84,0 @@ var marks = _this._fileMarkMap[filePath];

export * from './create-file-betterer';
export * from './file-betterer';
export * from './file';
export * from './types';

@@ -5,3 +5,4 @@ "use strict";

tslib_1.__exportStar(require("./create-file-betterer"), exports);
tslib_1.__exportStar(require("./file-betterer"), exports);
tslib_1.__exportStar(require("./file"), exports);
//# sourceMappingURL=index.js.map
{
"name": "@betterer/betterer",
"description": "Main engine for runing betterer tests",
"version": "0.5.1",
"version": "0.5.2",
"license": "MIT",

@@ -36,3 +36,3 @@ "publishConfig": {

},
"gitHead": "e979203f3ceafc88eee497e83a3ecd7625051e4d"
"gitHead": "97ee5008070d4b8d4d52343b76addaed775802da"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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