From 82c900ba3176ecf39aa328818aa2afc4373b3d2d Mon Sep 17 00:00:00 2001 From: Tokesh Date: Sat, 18 Jan 2025 00:08:50 +0500 Subject: [PATCH] debug: adding logs during unit tests in CI Signed-off-by: Tokesh --- package.json | 2 +- tools/src/_utils/JsonSchemaValidator.ts | 2 + tools/src/tester/StoryValidator.ts | 6 +++ tools/tests/tester/StoryValidator.test.ts | 48 +++++++++++------------ 4 files changed, 33 insertions(+), 25 deletions(-) diff --git a/package.json b/package.json index a0715e2a2..9940ac8b4 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "style:prepare": "ts-node tools/src/prepare-for-vale/prepare-for-vale.ts", "test": "npm run test:unit && npm run test:integ", "jest": "jest", - "test:unit": "jest --testMatch='**/*.test.ts' --testPathIgnorePatterns=/integ/", + "test:unit": "jest tools/tests/tester/StoryValidator.test.ts --testPathIgnorePatterns=/integ/", "test:integ": "jest --testMatch='**/integ/*.test.ts' --runInBand", "test:spec": "ts-node tools/src/tester/test.ts", "test:spec--insecure": "ts-node tools/src/tester/test.ts --opensearch-insecure" diff --git a/tools/src/_utils/JsonSchemaValidator.ts b/tools/src/_utils/JsonSchemaValidator.ts index 850468363..bd0ab6871 100644 --- a/tools/src/_utils/JsonSchemaValidator.ts +++ b/tools/src/_utils/JsonSchemaValidator.ts @@ -51,6 +51,7 @@ export default class JsonSchemaValidator { validate_data(data: any, schema?: Record): string | undefined { if (schema) return this.#validate(this.ajv.compile(schema), data) + console.log("validate_data func", this._validate, data); if (this._validate) return this.#validate(this._validate, data) throw new Error('No schema provided') } @@ -63,6 +64,7 @@ export default class JsonSchemaValidator { #validate(validate_func: ValidateFunction, data: any, is_schema: boolean = false): string | undefined { const valid = validate_func(data) as boolean const errors = is_schema ? this.ajv.errors : validate_func.errors + console.log("errors", errors); return valid ? undefined : this.errors_parser.parse(errors) } } diff --git a/tools/src/tester/StoryValidator.ts b/tools/src/tester/StoryValidator.ts index e9a2ef097..f5f4c4f5e 100644 --- a/tools/src/tester/StoryValidator.ts +++ b/tools/src/tester/StoryValidator.ts @@ -23,19 +23,25 @@ export default class StoryValidator { validate(story_file: StoryFile): StoryEvaluation | undefined { const schema_file_error = this.#validate_schema_path(story_file) + console.log("schema_file_error", schema_file_error) if (schema_file_error != null) return schema_file_error const schema_error = this.#validate_schema(story_file) + console.log("schema_error", schema_error) if (schema_error != null) return schema_error } #validate_schema_path(story_file: StoryFile): StoryEvaluation | undefined { const actual_path = story_file.story.$schema + console.log("actual_path", actual_path) const expected_path = path.relative(path.dirname(story_file.full_path), StoryValidator.SCHEMA_FILE) + console.log("expected_path", expected_path) if (actual_path !== expected_path) return this.#invalid(story_file, `Expected $schema to be ${expected_path}`) } #validate_schema(story_file: StoryFile): StoryEvaluation | undefined { + console.log("story_file", story_file) const message = this.json_validator.validate_data(story_file.story) + console.log("validate_schema message", message); if (message != null) return this.#invalid(story_file, message) } diff --git a/tools/tests/tester/StoryValidator.test.ts b/tools/tests/tester/StoryValidator.test.ts index aa28fdcc0..422548efa 100644 --- a/tools/tests/tester/StoryValidator.test.ts +++ b/tools/tests/tester/StoryValidator.test.ts @@ -21,11 +21,11 @@ function validate(path: string): StoryEvaluation | undefined { } describe('StoryValidator', () => { - test('wrong $schema', () => { - const evaluation = validate('tools/tests/tester/fixtures/wrong_$schema.yaml') - expect(evaluation?.result).toBe('ERROR') - expect(evaluation?.message).toBe('Invalid Story: Expected $schema to be ../../../../json_schemas/test_story.schema.yaml') - }) + // test('wrong $schema', () => { + // const evaluation = validate('tools/tests/tester/fixtures/wrong_$schema.yaml') + // expect(evaluation?.result).toBe('ERROR') + // expect(evaluation?.message).toBe('Invalid Story: Expected $schema to be ../../../../json_schemas/test_story.schema.yaml') + // }) test('invalid story', () => { const evaluation = validate('tools/tests/tester/fixtures/invalid_story.yaml') @@ -37,23 +37,23 @@ describe('StoryValidator', () => { "data/chapters/1/method must be array --- data/chapters/1/method must match exactly one schema in oneOf") }) - test('invalid description', () => { - const evaluation = validate('tools/tests/tester/fixtures/invalid_description.yaml') - expect(evaluation?.result).toBe('ERROR') - expect(evaluation?.message).toBe("Invalid Story: " + - "data/description must match pattern \"^\\p{Lu}[\\s\\S]*\\.$\" --- " + - "data/chapters/0/synopsis must match pattern \"^\\p{Lu}[\\s\\S]*\\.$|^\\p{Lu}[\\s\\S]*\\. \\[(GET|PUT|POST|DELETE|PATCH|HEAD|OPTIONS)\\]$\"") - }) - - test('invalid property', () => { - const evaluation = validate('tools/tests/tester/fixtures/invalid_property.yaml') - expect(evaluation?.result).toBe('ERROR') - expect(evaluation?.message).toBe("Invalid Story: " + - "data/prologues/0/retry contains unsupported properties: until") - }) - - test('valid story', () => { - const evaluation = validate('tools/tests/tester/fixtures/valid_story.yaml') - expect(evaluation).toBeUndefined() - }) + // test('invalid description', () => { + // const evaluation = validate('tools/tests/tester/fixtures/invalid_description.yaml') + // expect(evaluation?.result).toBe('ERROR') + // expect(evaluation?.message).toBe("Invalid Story: " + + // "data/description must match pattern \"^\\p{Lu}[\\s\\S]*\\.$\" --- " + + // "data/chapters/0/synopsis must match pattern \"^\\p{Lu}[\\s\\S]*\\.$|^\\p{Lu}[\\s\\S]*\\. \\[(GET|PUT|POST|DELETE|PATCH|HEAD|OPTIONS)\\]$\"") + // }) + + // test('invalid property', () => { + // const evaluation = validate('tools/tests/tester/fixtures/invalid_property.yaml') + // expect(evaluation?.result).toBe('ERROR') + // expect(evaluation?.message).toBe("Invalid Story: " + + // "data/prologues/0/retry contains unsupported properties: until") + // }) + + // test('valid story', () => { + // const evaluation = validate('tools/tests/tester/fixtures/valid_story.yaml') + // expect(evaluation).toBeUndefined() + // }) }) \ No newline at end of file