baset-core
Advanced tools
Comparing version 0.8.0 to 0.9.0
@@ -6,2 +6,22 @@ # Change Log | ||
<a name="0.9.0"></a> | ||
# [0.9.0](https://github.com/Igmat/baset/compare/v0.8.0...v0.9.0) (2018-03-03) | ||
### Bug Fixes | ||
* **core:** adding context and sandbox object to resolvers ([a56d1b1](https://github.com/Igmat/baset/commit/a56d1b1)) | ||
* **core:** moving responsibility for comparison to baseliners ([4f6c260](https://github.com/Igmat/baset/commit/4f6c260)) | ||
* **core:** selecting baseline ext by baseliner ([b68a4b9](https://github.com/Igmat/baset/commit/b68a4b9)) | ||
* **core:** shared data-types for resolver/baseliner interaction ([48816d5](https://github.com/Igmat/baset/commit/48816d5)) | ||
### Features | ||
* **core:** adding data type for html resolving ([8689b29](https://github.com/Igmat/baset/commit/8689b29)) | ||
* **core:** api for resolvers that may work with different value types ([f8ddd23](https://github.com/Igmat/baset/commit/f8ddd23)) | ||
<a name="0.8.0"></a> | ||
@@ -8,0 +28,0 @@ # [0.8.0](https://github.com/Igmat/baset/compare/v0.7.5...v0.8.0) (2018-02-28) |
export declare abstract class AbstractBaseliner { | ||
options: any; | ||
readonly ext: string; | ||
abstract create: (result: Promise<any>[]) => Promise<string>; | ||
constructor(options: any); | ||
compare: (result: Promise<any>[], baseline: Promise<string>) => Promise<{ | ||
isEqual: boolean; | ||
expected: string; | ||
actual: string; | ||
diff: { | ||
console: string; | ||
full: string; | ||
}; | ||
}>; | ||
} | ||
export declare type IBaselinerConstructor = new (options: any) => AbstractBaseliner; |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const utils_1 = require("./utils"); | ||
class AbstractBaseliner { | ||
constructor(options) { | ||
this.options = options; | ||
this.ext = '.base'; | ||
this.compare = (result, baseline) => __awaiter(this, void 0, void 0, function* () { | ||
const [newBase, oldBase] = yield Promise.all([this.create(result), baseline]); | ||
return { | ||
isEqual: utils_1.normalizeEndings(newBase) === utils_1.normalizeEndings(oldBase), | ||
expected: oldBase, | ||
actual: newBase, | ||
diff: { | ||
console: '', | ||
full: '', | ||
}, | ||
}; | ||
}); | ||
} | ||
@@ -7,0 +29,0 @@ } |
@@ -0,7 +1,9 @@ | ||
import * as dataTypes from './dataTypes'; | ||
import * as utils from './utils'; | ||
export { AbstractBaseliner } from './abstractBaseliner'; | ||
export { AbstractReader, AddHook, AddFileResolver } from './abstractReader'; | ||
export { AbstractResolver } from './abstractResolver'; | ||
export { AbstractEnvironmet } from './abstractEnvironment'; | ||
export { circularReference, ITestGroupOptions } from './testGroup'; | ||
export { Tester } from './tester'; | ||
export { utils }; | ||
export { utils, dataTypes }; |
@@ -10,2 +10,4 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const dataTypes = __importStar(require("./dataTypes")); | ||
exports.dataTypes = dataTypes; | ||
const utils = __importStar(require("./utils")); | ||
@@ -17,2 +19,4 @@ exports.utils = utils; | ||
exports.AbstractReader = abstractReader_1.AbstractReader; | ||
var abstractResolver_1 = require("./abstractResolver"); | ||
exports.AbstractResolver = abstractResolver_1.AbstractResolver; | ||
var abstractEnvironment_1 = require("./abstractEnvironment"); | ||
@@ -19,0 +23,0 @@ exports.AbstractEnvironmet = abstractEnvironment_1.AbstractEnvironmet; |
@@ -24,14 +24,9 @@ "use strict"; | ||
throw new Error(`No reader defined for ${name}!`); | ||
const output = (yield reader.read(name)).replace(/\r?\n|\r/g, '\n').trim(); | ||
const ext = path_1.default.extname(name); | ||
const baselinePath = path_1.default.resolve(name.replace(new RegExp(`${ext}$`), '.base')); | ||
const baselineValue = (yield utils_1.isExists(baselinePath)) | ||
? (yield utils_1.readFile(baselinePath, { encoding: 'utf-8' })).replace(/\r?\n|\r/g, '\n').trim() | ||
: false; | ||
yield utils_1.writeFile(path_1.default.resolve(`${baselinePath}.tmp`), output); | ||
const testResult = yield reader.test(name); | ||
yield utils_1.writeFile(utils_1.pathToTmp(testResult.path), testResult.output.actual); | ||
return { | ||
name, | ||
isPassed: baselineValue === output, | ||
expected: baselineValue || '', | ||
actual: output, | ||
isPassed: testResult.output.isEqual, | ||
expected: testResult.output.expected || '', | ||
actual: testResult.output.actual, | ||
}; | ||
@@ -41,3 +36,3 @@ }); | ||
const baseline = yield utils_1.readFile(path_1.default.resolve(name), { encoding: 'utf-8' }); | ||
const filePath = name.replace(/.tmp$/, ''); | ||
const filePath = utils_1.tmpToPath(name); | ||
yield utils_1.writeFile(path_1.default.resolve(filePath), baseline); | ||
@@ -44,0 +39,0 @@ yield utils_1.unlink(path_1.default.resolve(name)); |
@@ -17,6 +17,19 @@ import { IDictionary } from './utils'; | ||
private readerChain; | ||
private resolvers; | ||
private allImports; | ||
private indexOfResolver; | ||
constructor(pattern: string | RegExp, options: ITestGroupOptions, pluginsOptions: IDictionary<any>); | ||
match: (filePath: string) => boolean; | ||
read: (filePath: string) => Promise<string>; | ||
test: (filePath: string) => Promise<{ | ||
path: string; | ||
output: { | ||
isEqual: boolean; | ||
expected: string; | ||
actual: string; | ||
diff: { | ||
console: string; | ||
full: string; | ||
}; | ||
}; | ||
}>; | ||
private calculateValues; | ||
@@ -23,0 +36,0 @@ private createSelfReference; |
@@ -26,5 +26,6 @@ "use strict"; | ||
this.match = (filePath) => this.pattern.test(filePath); | ||
this.read = (filePath) => __awaiter(this, void 0, void 0, function* () { | ||
this.test = (filePath) => __awaiter(this, void 0, void 0, function* () { | ||
const resolvedPath = path_1.default.resolve(filePath); | ||
const compiler = this.getCompiler(); | ||
const sandbox = {}; | ||
const context = new baset_vm_1.NodeVM({ | ||
@@ -37,2 +38,3 @@ require: { | ||
}, | ||
sandbox: { basetSandbox: sandbox }, | ||
compiler: compiler.compile, | ||
@@ -49,7 +51,18 @@ sourceExtensions: compiler.extensions, | ||
const testsExports = tests.map((test, index) => context.run(test, `${resolvedPath}.${index}.js`)); | ||
const testsResults = testsExports.map((value, index) => this.calculateValues(value, `exports[${index}]`)); | ||
return this.baseliner.create(testsResults); | ||
const testsResults = testsExports.map((value, index) => this.calculateValues(value, context, sandbox, `exports[${index}]`)); | ||
const ext = path_1.default.extname(filePath); | ||
const baselinePath = path_1.default.resolve(filePath.replace(new RegExp(`${ext}$`), this.baseliner.ext)); | ||
const baselineValue = (yield utils_1.isExists(baselinePath)) | ||
? utils_1.readFile(baselinePath, { encoding: 'utf-8' }) | ||
: new Promise(resolve => resolve('')); | ||
return { | ||
path: baselinePath, | ||
output: yield this.baseliner.compare(testsResults, baselineValue), | ||
}; | ||
}); | ||
// tslint:disable-next-line:no-any | ||
this.calculateValues = (obj, name = 'exports') => __awaiter(this, void 0, void 0, function* () { | ||
this.calculateValues = (obj, context, sandbox, name = 'exports') => __awaiter(this, void 0, void 0, function* () { | ||
const resolverIndex = yield this.indexOfResolver(obj, context, sandbox); | ||
if (resolverIndex !== -1) | ||
return this.resolvers[resolverIndex].resolve(obj, context, sandbox); | ||
if (util_1.isPrimitive(obj)) | ||
@@ -61,9 +74,10 @@ return obj; | ||
if (obj instanceof Promise) | ||
return obj; | ||
return this.calculateValues(yield obj, context, sandbox, name); | ||
if (obj instanceof Function) | ||
return obj.toString().split('\n')[0]; | ||
if (Array.isArray(obj)) | ||
return yield Promise.all(obj.map((value, key) => this.calculateValues(value, `${name}[${key}]`))); | ||
if (Array.isArray(obj)) { | ||
return yield Promise.all(obj.map((value, key) => this.calculateValues(value, context, sandbox, `${name}[${key}]`))); | ||
} | ||
return (yield Promise.all(Object.keys(obj) | ||
.map((key) => __awaiter(this, void 0, void 0, function* () { return ({ [key]: yield this.calculateValues(obj[key], `${name}.${key}`) }); })))) | ||
.map((key) => __awaiter(this, void 0, void 0, function* () { return ({ [key]: yield this.calculateValues(obj[key], context, sandbox, `${name}.${key}`) }); })))) | ||
.reduce((result, prop) => (Object.assign({}, result, prop)), {}); | ||
@@ -119,2 +133,13 @@ }); | ||
}); | ||
this.resolvers = options.resolvers.map(resolverName => { | ||
const resolver = require(path_1.default.resolve(resolverName)).default; | ||
return new resolver(pluginsOptions[resolverName]); | ||
}); | ||
const resolveMatchers = this.resolvers | ||
.map((resolver, index) => (toMatch, context, sandbox) => __awaiter(this, void 0, void 0, function* () { return resolver.match(toMatch, context, sandbox); })); | ||
this.indexOfResolver = (obj, context, sandbox) => __awaiter(this, void 0, void 0, function* () { | ||
return (yield Promise.all(resolveMatchers | ||
.map(matcher => matcher(obj, context, sandbox)))) | ||
.indexOf(true); | ||
}); | ||
this.allImports = [ | ||
@@ -121,0 +146,0 @@ options.environment, |
@@ -10,1 +10,4 @@ /// <reference types="node" /> | ||
} | ||
export declare function pathToTmp(value: string): string; | ||
export declare function tmpToPath(value: string): string; | ||
export declare function normalizeEndings(value: string): string; |
@@ -7,2 +7,3 @@ "use strict"; | ||
const fs_1 = __importDefault(require("fs")); | ||
const path_1 = __importDefault(require("path")); | ||
const util_1 = require("util"); | ||
@@ -13,2 +14,15 @@ exports.writeFile = util_1.promisify(fs_1.default.writeFile); | ||
exports.unlink = util_1.promisify(fs_1.default.unlink); | ||
function pathToTmp(value) { | ||
const ext = path_1.default.extname(value); | ||
return value.replace(new RegExp(`${ext}$`), `.tmp${ext}`); | ||
} | ||
exports.pathToTmp = pathToTmp; | ||
function tmpToPath(value) { | ||
return value.replace(/.tmp./, '.'); | ||
} | ||
exports.tmpToPath = tmpToPath; | ||
function normalizeEndings(value) { | ||
return value.replace(/\r?\n|\r/g, '\n').trim(); | ||
} | ||
exports.normalizeEndings = normalizeEndings; | ||
//# sourceMappingURL=utils.js.map |
{ | ||
"name": "baset-core", | ||
"version": "0.8.0", | ||
"version": "0.9.0", | ||
"description": "Core library for BaseT project.", | ||
@@ -32,3 +32,3 @@ "keywords": [ | ||
"@types/node": "^9.3.0", | ||
"baset": "^0.8.0", | ||
"baset": "^0.9.0", | ||
"doctoc": "^1.3.0", | ||
@@ -39,4 +39,4 @@ "tslint": "^5.9.1", | ||
"dependencies": { | ||
"baset-vm": "^0.7.3" | ||
"baset-vm": "^0.9.0" | ||
} | ||
} |
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
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
38106
9
31
432
4
+ Addedbaset-vm@0.9.0(transitive)
- Removedbaset-vm@0.7.3(transitive)
Updatedbaset-vm@^0.9.0