Skip to content

Commit

Permalink
Create a translations test suite (github#30000)
Browse files Browse the repository at this point in the history
* Scaffold files for migration

* Move user-agent into unit suite

* Nothing to move from browser suite

* Migrate tests to translations/content

* Migrate existing translation test to meta

* No graphql tests to migrate

* Migrate lint-translation-reporter

* Migrate lint-translation-reporter

* Remove languages-schema, unused

* Restore languages-schema

* Restore languages-schema

* Migrate rendering

* Migrate routing

* Migrate most of unit

* Remove dead files, comment out tests that aren't expected to work yet

* Migrate from get-redirect

* Migrate page and pages

* Migrate linting code

* Fix lint issues

* Found a few more

* Run prettier

* Move crowdin-config test and helper

* Update crowdin-config.js

* Remove translation linting, crowdin config lint, reduce file count

* Remove test that's been skipped for a year

* Restore linting with note to remove later

* Update lint-translation-reporter.js

* Clean up rendering suite

* Update rendering.js

* Remove excessive describe blocks

* Redirect tests

* Clean up unit

* Remove test that's never called

* Don't compare early access

* Rename test suites

* Update "content" tests

* Update files.js

* Update search.js

* Update files.js

* Update files.js
  • Loading branch information
heiskr authored Aug 25, 2022
1 parent df6b782 commit 303d519
Show file tree
Hide file tree
Showing 43 changed files with 210 additions and 1,008 deletions.
2 changes: 1 addition & 1 deletion components/article/PlatformPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { sendEvent, EventType } from 'components/lib/events'
import { useRouter } from 'next/router'

import { useArticleContext } from 'components/context/ArticleContext'
import parseUserAgent from 'components/lib/user-agent'
import { parseUserAgent } from 'components/lib/user-agent'

const platforms = [
{ id: 'mac', label: 'Mac' },
Expand Down
2 changes: 1 addition & 1 deletion components/lib/events.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable camelcase */
import { v4 as uuidv4 } from 'uuid'
import Cookies from 'js-cookie'
import parseUserAgent from './user-agent'
import { parseUserAgent } from './user-agent'

const COOKIE_NAME = '_docs-events'

Expand Down
2 changes: 1 addition & 1 deletion components/lib/user-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const BROWSER_REGEXPS = [
/ms(ie)\/([^\s)]+)/i,
]

export default function parseUserAgent(ua = navigator.userAgent) {
export function parseUserAgent(ua = navigator.userAgent) {
ua = ua.toLowerCase()
const osRe = OS_REGEXPS.find((re) => re.test(ua))
let [, os = 'other', os_version = '0'] = (osRe && ua.match(osRe)) || []
Expand Down
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ let reporters = ['default']

if (testTranslation) {
// only use custom reporter if we are linting translations
// Remove this when removing translations directory B504EDD0
reporters = ['<rootDir>/tests/helpers/lint-translation-reporter.js']
} else if (isActions) {
reporters.push('jest-github-actions-reporter')
Expand Down
2 changes: 2 additions & 0 deletions script/i18n/lint-translation-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
//
// [end-readme]

// Remove this when removing translations directory B504EDD0

import { execSync } from 'child_process'
import { program } from 'commander'
import fs from 'fs'
Expand Down
54 changes: 0 additions & 54 deletions tests/content/crowdin-config.js

This file was deleted.

18 changes: 0 additions & 18 deletions tests/content/featured-links.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { fileURLToPath } from 'url'

import { beforeAll, jest } from '@jest/globals'
import nock from 'nock'
import japaneseCharacters from 'japanese-characters'

import { getDOM, getJSON } from '../helpers/e2etest.js'
import enterpriseServerReleases from '../../lib/enterprise-server-releases.js'
Expand Down Expand Up @@ -49,23 +48,6 @@ describe('featuredLinks', () => {
).toBe(true)
})

test('localized intro links link to localized pages', async () => {
const $jaPages = await getDOM('/ja')
const $enPages = await getDOM('/en')
const $jaFeaturedLinks = $jaPages('[data-testid=article-list] a')
const $enFeaturedLinks = $enPages('[data-testid=article-list] a')
expect($jaFeaturedLinks.length).toBe($enFeaturedLinks.length)
expect($jaFeaturedLinks.eq(0).attr('href').startsWith('/ja')).toBe(true)

// Footer translations change very rarely if ever, so we can more
// reliably test those text values for the language
const footerText = []
$jaPages('footer a').each((index, element) => {
footerText.push($jaPages(element).text())
})
expect(footerText.some((elem) => japaneseCharacters.presentIn(elem)))
})

test('Enterprise user intro links have expected values', async () => {
const $ = await getDOM(`/en/enterprise/${enterpriseServerReleases.latest}/user/get-started`)
const $featuredLinks = $('[data-testid=article-list] a')
Expand Down
7 changes: 0 additions & 7 deletions tests/content/glossary.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,6 @@ describe('glossaries', () => {
})
})

test('non-English external glossary is in correct order', async () => {
const vals = loadSiteData().ja.site.data.glossaries.external
vals.forEach((val, i) => {
expect(val.term.localeCompare(vals[i + 1], 'ja')).toBeGreaterThan(0)
})
})

test('candidates all have a term, but no description', async () => {
expect(glossaries.candidates.length).toBeGreaterThan(20)
glossaries.candidates.forEach((entry) => {
Expand Down
10 changes: 0 additions & 10 deletions tests/content/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,6 @@ describe('search', () => {
})
})
})

test('has Lunr index for every language for dotcom', async () => {
expect(languageCodes.length).toBeGreaterThan(0)
languageCodes.forEach((languageCode) => {
const indexName = `${namePrefix}-dotcom-${languageCode}`
const indexRecordName = `${indexName}-records`
expect(lunrIndexNames.includes(indexName)).toBe(true)
expect(lunrIndexNames.includes(indexRecordName)).toBe(true)
})
})
})

function getDate(date) {
Expand Down
11 changes: 0 additions & 11 deletions tests/content/site-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ describe('siteData module (English)', () => {

test('sets a top-level key for each language', async () => {
expect('en' in data).toEqual(true)
expect('ja' in data).toEqual(true)
})

test('includes English variables', async () => {
Expand All @@ -35,16 +34,6 @@ describe('siteData module (English)', () => {
expect(reusable).toBe('1. Change the current working directory to your local repository.')
})

test('includes Japanese variables', async () => {
const prodName = get(data, 'ja.site.data.variables.product.prodname_dotcom')
expect(prodName).toBe('GitHub')
})

test('includes Japanese reusables', async () => {
const reusable = get(data, 'ja.site.data.reusables.audit_log.octicon_icon')
expect(reusable.includes('任意のページの左上で')).toBe(true)
})

test('all Liquid tags are valid', async () => {
const dataMap = flat(data)
for (const key in dataMap) {
Expand Down
15 changes: 0 additions & 15 deletions tests/content/site-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import revalidator from 'revalidator'
import schema from '../helpers/schemas/site-tree-schema.js'
import EnterpriseServerReleases from '../../lib/enterprise-server-releases.js'
import { loadSiteTree } from '../../lib/page-data.js'
import japaneseCharacters from 'japanese-characters'
import nonEnterpriseDefaultVersion from '../../lib/non-enterprise-default-version.js'
import { jest } from '@jest/globals'

Expand All @@ -18,7 +17,6 @@ describe('siteTree', () => {

test('has language codes as top-level keys', () => {
expect('en' in siteTree).toBe(true)
expect('ja' in siteTree).toBe(true)
})

test('object order and structure', () => {
Expand All @@ -29,19 +27,6 @@ describe('siteTree', () => {
})

describe('localized titles', () => {
// skipped because it has rendering errors. See translations/log/ja-resets.csv
test.skip('titles for categories', () => {
const japaneseTitle =
siteTree.ja[nonEnterpriseDefaultVersion].childPages[0].childPages[0].page.title
expect(typeof japaneseTitle).toBe('string')
expect(japaneseCharacters.presentIn(japaneseTitle)).toBe(true)

const englishTitle =
siteTree.en[nonEnterpriseDefaultVersion].childPages[0].childPages[0].page.title
expect(typeof englishTitle).toBe('string')
expect(japaneseCharacters.presentIn(englishTitle)).toBe(false)
})

test('articles that include site data in liquid templating', async () => {
const ghesLatest = `enterprise-server@${latestEnterpriseRelease}`
const ghesSiteTree = siteTree.en[ghesLatest]
Expand Down
12 changes: 0 additions & 12 deletions tests/helpers/crowdin-config.js

This file was deleted.

7 changes: 2 additions & 5 deletions tests/helpers/e2etest.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export async function get(
followRedirects: false,
followAllRedirects: false,
headers: {},
cookieJar: undefined,
}
) {
const method = opts.method || 'get'
Expand All @@ -22,7 +21,6 @@ export async function get(
body: opts.body,
headers: opts.headers,
retry: { limit: 0 },
cookieJar: opts.cookieJar,
throwHttpErrors: false,
followRedirect: opts.followAllRedirects || opts.followRedirects,
},
Expand Down Expand Up @@ -62,14 +60,13 @@ export function post(route, opts) {

export async function getDOM(
route,
{ headers, allow500s, allow404, cookieJar } = {
{ headers, allow500s, allow404 } = {
headers: undefined,
allow500s: false,
allow404: false,
cookieJar: undefined,
}
) {
const res = await get(route, { followRedirects: true, headers, cookieJar })
const res = await get(route, { followRedirects: true, headers })
if (!allow500s && res.status >= 500) {
throw new Error(`Server error (${res.status}) on ${route}`)
}
Expand Down
2 changes: 2 additions & 0 deletions tests/helpers/lint-translation-reporter.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Remove this when removing translations directory B504EDD0

import chalk from 'chalk'
import stripAnsi from 'strip-ansi'
import { groupBy } from 'lodash-es'
Expand Down
48 changes: 0 additions & 48 deletions tests/helpers/schemas/languages-schema.js

This file was deleted.

1 change: 1 addition & 0 deletions tests/linting/lint-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ if (!process.env.TEST_TRANSLATION) {
)
learningTracksToLint = zip(learningTracksYamlRelPaths, learningTracksYamlAbsPaths)
} else {
// Remove this `else` when removing translations directory B504EDD0
// get all translated markdown or yaml files by comparing files changed to main branch
const changedFilesRelPaths = execSync(
'git -c diff.renameLimit=10000 diff --name-only origin/main',
Expand Down
Loading

0 comments on commit 303d519

Please sign in to comment.