Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
GrantBirki committed Dec 29, 2023
1 parent fc0274e commit ebb8d2b
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 19 deletions.
4 changes: 4 additions & 0 deletions __tests__/fixtures/json/with_yaml/first/test1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"foo": 1,
"bar": "abc"
}
1 change: 1 addition & 0 deletions __tests__/fixtures/json/with_yaml/first/test1.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
key: value
4 changes: 4 additions & 0 deletions __tests__/fixtures/json/with_yaml/second/test2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"foo": 1,
"bar": "abc"
}
1 change: 1 addition & 0 deletions __tests__/fixtures/json/with_yaml/second/test2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
key: value
16 changes: 16 additions & 0 deletions __tests__/functions/json-validator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,22 @@ test('successfully validates a yaml file with a schema when yaml_as_json is true
})
})

test('successfully validates a json file and skips over the yaml one in the json processor', async () => {
process.env.INPUT_YAML_AS_JSON = 'false'
process.env.INPUT_FILES = `
__tests__/fixtures/json/with_yaml/**/test1.yml,
__tests__/fixtures/json/with_yaml/**/test*.json
`

expect(await jsonValidator(excludeMock)).toStrictEqual({
failed: 0,
passed: 2,
skipped: 0,
success: true,
violations: []
})
})

test('processes multiple files when yaml_as_json is true and also a mixture of other json files with yaml are present', async () => {
process.env.INPUT_YAML_AS_JSON = 'true'
process.env.INPUT_JSON_SCHEMA = ''
Expand Down
18 changes: 9 additions & 9 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions src/functions/json-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,15 @@ export async function jsonValidator(exclude) {
data = parse(readFileSync(fullPath, 'utf8'))

// if the file is a yaml file but it should not be treated as json
} else if (
yamlAsJson === false &&
(fullPath.endsWith(yamlExtension) ||
fullPath.endsWith(yamlExtensionShort))
) {
core.debug(
`the json-validator found a yaml file so it will be skipped here: '${fullPath}'`
)
continue
// } else if (
// yamlAsJson === false &&
// (fullPath.endsWith(yamlExtension) ||
// fullPath.endsWith(yamlExtensionShort))
// ) {
// core.debug(
// `the json-validator found a yaml file so it will be skipped here: '${fullPath}'`
// )
// continue

// if the file is a json file
} else {
Expand Down

0 comments on commit ebb8d2b

Please sign in to comment.