Skip to content

Commit 3f81094

Browse files
CopilotGrantBirki
andcommitted
Format test files and bundle final changes
Co-authored-by: GrantBirki <[email protected]>
1 parent 27c6361 commit 3f81094

File tree

5 files changed

+97
-75
lines changed

5 files changed

+97
-75
lines changed

__tests__/functions/json-validator.test.js

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -646,15 +646,15 @@ test('yamlAsJson: failed validation of a multi-document-file', async () => {
646646
test('successfully skips JSON files that match json_exclude_regex', async () => {
647647
process.env.INPUT_JSON_EXCLUDE_REGEX = '.*valid.*\\.json'
648648
process.env.INPUT_BASE_DIR = '__tests__/fixtures/json/valid'
649-
649+
650650
expect(await jsonValidator(excludeMock)).toStrictEqual({
651651
failed: 0,
652652
passed: 0,
653653
skipped: 1,
654654
success: true,
655655
violations: []
656656
})
657-
657+
658658
expect(infoMock).toHaveBeenCalledWith(
659659
expect.stringMatching('skipping due to exclude match:')
660660
)
@@ -663,7 +663,7 @@ test('successfully skips JSON files that match json_exclude_regex', async () =>
663663
test('handles json_exclude_regex with empty string (no exclusion)', async () => {
664664
process.env.INPUT_JSON_EXCLUDE_REGEX = ''
665665
process.env.INPUT_BASE_DIR = '__tests__/fixtures/json/valid'
666-
666+
667667
expect(await jsonValidator(excludeMock)).toStrictEqual({
668668
failed: 0,
669669
passed: 1,
@@ -676,11 +676,11 @@ test('handles json_exclude_regex with empty string (no exclusion)', async () =>
676676
test('processes non-array data correctly (covers data validation branch)', async () => {
677677
process.env.INPUT_BASE_DIR = '__tests__/fixtures/json/valid'
678678
process.env.INPUT_JSON_SCHEMA = ''
679-
679+
680680
const result = await jsonValidator(excludeMock)
681681
expect(result.success).toBe(true)
682682
expect(result.passed).toBe(1)
683-
683+
684684
expect(debugMock).toHaveBeenCalledWith(
685685
expect.stringMatching('1 object\\(s\\) found in file:')
686686
)
@@ -756,20 +756,22 @@ test('handles use_ajv_formats disabled', async () => {
756756
violations: []
757757
})
758758

759-
expect(debugMock).toHaveBeenCalledWith('ajv-formats will not be used with the json-validator')
759+
expect(debugMock).toHaveBeenCalledWith(
760+
'ajv-formats will not be used with the json-validator'
761+
)
760762
})
761763

762764
test('handles non-array data processing with single document YAML as JSON', async () => {
763765
// This test covers the case where data is not initially an array (line 254)
764766
process.env.INPUT_YAML_AS_JSON = 'true'
765-
process.env.INPUT_ALLOW_MULTIPLE_DOCUMENTS = 'false' // This makes data not an array initially
767+
process.env.INPUT_ALLOW_MULTIPLE_DOCUMENTS = 'false' // This makes data not an array initially
766768
process.env.INPUT_BASE_DIR = '__tests__/fixtures/yaml_as_json/valid'
767769
process.env.INPUT_JSON_SCHEMA = ''
768-
770+
769771
const result = await jsonValidator(excludeMock)
770772
expect(result.success).toBe(true)
771773
expect(result.passed).toBe(1)
772-
774+
773775
// This should trigger the Array.isArray check and the debug message
774776
expect(debugMock).toHaveBeenCalledWith(
775777
expect.stringMatching('1 object\\(s\\) found in file:')
@@ -780,29 +782,29 @@ test('edge case: empty json_exclude_regex with complex file structure', async ()
780782
process.env.INPUT_JSON_EXCLUDE_REGEX = ''
781783
process.env.INPUT_BASE_DIR = '__tests__/fixtures/json/mixture'
782784
process.env.INPUT_JSON_SCHEMA = ''
783-
785+
784786
const result = await jsonValidator(excludeMock)
785787
expect(result.passed + result.failed).toBeGreaterThan(0)
786788
})
787789

788790
test('edge case: complex file patterns with multiple extensions', async () => {
789-
process.env.INPUT_FILES = '__tests__/fixtures/json/valid/*.json\n__tests__/fixtures/yaml_as_json/valid/*.yaml'
791+
process.env.INPUT_FILES =
792+
'__tests__/fixtures/json/valid/*.json\n__tests__/fixtures/yaml_as_json/valid/*.yaml'
790793
process.env.INPUT_YAML_AS_JSON = 'true'
791794
process.env.INPUT_BASE_DIR = '.'
792795
process.env.INPUT_JSON_SCHEMA = ''
793-
796+
794797
const result = await jsonValidator(excludeMock)
795798
expect(result.passed).toBeGreaterThan(0)
796-
797-
expect(debugMock).toHaveBeenCalledWith(
798-
expect.stringMatching('using files:')
799-
)
799+
800+
expect(debugMock).toHaveBeenCalledWith(expect.stringMatching('using files:'))
800801
})
801802

802803
test('edge case: malformed custom regexp formats with complex patterns', async () => {
803804
expect.assertions(1)
804805
try {
805-
process.env.INPUT_AJV_CUSTOM_REGEXP_FORMATS = 'valid_format=^[a-z]+$\ninvalid-format'
806+
process.env.INPUT_AJV_CUSTOM_REGEXP_FORMATS =
807+
'valid_format=^[a-z]+$\ninvalid-format'
806808
await jsonValidator(excludeMock)
807809
} catch (e) {
808810
expect(e.message).toContain('is not in expected format "key=regex"')
@@ -811,12 +813,13 @@ test('edge case: malformed custom regexp formats with complex patterns', async (
811813

812814
test('edge case: schema file skipping logic', async () => {
813815
process.env.INPUT_JSON_SCHEMA = '__tests__/fixtures/schemas/schema1.json'
814-
process.env.INPUT_FILES = '__tests__/fixtures/schemas/schema1.json\n__tests__/fixtures/json/valid/json1.json'
816+
process.env.INPUT_FILES =
817+
'__tests__/fixtures/schemas/schema1.json\n__tests__/fixtures/json/valid/json1.json'
815818
process.env.INPUT_BASE_DIR = '.'
816-
819+
817820
const result = await jsonValidator(excludeMock)
818821
expect(result.passed).toBe(1) // Only json1.json should be processed, schema1.json should be skipped
819-
822+
820823
expect(debugMock).toHaveBeenCalledWith(
821824
expect.stringMatching('skipping json schema file:')
822825
)
@@ -827,33 +830,34 @@ test('stress test: large number of custom regex formats', async () => {
827830
for (let i = 0; i < 10; i++) {
828831
formats.push(`format${i}=^test${i}.*$`)
829832
}
830-
833+
831834
process.env.INPUT_AJV_CUSTOM_REGEXP_FORMATS = formats.join('\n')
832835
process.env.INPUT_BASE_DIR = '__tests__/fixtures/json/valid'
833836
process.env.INPUT_JSON_SCHEMA = ''
834-
837+
835838
const result = await jsonValidator(excludeMock)
836839
expect(result.success).toBe(true)
837840
})
838841

839842
test('edge case: duplicate file processing prevention', async () => {
840843
// Test that files are not processed multiple times
841-
process.env.INPUT_FILES = '__tests__/fixtures/json/valid/json1.json\n__tests__/fixtures/json/valid/json1.json'
844+
process.env.INPUT_FILES =
845+
'__tests__/fixtures/json/valid/json1.json\n__tests__/fixtures/json/valid/json1.json'
842846
process.env.INPUT_BASE_DIR = '.'
843847
process.env.INPUT_JSON_SCHEMA = ''
844-
848+
845849
const result = await jsonValidator(excludeMock)
846850
expect(result.passed).toBe(1) // Should only process the file once
847-
851+
848852
expect(debugMock).toHaveBeenCalledWith(
849853
expect.stringMatching('skipping duplicate file:')
850854
)
851855
})
852856

853857
test('edge case: baseDir with trailing slash normalization', async () => {
854-
process.env.INPUT_BASE_DIR = '__tests__/fixtures/json/valid/' // Note trailing slash
858+
process.env.INPUT_BASE_DIR = '__tests__/fixtures/json/valid/' // Note trailing slash
855859
process.env.INPUT_JSON_SCHEMA = ''
856-
860+
857861
const result = await jsonValidator(excludeMock)
858862
expect(result.success).toBe(true)
859863
expect(result.passed).toBe(1)
@@ -864,7 +868,7 @@ test('real world scenario: large schema with draft-2019-09', async () => {
864868
process.env.INPUT_JSON_SCHEMA = '__tests__/fixtures/schemas/challenge.json'
865869
process.env.INPUT_BASE_DIR = '__tests__/fixtures/real_world/challenges'
866870
process.env.INPUT_YAML_AS_JSON = 'true'
867-
871+
868872
const result = await jsonValidator(excludeMock)
869873
expect(result).toBeDefined()
870874
expect(typeof result.success).toBe('boolean')
@@ -875,16 +879,16 @@ test('edge case: potential non-array data with complex yaml parsing', async () =
875879
const fs = require('fs')
876880
const tempFile = '/tmp/complex_yaml.yaml'
877881
fs.writeFileSync(tempFile, 'scalar_value')
878-
882+
879883
process.env.INPUT_YAML_AS_JSON = 'true'
880884
process.env.INPUT_ALLOW_MULTIPLE_DOCUMENTS = 'false'
881885
process.env.INPUT_FILES = tempFile
882886
process.env.INPUT_BASE_DIR = '.'
883887
process.env.INPUT_JSON_SCHEMA = ''
884-
888+
885889
const result = await jsonValidator(excludeMock)
886890
expect(result.passed).toBe(1)
887-
891+
888892
// Cleanup
889893
fs.unlinkSync(tempFile)
890894
})
@@ -894,16 +898,16 @@ test('edge case: empty document processing', async () => {
894898
const fs = require('fs')
895899
const tempFile = '/tmp/empty.yaml'
896900
fs.writeFileSync(tempFile, '')
897-
901+
898902
process.env.INPUT_YAML_AS_JSON = 'true'
899903
process.env.INPUT_ALLOW_MULTIPLE_DOCUMENTS = 'false'
900904
process.env.INPUT_FILES = tempFile
901905
process.env.INPUT_BASE_DIR = '.'
902906
process.env.INPUT_JSON_SCHEMA = ''
903-
907+
904908
const result = await jsonValidator(excludeMock)
905909
expect(result.passed + result.failed).toBeGreaterThan(0)
906-
910+
907911
// Cleanup
908912
fs.unlinkSync(tempFile)
909913
})
@@ -913,16 +917,16 @@ test('edge case: malformed JSON in real file', async () => {
913917
const fs = require('fs')
914918
const tempFile = '/tmp/malformed.json'
915919
fs.writeFileSync(tempFile, '{"invalid": json, missing quotes}')
916-
920+
917921
process.env.INPUT_FILES = tempFile
918922
process.env.INPUT_BASE_DIR = '.'
919923
process.env.INPUT_JSON_SCHEMA = ''
920924
process.env.INPUT_YAML_AS_JSON = 'false'
921-
925+
922926
const result = await jsonValidator(excludeMock)
923927
expect(result.failed).toBe(1)
924928
expect(result.success).toBe(false)
925-
929+
926930
// Cleanup
927931
fs.unlinkSync(tempFile)
928932
})

__tests__/functions/process-results.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ test('tests constructBody function with JSON failures only (covers lines 50-67)'
280280
{success: true, failed: 0, passed: 3, skipped: 0, violations: []}
281281
)
282282
).toBe(false)
283-
283+
284284
// The constructBody function should have been called and created a comment
285285
expect(infoMock).toHaveBeenCalledWith(
286286
expect.stringMatching('📝 adding comment to PR')
@@ -301,7 +301,7 @@ test('tests constructBody function with YAML failures only (covers lines 69-86)'
301301
}
302302
)
303303
).toBe(false)
304-
304+
305305
// The constructBody function should have been called and created a comment
306306
expect(infoMock).toHaveBeenCalledWith(
307307
expect.stringMatching('📝 adding comment to PR')

0 commit comments

Comments
 (0)