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

after-test

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

after-test - npm Package Compare versions

Comparing version 1.0.7 to 1.0.8

440

lib/base-fixture.js

@@ -36,239 +36,227 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

};
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
import * as assert from 'assert';
import * as fs from 'fs';
import * as path from 'path';
import { promisify } from 'util';
var copyFileP = promisify(fs.copyFile);
var writeFileP = promisify(fs.writeFile);
var readFileP = promisify(fs.readFile);
var fileExistsP = promisify(fs.exists);
var BaseFixture = /** @class */ (function () {
function BaseFixture(currentDir) {
this.currentDir = currentDir;
this.actualDir = path.resolve(this.currentDir + "/actual/");
this.errorDir = path.resolve(this.currentDir + "/error/");
this.expectDir = path.resolve(this.currentDir + "/expect/");
this.srcDir = path.resolve(this.currentDir + "/src/");
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports", "assert", "fs", "path", "util"], factory);
}
})(function (require, exports) {
"use strict";
exports.__esModule = true;
var assert = require("assert");
var fs = require("fs");
var path = require("path");
var util_1 = require("util");
var copyFileP = util_1.promisify(fs.copyFile);
var writeFileP = util_1.promisify(fs.writeFile);
var readFileP = util_1.promisify(fs.readFile);
var fileExistsP = util_1.promisify(fs.exists);
var BaseFixture = /** @class */ (function () {
function BaseFixture(currentDir) {
this.currentDir = currentDir;
this.actualDir = path.resolve(this.currentDir + "/actual/");
this.errorDir = path.resolve(this.currentDir + "/error/");
this.expectDir = path.resolve(this.currentDir + "/expect/");
this.srcDir = path.resolve(this.currentDir + "/src/");
}
BaseFixture.prototype.isString = function (s) {
return Object.prototype.toString.call(s) === '[object String]';
};
BaseFixture.prototype.setCurrentDir = function (currentDir) {
this.currentDir = currentDir;
};
BaseFixture.prototype.writeFile = function (type, content, fileName) {
return __awaiter(this, void 0, void 0, function () {
var Types, filePath;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
Types = ['actual', 'expect', 'error'];
if (!(this.isString(fileName) && this.isString(content))) {
throw new Error('[Aftertest writeFile] Filename/Content must be a string.');
}
if (Types.indexOf(type) < 0) {
throw new Error('[Aftertest writeFile] Type is wrong.');
}
// istanbul ignore next
if (type === 'error') {
fileName = 'index.json';
}
type = type + "Dir";
filePath = this[type] + "/" + fileName;
return [4 /*yield*/, fileExistsP(this[type])];
case 1:
// istanbul ignore next
if (!(_a.sent())) {
fs.mkdirSync(this[type]);
}
return [2 /*return*/, writeFileP(filePath, content, { encoding: 'utf8', flag: 'w+' })];
}
});
BaseFixture.prototype.isString = function (s) {
return Object.prototype.toString.call(s) === '[object String]';
};
BaseFixture.prototype.setCurrentDir = function (currentDir) {
this.currentDir = currentDir;
};
BaseFixture.prototype.writeFile = function (type, content, fileName) {
return __awaiter(this, void 0, void 0, function () {
var Types, filePath;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
Types = ['actual', 'expect', 'error'];
if (!(this.isString(fileName) && this.isString(content))) {
throw new Error('[Aftertest writeFile] Filename/Content must be a string.');
}
if (Types.indexOf(type) < 0) {
throw new Error('[Aftertest writeFile] Type is wrong.');
}
// istanbul ignore next
if (type === 'error') {
fileName = 'index.json';
}
type = type + "Dir";
filePath = this[type] + "/" + fileName;
return [4 /*yield*/, fileExistsP(this[type])];
case 1:
// istanbul ignore next
if (!(_a.sent())) {
fs.mkdirSync(this[type]);
}
return [2 /*return*/, writeFileP(filePath, content, { encoding: 'utf8', flag: 'w+' })];
}
});
};
BaseFixture.prototype.readFile = function (type, fileName) {
return __awaiter(this, void 0, void 0, function () {
var Types, filePath;
return __generator(this, function (_a) {
Types = ['actual', 'expect', 'src'];
if (Types.indexOf(type) < 0) {
throw new Error('[Aftertest readFile] Type is wrong.');
}
type = type + "Dir";
filePath = this[type] + "/" + fileName;
return [2 /*return*/, readFileP(filePath, {
encoding: 'utf8',
flag: 'r'
})];
});
});
};
BaseFixture.prototype.readFile = function (type, fileName) {
return __awaiter(this, void 0, void 0, function () {
var Types, filePath;
return __generator(this, function (_a) {
Types = ['actual', 'expect', 'src'];
if (Types.indexOf(type) < 0) {
throw new Error('[Aftertest readFile] Type is wrong.');
}
type = type + "Dir";
filePath = this[type] + "/" + fileName;
return [2 /*return*/, readFileP(filePath, {
encoding: 'utf8',
flag: 'r'
})];
});
};
BaseFixture.prototype.getAllDirs = function (dirPath) {
return __awaiter(this, void 0, void 0, function () {
var files, dirs;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, util_1.promisify(fs.readdir)(dirPath)];
case 1:
files = _a.sent();
dirs = files.filter(function (file) {
var stat = fs.lstatSync(dirPath + "/" + file);
return stat.isDirectory();
});
return [2 /*return*/, dirs];
}
});
});
};
BaseFixture.prototype.getAllDirs = function (dirPath) {
return __awaiter(this, void 0, void 0, function () {
var files, dirs;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, promisify(fs.readdir)(dirPath)];
case 1:
files = _a.sent();
dirs = files.filter(function (file) {
var stat = fs.lstatSync(dirPath + "/" + file);
return stat.isDirectory();
});
return [2 /*return*/, dirs];
}
});
};
BaseFixture.prototype.getFilelist = function (filePath) {
var items = fs.readdirSync(filePath);
var files = items.filter(function (item) {
var stat = fs.lstatSync(filePath + "/" + item);
return stat.isFile();
});
};
BaseFixture.prototype.getFilelist = function (filePath) {
var items = fs.readdirSync(filePath);
var files = items.filter(function (item) {
var stat = fs.lstatSync(filePath + "/" + item);
return stat.isFile();
});
return files;
};
BaseFixture.prototype.build = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
throw new Error('error should be emitted');
});
return files;
};
BaseFixture.prototype.build = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
throw new Error('error should be emitted');
});
});
};
BaseFixture.prototype.compareError = function (error) {
return __awaiter(this, void 0, void 0, function () {
var errorPath, errorFileExists, message, errorJSON, errorMessage;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
errorPath = path.resolve(this.errorDir + "/index.json");
return [4 /*yield*/, fileExistsP(errorPath)];
case 1:
errorFileExists = _a.sent();
message = error.message;
if (!!errorFileExists) return [3 /*break*/, 3];
return [4 /*yield*/, this.writeFile('error', JSON.stringify({
message: [message]
}, null, 2), '')];
case 2:
_a.sent();
return [3 /*break*/, 4];
case 3:
errorJSON = require(errorPath);
errorMessage = errorJSON.message;
if (errorMessage.indexOf(message) < 0) {
throw error;
}
_a.label = 4;
case 4: return [2 /*return*/];
}
});
};
BaseFixture.prototype.compareError = function (error) {
return __awaiter(this, void 0, void 0, function () {
var errorPath, errorFileExists, message, errorJSON, errorMessage;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
errorPath = path.resolve(this.errorDir + "/index.json");
return [4 /*yield*/, fileExistsP(errorPath)];
case 1:
errorFileExists = _a.sent();
message = error.message;
if (!!errorFileExists) return [3 /*break*/, 3];
return [4 /*yield*/, this.writeFile('error', JSON.stringify({
message: [message]
}, null, 2), '')];
case 2:
_a.sent();
return [3 /*break*/, 4];
case 3:
errorJSON = require(errorPath);
errorMessage = errorJSON.message;
if (errorMessage.indexOf(message) < 0) {
throw error;
}
_a.label = 4;
case 4: return [2 /*return*/];
}
});
});
};
BaseFixture.prototype.makeDiff = function (taskName) {
var _this = this;
it(taskName, function () { return __awaiter(_this, void 0, void 0, function () {
var e, err_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
e = null;
_a.label = 1;
case 1:
_a.trys.push([1, 3, , 5]);
return [4 /*yield*/, this.build()];
case 2:
_a.sent();
return [3 /*break*/, 5];
case 3:
err_1 = _a.sent();
e = err_1;
return [4 /*yield*/, this.compareError(e)];
case 4:
_a.sent();
return [3 /*break*/, 5];
case 5:
if (!(e == null)) return [3 /*break*/, 7];
return [4 /*yield*/, this.compareDir()];
case 6:
_a.sent();
_a.label = 7;
case 7: return [2 /*return*/];
}
});
};
BaseFixture.prototype.makeDiff = function (taskName) {
var _this = this;
it(taskName, function () { return __awaiter(_this, void 0, void 0, function () {
var e, err_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
e = null;
_a.label = 1;
case 1:
_a.trys.push([1, 3, , 5]);
return [4 /*yield*/, this.build()];
case 2:
_a.sent();
return [3 /*break*/, 5];
case 3:
err_1 = _a.sent();
e = err_1;
return [4 /*yield*/, this.compareError(e)];
case 4:
_a.sent();
return [3 /*break*/, 5];
case 5:
if (!(e == null)) return [3 /*break*/, 7];
return [4 /*yield*/, this.compareDir()];
case 6:
_a.sent();
_a.label = 7;
case 7: return [2 /*return*/];
}
});
}); });
};
BaseFixture.prototype.compareDir = function () {
return __awaiter(this, void 0, void 0, function () {
var expectFiles, actualFiles, _i, actualFiles_1, file, ac, ex;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
expectFiles = this.getFilelist(this.expectDir);
if (!(expectFiles.length > 0)) return [3 /*break*/, 6];
actualFiles = this.getFilelist(this.actualDir);
assert.deepEqual(actualFiles, expectFiles);
_i = 0, actualFiles_1 = actualFiles;
_a.label = 1;
case 1:
if (!(_i < actualFiles_1.length)) return [3 /*break*/, 5];
file = actualFiles_1[_i];
return [4 /*yield*/, readFileP(path.resolve(this.actualDir, file))];
case 2:
ac = _a.sent();
return [4 /*yield*/, readFileP(path.resolve(this.expectDir, file))];
case 3:
ex = _a.sent();
assert.equal(ac.toString(), ex.toString());
_a.label = 4;
case 4:
_i++;
return [3 /*break*/, 1];
case 5: return [2 /*return*/];
case 6:
}); });
};
BaseFixture.prototype.compareDir = function () {
return __awaiter(this, void 0, void 0, function () {
var expectFiles, actualFiles, _i, actualFiles_1, file, ac, ex;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
expectFiles = this.getFilelist(this.expectDir);
if (!(expectFiles.length > 0)) return [3 /*break*/, 6];
actualFiles = this.getFilelist(this.actualDir);
assert.deepEqual(actualFiles, expectFiles);
_i = 0, actualFiles_1 = actualFiles;
_a.label = 1;
case 1:
if (!(_i < actualFiles_1.length)) return [3 /*break*/, 5];
file = actualFiles_1[_i];
return [4 /*yield*/, readFileP(path.resolve(this.actualDir, file))];
case 2:
ac = _a.sent();
return [4 /*yield*/, readFileP(path.resolve(this.expectDir, file))];
case 3:
ex = _a.sent();
assert.equal(ac.toString(), ex.toString());
_a.label = 4;
case 4:
_i++;
return [3 /*break*/, 1];
case 5: return [2 /*return*/];
case 6:
// istanbul ignore next
return [4 /*yield*/, this.moveActualToExpect()];
case 7:
// istanbul ignore next
return [4 /*yield*/, this.moveActualToExpect()];
case 7:
// istanbul ignore next
_a.sent();
// istanbul ignore next
assert(true);
_a.label = 8;
case 8: return [2 /*return*/];
}
});
_a.sent();
// istanbul ignore next
assert(true);
_a.label = 8;
case 8: return [2 /*return*/];
}
});
};
BaseFixture.prototype.moveActualToExpect = function () {
return __awaiter(this, void 0, void 0, function () {
var files, promises;
var _this = this;
return __generator(this, function (_a) {
files = this.getFilelist(this.actualDir);
promises = [];
files.forEach(function (file) {
promises.push(copyFileP(_this.actualDir + "/" + file, _this.expectDir + "/" + file));
});
return [2 /*return*/, Promise.all(promises)];
});
};
BaseFixture.prototype.moveActualToExpect = function () {
return __awaiter(this, void 0, void 0, function () {
var files, promises;
var _this = this;
return __generator(this, function (_a) {
files = this.getFilelist(this.actualDir);
promises = [];
files.forEach(function (file) {
promises.push(copyFileP(_this.actualDir + "/" + file, _this.expectDir + "/" + file));
});
return [2 /*return*/, Promise.all(promises)];
});
};
BaseFixture.prototype.runTask = function (taskName) {
this.makeDiff(taskName);
};
return BaseFixture;
}());
exports.BaseFixture = BaseFixture;
});
});
};
BaseFixture.prototype.runTask = function (taskName) {
this.makeDiff(taskName);
};
return BaseFixture;
}());
export { BaseFixture };
//# sourceMappingURL=base-fixture.js.map
{
"name": "after-test",
"version": "1.0.7",
"version": "1.0.8",
"description": "aftercss",

@@ -5,0 +5,0 @@ "bin": {

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