Skip to content

Commit

Permalink
Add a new test that checks every YAML document can be parsed (github#…
Browse files Browse the repository at this point in the history
…23053)

* fix: update lint-translation script to point to the correct test

This change reflects its new home in `test/linting/lint-files.js` as committed in github/docs-internal@f0d17c3 on April 28, 2021.

* test: check release notes can be parsed a single YAML document

* test: check yaml content parsability

* test: check parsability for all YAML content

* refactor: move annotations to lint yaml content suite

* fix: revert file contents

* fix: remove local test script

* refactor: lowercase yaml file type

* fix: remove null assignment to stay consistent with other variables

* refactor: update reference name to caught error

* fix: remove the royal we from annotation

* refactor: update annotation for improved readability

* fix: add missing preposition
  • Loading branch information
francisfuzz committed Nov 23, 2021
1 parent 74c9412 commit 9c4ef4d
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@
"link-check-server": "cross-env NODE_ENV=production ENABLED_LANGUAGES='en' PORT=4002 node server.mjs",
"link-check-test": "cross-env node script/check-internal-links.js",
"lint": "eslint '**/*.{js,mjs,ts,tsx}'",
"lint-translation": "cross-env TEST_TRANSLATION=true jest content/lint-files",
"lint-translation": "cross-env NODE_OPTIONS=--experimental-vm-modules TEST_TRANSLATION=true jest tests/linting/lint-files.js",
"pa11y-ci": "pa11y-ci",
"pa11y-test": "start-server-and-test browser-test-server 4001 pa11y-ci",
"prebrowser-test": "npm run build",
Expand Down
2 changes: 1 addition & 1 deletion script/i18n/lint-translation-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import program from 'commander'

// Set up supported linting check types and their corresponding commands.
const CHECK_COMMANDS = {
parsing: 'TEST_TRANSLATION=true npx jest linting/lint-files',
parsing: 'npm run lint-translation',
rendering: 'script/i18n/test-render-translation.js',
}
const SUPPORTED_CHECK_TYPES = Object.keys(CHECK_COMMANDS)
Expand Down
58 changes: 53 additions & 5 deletions tests/linting/lint-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -679,10 +679,18 @@ describe('lint yaml content', () => {
if (ymlToLint.length < 1) return
describe.each(ymlToLint)('%s', (yamlRelPath, yamlAbsPath) => {
let dictionary, isEarlyAccess, ifversionConditionals, ifConditionals
// This variable is used to determine if the file was parsed successfully.
// When `yaml.load()` fails to parse the file, it is overwritten with the error message.
// `false` is intentionally chosen since `null` and `undefined` are valid return values.
let dictionaryError = false

beforeAll(async () => {
const fileContents = await readFileAsync(yamlAbsPath, 'utf8')
dictionary = yaml.load(fileContents, { filename: yamlRelPath })
try {
dictionary = yaml.load(fileContents, { filename: yamlRelPath })
} catch (error) {
dictionaryError = error
}

isEarlyAccess = yamlRelPath.split('/').includes('early-access')

Expand All @@ -691,6 +699,10 @@ describe('lint yaml content', () => {
ifConditionals = getLiquidConditionals(fileContents, 'if')
})

test('it can be parsed as a single yaml document', () => {
expect(dictionaryError).toBe(false)
})

test('ifversion conditionals are valid in yaml', async () => {
const errors = validateIfversionConditionals(ifversionConditionals)
expect(errors.length, errors.join('\n')).toBe(0)
Expand Down Expand Up @@ -907,10 +919,19 @@ describe('lint GHES release notes', () => {
if (ghesReleaseNotesToLint.length < 1) return
describe.each(ghesReleaseNotesToLint)('%s', (yamlRelPath, yamlAbsPath) => {
let dictionary
let dictionaryError = false

beforeAll(async () => {
const fileContents = await readFileAsync(yamlAbsPath, 'utf8')
dictionary = yaml.load(fileContents, { filename: yamlRelPath })
try {
dictionary = yaml.load(fileContents, { filename: yamlRelPath })
} catch (error) {
dictionaryError = error
}
})

it('can be parsed as a single yaml document', () => {
expect(dictionaryError).toBe(false)
})

it('matches the schema', () => {
Expand Down Expand Up @@ -954,10 +975,19 @@ describe('lint GHAE release notes', () => {
const currentWeeksFound = []
describe.each(ghaeReleaseNotesToLint)('%s', (yamlRelPath, yamlAbsPath) => {
let dictionary
let dictionaryError = false

beforeAll(async () => {
const fileContents = await readFileAsync(yamlAbsPath, 'utf8')
dictionary = yaml.load(fileContents, { filename: yamlRelPath })
try {
dictionary = yaml.load(fileContents, { filename: yamlRelPath })
} catch (error) {
dictionaryError = error
}
})

it('can be parsed as a single yaml document', () => {
expect(dictionaryError).toBe(false)
})

it('matches the schema', () => {
Expand Down Expand Up @@ -1008,10 +1038,19 @@ describe('lint learning tracks', () => {
if (learningTracksToLint.length < 1) return
describe.each(learningTracksToLint)('%s', (yamlRelPath, yamlAbsPath) => {
let dictionary
let dictionaryError = false

beforeAll(async () => {
const fileContents = await readFileAsync(yamlAbsPath, 'utf8')
dictionary = yaml.load(fileContents, { filename: yamlRelPath })
try {
dictionary = yaml.load(fileContents, { filename: yamlRelPath })
} catch (error) {
dictionaryError = error
}
})

it('can be parsed as a single yaml document', () => {
expect(dictionaryError).toBe(false)
})

it('matches the schema', () => {
Expand Down Expand Up @@ -1083,10 +1122,19 @@ describe('lint feature versions', () => {
if (featureVersionsToLint.length < 1) return
describe.each(featureVersionsToLint)('%s', (yamlRelPath, yamlAbsPath) => {
let dictionary
let dictionaryError = false

beforeAll(async () => {
const fileContents = await readFileAsync(yamlAbsPath, 'utf8')
dictionary = yaml.load(fileContents, { filename: yamlRelPath })
try {
dictionary = yaml.load(fileContents, { filename: yamlRelPath })
} catch (error) {
dictionaryError = error
}
})

it('can be parsed as a single yaml document', () => {
expect(dictionaryError).toBe(false)
})

it('matches the schema', () => {
Expand Down

0 comments on commit 9c4ef4d

Please sign in to comment.