Skip to content

Commit

Permalink
debug: adding logs during unit tests in CI
Browse files Browse the repository at this point in the history
Signed-off-by: Tokesh <tokesh789@gmail.com>
  • Loading branch information
Tokesh committed Jan 17, 2025
1 parent 021f187 commit 82c900b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 25 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions tools/src/_utils/JsonSchemaValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export default class JsonSchemaValidator {

validate_data(data: any, schema?: Record<any, any>): 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')
}
Expand All @@ -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)
}
}
6 changes: 6 additions & 0 deletions tools/src/tester/StoryValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
48 changes: 24 additions & 24 deletions tools/tests/tester/StoryValidator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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()
// })
})

0 comments on commit 82c900b

Please sign in to comment.