baset-core
Advanced tools
Comparing version 0.3.0 to 0.4.0
@@ -6,2 +6,13 @@ # Change Log | ||
<a name="0.4.0"></a> | ||
# [0.4.0](https://github.com/Igmat/baset/compare/v0.3.0...v0.4.0) (2018-01-24) | ||
### Features | ||
* **Core:** Recursivly check exports to work with promises and functions ([fbf5eb0](https://github.com/Igmat/baset/commit/fbf5eb0)) | ||
<a name="0.3.0"></a> | ||
@@ -8,0 +19,0 @@ # [0.3.0](https://github.com/Igmat/baset/compare/v0.2.2...v0.3.0) (2018-01-23) |
export declare function test(specs: string[], baselines: string[]): Promise<string>[]; | ||
export declare function accept(files: string[]): void; |
"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 }); | ||
@@ -6,31 +14,51 @@ const fs = require("fs"); | ||
const path = require("path"); | ||
function test(specs, baselines) { | ||
const files = specs.map(name => ({ | ||
name, | ||
output: beautify(require(path.resolve(name)), undefined, 4, 20), | ||
})); | ||
return files.map(file => new Promise((resolve, reject) => { | ||
const baselinePath = path.resolve(file.name.replace(/.spec.js$/, '.base')); | ||
const baseline = fs.existsSync(baselinePath) | ||
? fs.readFileSync(baselinePath, { encoding: 'utf-8' }) | ||
: false; | ||
fs.writeFile(path.resolve(file.name.replace(/.spec.js$/, '.base.tmp')), file.output, err => { | ||
if (err) { | ||
console.log(err); | ||
return reject(err); | ||
} | ||
console.log(`Temp baseline for ${file.name} is written.`); | ||
if (baseline === file.output) { | ||
resolve(`Test for ${file.name} is passed`); | ||
} | ||
else { | ||
reject({ | ||
name: file.name, | ||
expected: baseline || '', | ||
actual: file.output, | ||
}); | ||
} | ||
const util_1 = require("util"); | ||
// tslint:disable-next-line:no-any | ||
function calculateValues(obj) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (util_1.isPrimitive(obj)) | ||
return obj; | ||
else if (obj instanceof Promise) | ||
return obj; | ||
else if (obj instanceof Function) | ||
return obj(); | ||
else if (obj instanceof Array) | ||
return yield Promise.all(obj.map(calculateValues)); | ||
return (yield Promise.all(Object.keys(obj) | ||
.map((key) => __awaiter(this, void 0, void 0, function* () { return ({ [key]: yield calculateValues(obj[key]) }); })))) | ||
.reduce((result, prop) => (Object.assign({}, result, prop)), {}); | ||
}); | ||
} | ||
function testSpec(spec) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const file = { | ||
name: spec, | ||
output: beautify(yield calculateValues(require(path.resolve(spec))), undefined, 4, 20), | ||
}; | ||
return yield new Promise((resolve, reject) => { | ||
const baselinePath = path.resolve(file.name.replace(/.spec.js$/, '.base')); | ||
const baseline = fs.existsSync(baselinePath) | ||
? fs.readFileSync(baselinePath, { encoding: 'utf-8' }) | ||
: false; | ||
fs.writeFile(path.resolve(file.name.replace(/.spec.js$/, '.base.tmp')), file.output, err => { | ||
if (err) | ||
return reject(err); | ||
console.log(`Temp baseline for ${file.name} is written.`); | ||
if (baseline === file.output) { | ||
resolve(`Test for ${file.name} is passed`); | ||
} | ||
else { | ||
reject({ | ||
name: file.name, | ||
expected: baseline || '', | ||
actual: file.output, | ||
}); | ||
} | ||
}); | ||
}); | ||
})); | ||
}); | ||
} | ||
function test(specs, baselines) { | ||
return specs.map(testSpec); | ||
} | ||
exports.test = test; | ||
@@ -37,0 +65,0 @@ function accept(files) { |
{ | ||
"name": "baset-core", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "", | ||
@@ -17,3 +17,3 @@ "main": "dist/index.js", | ||
"@types/node": "^9.3.0", | ||
"baset": "^0.3.0", | ||
"baset": "^0.4.0", | ||
"tslint": "^5.9.1", | ||
@@ -20,0 +20,0 @@ "typescript": "^2.6.2" |
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
8387
76