mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-23 18:12:43 +00:00
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018 StApps
|
||||
* Copyright (C) 2018-2019 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
@@ -19,10 +19,10 @@ import * as mustache from 'mustache';
|
||||
import {basename, join, resolve} from 'path';
|
||||
import {
|
||||
ExpectableValidationErrors,
|
||||
globPromisfied,
|
||||
globPromisified,
|
||||
isThingWithType,
|
||||
logger,
|
||||
readFilePromisifed,
|
||||
readFilePromisified,
|
||||
writeFilePromisified,
|
||||
} from './common';
|
||||
|
||||
@@ -53,7 +53,7 @@ export class Validator {
|
||||
* @param schemaDir Path to directory that contains schema files
|
||||
*/
|
||||
public async addSchemas(schemaDir: PathLike): Promise<string[]> {
|
||||
const schemaFiles = await globPromisfied(join(schemaDir.toString(), '*.json'));
|
||||
const schemaFiles = await globPromisified(join(schemaDir.toString(), '*.json'));
|
||||
|
||||
if (schemaFiles.length === 0) {
|
||||
throw new Error(`No schema files in ${schemaDir.toString()}!`);
|
||||
@@ -64,7 +64,7 @@ export class Validator {
|
||||
// Iterate over schema files
|
||||
await asyncPool(2, schemaFiles, async (file) => {
|
||||
// read schema file
|
||||
const buffer = await readFilePromisifed(file);
|
||||
const buffer = await readFilePromisified(file);
|
||||
const schema = JSON.parse(buffer.toString());
|
||||
|
||||
// add schema to validator
|
||||
@@ -124,7 +124,7 @@ export async function validateFiles(schemaDir: string, resourcesDir: string): Pr
|
||||
await v.addSchemas(schemaDir);
|
||||
|
||||
// get list of files to test
|
||||
const testFiles = await globPromisfied(join(resourcesDir, '*.json'));
|
||||
const testFiles = await globPromisified(join(resourcesDir, '*.json'));
|
||||
|
||||
if (testFiles.length === 0) {
|
||||
throw new Error(`No test files in ${resourcesDir}!`);
|
||||
@@ -139,7 +139,7 @@ export async function validateFiles(schemaDir: string, resourcesDir: string): Pr
|
||||
await asyncPool(2, testFiles, async (testFile) => {
|
||||
const testFileName = basename(testFile);
|
||||
|
||||
const buffer = await readFilePromisifed(join(resourcesDir, testFileName));
|
||||
const buffer = await readFilePromisified(join(resourcesDir, testFileName));
|
||||
|
||||
// read test description from file
|
||||
const testDescription = JSON.parse(buffer.toString());
|
||||
@@ -208,10 +208,10 @@ export async function validateFiles(schemaDir: string, resourcesDir: string): Pr
|
||||
* @param errors Errors that occurred in validation
|
||||
*/
|
||||
export async function writeReport(reportPath: PathLike, errors: ExpectableValidationErrors): Promise<void> {
|
||||
let buffer = await readFilePromisifed(resolve(__dirname, '..', 'resources', 'file.html.mustache'));
|
||||
let buffer = await readFilePromisified(resolve(__dirname, '..', 'resources', 'file.html.mustache'));
|
||||
const fileTemplate = buffer.toString();
|
||||
|
||||
buffer = await readFilePromisifed(resolve(__dirname, '..', 'resources', 'error.html.mustache'));
|
||||
buffer = await readFilePromisified(resolve(__dirname, '..', 'resources', 'error.html.mustache'));
|
||||
const errorTemplate = buffer.toString();
|
||||
|
||||
let output = '';
|
||||
@@ -236,7 +236,7 @@ export async function writeReport(reportPath: PathLike, errors: ExpectableValida
|
||||
});
|
||||
});
|
||||
|
||||
buffer = await readFilePromisifed(resolve(__dirname, '..', 'resources', 'report.html.mustache'));
|
||||
buffer = await readFilePromisified(resolve(__dirname, '..', 'resources', 'report.html.mustache'));
|
||||
const reportTemplate = buffer.toString();
|
||||
|
||||
await writeFilePromisified(reportPath, mustache.render(reportTemplate, {
|
||||
|
||||
Reference in New Issue
Block a user