diff --git a/.github/allowed-actions.js b/.github/allowed-actions.js index 6450852204b9..9d2d7400e217 100644 --- a/.github/allowed-actions.js +++ b/.github/allowed-actions.js @@ -30,7 +30,7 @@ module.exports = [ 'rachmari/labeler@832d42ec5523f3c6d46e8168de71cd54363e3e2e', 'repo-sync/github-sync@3832fe8e2be32372e1b3970bbae8e7079edeec88', 'repo-sync/pull-request@33777245b1aace1a58c87a29c90321aa7a74bd7d', - 'rtCamp/action-slack-notify@e17352feaf9aee300bf0ebc1dfbf467d80438815', + 'someimportantcompany/github-actions-slack-message@0b470c14b39da4260ed9e3f9a4f1298a74ccdefd', 'tjenkinson/gh-action-auto-merge-dependency-updates@cee2ac0', 'EndBug/add-and-commit@9358097a71ad9fb9e2f9624c6098c89193d83575' ] diff --git a/.github/workflows/repo-freeze-reminders.yml b/.github/workflows/repo-freeze-reminders.yml index e6f7eb479eca..f3b166cd870e 100644 --- a/.github/workflows/repo-freeze-reminders.yml +++ b/.github/workflows/repo-freeze-reminders.yml @@ -14,11 +14,10 @@ jobs: if: github.repository == 'github/docs-internal' steps: - name: Send Slack notification if repo is frozen + uses: someimportantcompany/github-actions-slack-message@0b470c14b39da4260ed9e3f9a4f1298a74ccdefd if: ${{ env.FREEZE == 'true' }} - uses: rtCamp/action-slack-notify@e17352feaf9aee300bf0ebc1dfbf467d80438815 - env: - SLACK_WEBHOOK: ${{ secrets.DOCS_ALERTS_SLACK_WEBHOOK }} - SLACK_USERNAME: docs-repo-sync - SLACK_ICON_EMOJI: ':freezing_face:' - SLACK_COLOR: '#51A0D5' # Carolina Blue - SLACK_MESSAGE: All repo-sync runs will fail for ${{ github.repository }} because the repo is currently frozen! + with: + channel: ${{ secrets.DOCS_ALERTS_SLACK_CHANNEL_ID }} + bot-token: ${{ secrets.SLACK_DOCS_BOT_TOKEN }} + color: info + text: All repo-sync runs will fail for ${{ github.repository }} because the repo is currently frozen! diff --git a/.github/workflows/repo-sync-stalls.yml b/.github/workflows/repo-sync-stalls.yml index ea44f9244a40..2784f4703a97 100644 --- a/.github/workflows/repo-sync-stalls.yml +++ b/.github/workflows/repo-sync-stalls.yml @@ -45,11 +45,10 @@ jobs: } }) - name: Send Slack notification if workflow fails - uses: rtCamp/action-slack-notify@e17352feaf9aee300bf0ebc1dfbf467d80438815 - if: ${{ failure() }} - env: - SLACK_WEBHOOK: ${{ secrets.DOCS_ALERTS_SLACK_WEBHOOK }} - SLACK_USERNAME: docs-repo-sync - SLACK_ICON_EMOJI: ':ohno:' - SLACK_COLOR: '#B90E0A' # Crimson - SLACK_MESSAGE: Repo sync appears to be stalled for ${{github.repository}}. See https://github.com/${{github.repository}}/pulls?q=is%3Apr+is%3Aopen+repo+sync + uses: someimportantcompany/github-actions-slack-message@0b470c14b39da4260ed9e3f9a4f1298a74ccdefd + if: failure() + with: + channel: ${{ secrets.DOCS_ALERTS_SLACK_CHANNEL_ID }} + bot-token: ${{ secrets.SLACK_DOCS_BOT_TOKEN }} + color: failure + text: Repo sync appears to be stalled for ${{github.repository}}. See https://github.com/${{github.repository}}/pulls?q=is%3Apr+is%3Aopen+repo+sync diff --git a/.github/workflows/repo-sync.yml b/.github/workflows/repo-sync.yml index b33242e90be3..c1d0ef92d5a5 100644 --- a/.github/workflows/repo-sync.yml +++ b/.github/workflows/repo-sync.yml @@ -70,11 +70,10 @@ jobs: number: ${{ steps.find-pull-request.outputs.number }} - name: Send Slack notification if workflow fails - uses: rtCamp/action-slack-notify@e17352feaf9aee300bf0ebc1dfbf467d80438815 - if: ${{ failure() }} - env: - SLACK_WEBHOOK: ${{ secrets.DOCS_ALERTS_SLACK_WEBHOOK }} - SLACK_USERNAME: docs-repo-sync - SLACK_ICON_EMOJI: ':ohno:' - SLACK_COLOR: '#B90E0A' # Crimson - SLACK_MESSAGE: The last repo-sync run for ${{github.repository}} failed. See https://github.com/${{github.repository}}/actions?query=workflow%3A%22Repo+Sync%22 + uses: someimportantcompany/github-actions-slack-message@0b470c14b39da4260ed9e3f9a4f1298a74ccdefd + if: failure() + with: + channel: ${{ secrets.DOCS_ALERTS_SLACK_CHANNEL_ID }} + bot-token: ${{ secrets.SLACK_DOCS_BOT_TOKEN }} + color: failure + text: The last repo-sync run for ${{github.repository}} failed. See https://github.com/${{github.repository}}/actions?query=workflow%3A%22Repo+Sync%22 diff --git a/.github/workflows/sync-algolia-search-indices.yml b/.github/workflows/sync-algolia-search-indices.yml index a7f9ac3b4910..512b3b0e0c9c 100644 --- a/.github/workflows/sync-algolia-search-indices.yml +++ b/.github/workflows/sync-algolia-search-indices.yml @@ -33,8 +33,10 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: npm run sync-search - name: Send slack notification if workflow run fails - uses: rtCamp/action-slack-notify@e17352feaf9aee300bf0ebc1dfbf467d80438815 + uses: someimportantcompany/github-actions-slack-message@0b470c14b39da4260ed9e3f9a4f1298a74ccdefd if: failure() - env: - SLACK_WEBHOOK: ${{ secrets.DOCS_ALERTS_SLACK_WEBHOOK }} - SLACK_MESSAGE: The last Algolia workflow run for ${{github.repository}} failed. Search actions for `workflow:Algolia` + with: + channel: ${{ secrets.DOCS_ALERTS_SLACK_CHANNEL_ID }} + bot-token: ${{ secrets.SLACK_DOCS_BOT_TOKEN }} + color: failure + text: The last Algolia workflow run for ${{github.repository}} failed. Search actions for `workflow:Algolia` diff --git a/lib/page.js b/lib/page.js index c282f1792fd1..f9274f0119e8 100644 --- a/lib/page.js +++ b/lib/page.js @@ -1,5 +1,5 @@ const assert = require('assert') -const fs = require('fs') +const fs = require('fs').promises const path = require('path') const cheerio = require('cheerio') const patterns = require('./patterns') @@ -23,15 +23,30 @@ const slash = require('slash') const statsd = require('./statsd') class Page { - constructor (opts) { + static async init (opts) { assert(opts.relativePath, 'relativePath is required') assert(opts.basePath, 'basePath is required') + + const relativePath = slash(opts.relativePath) + const fullPath = slash(path.join(opts.basePath, relativePath)) + const raw = await fs.readFile(fullPath, 'utf8') + + return new Page({ ...opts, relativePath, fullPath, raw }) + } + + static async exists (path) { + try { + return await fs.stat(path) + } catch (err) { + if (err.code === 'ENOENT') return false + console.error(err) + } + } + + constructor (opts) { assert(opts.languageCode, 'languageCode is required') Object.assign(this, { ...opts }) - this.relativePath = slash(this.relativePath) - this.fullPath = slash(path.join(this.basePath, this.relativePath)) - this.raw = fs.readFileSync(this.fullPath, 'utf8') // TODO remove this when crowdin-support issue 66 has been resolved if (this.languageCode !== 'en' && this.raw.includes(': verdadero')) { diff --git a/lib/pages.js b/lib/pages.js index cdca1fae1e2a..4db70e7dd5cb 100644 --- a/lib/pages.js +++ b/lib/pages.js @@ -2,42 +2,50 @@ const path = require('path') const walk = require('walk-sync').entries const Page = require('./page') const languages = require('./languages') -const fs = require('fs') +const { mapLimit, filterLimit } = require('async') +const FILE_READ_LIMIT = 500 async function loadPageList () { const pageList = [] // load english pages const englishPath = path.join(__dirname, '..', languages.en.dir, 'content') - const englishPages = walk(englishPath) - .filter(({ relativePath }) => { - return relativePath.endsWith('.md') && - !relativePath.includes('README') - }) - .map(fileData => new Page({ ...fileData, languageCode: languages.en.code })) - + const englishPaths = walk(englishPath) + .filter(({ relativePath }) => + relativePath.endsWith('.md') && !relativePath.includes('README') + ) + const englishPages = await mapLimit( + englishPaths, + FILE_READ_LIMIT, + async fileData => await Page.init({ ...fileData, languageCode: languages.en.code }) + ) pageList.push(...englishPages) // load matching pages in other languages - for (const page of englishPages) { - for (const language of Object.values(languages)) { - if (language.code === 'en') continue - + let localizedPaths = Object.values(languages) + .filter(({ code }) => code !== 'en') + .map(language => { const basePath = path.join(__dirname, '..', language.dir, 'content') - const localizedPath = path.join(basePath, page.relativePath) - try { - fs.statSync(localizedPath) - } catch (_) { - continue - } - - pageList.push(new Page({ - relativePath: page.relativePath, + return englishPages.map(page => ({ basePath, + relativePath: page.relativePath, + localizedPath: path.join(basePath, page.relativePath), languageCode: language.code })) - } - } + }) + .flat() + localizedPaths = await filterLimit( + localizedPaths, + FILE_READ_LIMIT, + async ({ localizedPath }) => Page.exists(localizedPath) + ) + const localizedPages = await mapLimit( + localizedPaths, + FILE_READ_LIMIT, + async ({ basePath, relativePath, languageCode }) => + await Page.init({ basePath, relativePath, languageCode }) + ) + pageList.push(...localizedPages) return pageList } diff --git a/tests/browser/browser.js b/tests/browser/browser.js index 64fdb083ab33..aca6b864a720 100644 --- a/tests/browser/browser.js +++ b/tests/browser/browser.js @@ -3,6 +3,8 @@ const sleep = require('await-sleep') const querystring = require('querystring') describe('homepage', () => { + jest.setTimeout(60 * 1000) + test('should be titled "GitHub Documentation"', async () => { await page.goto('http://localhost:4001') await expect(page.title()).resolves.toMatch('GitHub Documentation') @@ -10,6 +12,8 @@ describe('homepage', () => { }) describe('algolia browser search', () => { + jest.setTimeout(60 * 1000) + it('works on the homepage', async () => { await page.goto('http://localhost:4001/en') await page.click('#search-input-container input[type="search"]') diff --git a/tests/content/crowdin-config.js b/tests/content/crowdin-config.js index 63301e09935d..fd26e74b42e7 100644 --- a/tests/content/crowdin-config.js +++ b/tests/content/crowdin-config.js @@ -4,6 +4,8 @@ const ignoredPagePaths = config.files[0].ignore const ignoredDataPaths = config.files[2].ignore describe('crowdin.yml config file', () => { + jest.setTimeout(60 * 1000) + let pages beforeAll(async (done) => { pages = await loadPages() diff --git a/tests/content/site-data-references.js b/tests/content/site-data-references.js index d9a38bc4e684..045e33843ba4 100644 --- a/tests/content/site-data-references.js +++ b/tests/content/site-data-references.js @@ -7,6 +7,8 @@ const fs = require('fs').promises const path = require('path') describe('data references', () => { + jest.setTimeout(60 * 1000) + let data, pages beforeAll(async (done) => { diff --git a/tests/routing/redirects.js b/tests/routing/redirects.js index 740cd67d55d0..b41a0888a8c1 100644 --- a/tests/routing/redirects.js +++ b/tests/routing/redirects.js @@ -17,8 +17,8 @@ describe('redirects', () => { done() }) - test('page.redirects is an array', () => { - const page = new Page({ + test('page.redirects is an array', async () => { + const page = await Page.init({ relativePath: 'github/collaborating-with-issues-and-pull-requests/about-branches.md', basePath: path.join(__dirname, '../../content'), languageCode: 'en' @@ -26,8 +26,8 @@ describe('redirects', () => { expect(isPlainObject(page.redirects)).toBe(true) }) - test('dotcom homepage page.redirects', () => { - const page = new Page({ + test('dotcom homepage page.redirects', async () => { + const page = await Page.init({ relativePath: 'github/index.md', basePath: path.join(__dirname, '../../content'), languageCode: 'en' @@ -41,7 +41,7 @@ describe('redirects', () => { }) test('converts single `redirect_from` strings values into arrays', async () => { - const page = new Page({ + const page = await Page.init({ relativePath: 'github/collaborating-with-issues-and-pull-requests/about-conversations-on-github.md', basePath: path.join(__dirname, '../../content'), languageCode: 'en' diff --git a/tests/unit/find-page.js b/tests/unit/find-page.js index bb422df1b3e5..5772db5f010d 100644 --- a/tests/unit/find-page.js +++ b/tests/unit/find-page.js @@ -8,7 +8,7 @@ describe('find page', () => { jest.setTimeout(1000 * 1000) test('falls back to the English page if it can\'t find a localized page', async () => { - const page = new Page({ + const page = await Page.init({ relativePath: 'page-that-does-not-exist-in-translations-dir.md', basePath: path.join(__dirname, '../fixtures'), languageCode: 'en' @@ -24,7 +24,7 @@ describe('find page', () => { }) test('follows redirects', async () => { - const page = new Page({ + const page = await Page.init({ relativePath: 'page-with-redirects.md', basePath: path.join(__dirname, '../fixtures'), languageCode: 'en' diff --git a/tests/unit/liquid-helpers.js b/tests/unit/liquid-helpers.js index ee6b8d3ecf17..41c54a2e3d27 100644 --- a/tests/unit/liquid-helpers.js +++ b/tests/unit/liquid-helpers.js @@ -5,6 +5,8 @@ const { set } = require('lodash') const nonEnterpriseDefaultVersion = require('../../lib/non-enterprise-default-version') describe('liquid helper tags', () => { + jest.setTimeout(60 * 1000) + const context = {} let pageMap beforeAll(async (done) => { diff --git a/tests/unit/page.js b/tests/unit/page.js index 5d1b46a0c3ad..44f98c94a567 100644 --- a/tests/unit/page.js +++ b/tests/unit/page.js @@ -15,14 +15,14 @@ const opts = { } describe('Page class', () => { - test('preserves file path info', () => { - const page = new Page(opts) + test('preserves file path info', async () => { + const page = await Page.init(opts) expect(page.relativePath).toBe('github/collaborating-with-issues-and-pull-requests/about-branches.md') expect(page.fullPath.includes(page.relativePath)).toBe(true) }) - test('does not error out on translated TOC with no links', () => { - const page = new Page({ + test('does not error out on translated TOC with no links', async () => { + const page = await Page.init({ relativePath: 'translated-toc-with-no-links-index.md', basePath: path.join(__dirname, '../fixtures'), languageCode: 'ja' @@ -31,30 +31,34 @@ describe('Page class', () => { }) describe('showMiniToc page property', () => { - const article = new Page({ - relativePath: 'sample-article.md', - basePath: path.join(__dirname, '../fixtures'), - languageCode: 'en' - }) + let article, articleWithFM, tocPage, mapTopic - const articleWithFM = new Page({ - showMiniToc: false, - relativePath: article.relativePath, - basePath: article.basePath, - languageCode: article.languageCode - }) + beforeAll(async () => { + article = await Page.init({ + relativePath: 'sample-article.md', + basePath: path.join(__dirname, '../fixtures'), + languageCode: 'en' + }) - const tocPage = new Page({ - relativePath: 'sample-toc-index.md', - basePath: path.join(__dirname, '../fixtures'), - languageCode: 'en' - }) + articleWithFM = await Page.init({ + showMiniToc: false, + relativePath: article.relativePath, + basePath: article.basePath, + languageCode: article.languageCode + }) + + tocPage = await Page.init({ + relativePath: 'sample-toc-index.md', + basePath: path.join(__dirname, '../fixtures'), + languageCode: 'en' + }) - const mapTopic = new Page({ - mapTopic: true, - relativePath: article.relativePath, - basePath: article.basePath, - languageCode: article.languageCode + mapTopic = await Page.init({ + mapTopic: true, + relativePath: article.relativePath, + basePath: article.basePath, + languageCode: article.languageCode + }) }) test('is true by default on articles', () => { @@ -76,7 +80,7 @@ describe('Page class', () => { describe('page.render(context)', () => { test('rewrites links to include the current language prefix and version', async () => { - const page = new Page(opts) + const page = await Page.init(opts) const context = { page: { version: nonEnterpriseDefaultVersion }, currentVersion: nonEnterpriseDefaultVersion, @@ -99,7 +103,7 @@ describe('Page class', () => { }) test('rewrites links in the intro to include the current language prefix and version', async () => { - const page = new Page(opts) + const page = await Page.init(opts) page.rawIntro = '[Pull requests](/articles/about-pull-requests)' const context = { page: { version: nonEnterpriseDefaultVersion }, @@ -114,7 +118,7 @@ describe('Page class', () => { }) test('does not rewrite links that include deprecated enterprise release numbers', async () => { - const page = new Page({ + const page = await Page.init({ relativePath: 'admin/enterprise-management/migrating-from-github-enterprise-1110x-to-2123.md', basePath: path.join(__dirname, '../../content'), languageCode: 'en' @@ -133,7 +137,7 @@ describe('Page class', () => { }) test('does not rewrite links to external redirects', async () => { - const page = new Page(opts) + const page = await Page.init(opts) page.markdown = `${page.markdown}\n\nSee [Capistrano](/capistrano).` const context = { page: { version: nonEnterpriseDefaultVersion }, @@ -150,7 +154,7 @@ describe('Page class', () => { // But they don't have access to our currently supported versions, which we're testing here. // This test ensures that this works as expected: {% if enterpriseServerVersions contains currentVersion %} test('renders the expected Enterprise Server versioned content', async () => { - const page = new Page({ + const page = await Page.init({ relativePath: 'page-versioned-for-all-enterprise-releases.md', basePath: path.join(__dirname, '../fixtures'), languageCode: 'en' @@ -184,27 +188,27 @@ describe('Page class', () => { }) }) - test('preserves `languageCode`', () => { - const page = new Page(opts) + test('preserves `languageCode`', async () => { + const page = await Page.init(opts) expect(page.languageCode).toBe('en') }) - test('parentProductId getter', () => { - let page = new Page({ + test('parentProductId getter', async () => { + let page = await Page.init({ relativePath: 'github/some-category/some-article.md', basePath: path.join(__dirname, '../fixtures/products'), languageCode: 'en' }) expect(page.parentProductId).toBe('github') - page = new Page({ + page = await Page.init({ relativePath: 'actions/some-category/some-article.md', basePath: path.join(__dirname, '../fixtures/products'), languageCode: 'en' }) expect(page.parentProductId).toBe('actions') - page = new Page({ + page = await Page.init({ relativePath: 'admin/some-category/some-article.md', basePath: path.join(__dirname, '../fixtures/products'), languageCode: 'en' @@ -213,26 +217,26 @@ describe('Page class', () => { }) describe('permalinks', () => { - test('is an array', () => { - const page = new Page(opts) + test('is an array', async () => { + const page = await Page.init(opts) expect(Array.isArray(page.permalinks)).toBe(true) }) - test('has a key for every supported enterprise version (and no deprecated versions)', () => { - const page = new Page(opts) + test('has a key for every supported enterprise version (and no deprecated versions)', async () => { + const page = await Page.init(opts) const pageVersions = page.permalinks.map(permalink => permalink.pageVersion) expect(enterpriseServerReleases.supported.every(version => pageVersions.includes(`enterprise-server@${version}`))).toBe(true) expect(enterpriseServerReleases.deprecated.every(version => !pageVersions.includes(`enterprise-server@${version}`))).toBe(true) }) - test('sets versioned values', () => { - const page = new Page(opts) + test('sets versioned values', async () => { + const page = await Page.init(opts) expect(page.permalinks.find(permalink => permalink.pageVersion === nonEnterpriseDefaultVersion).href).toBe(`/en/${nonEnterpriseDefaultVersion}/github/collaborating-with-issues-and-pull-requests/about-branches`) expect(page.permalinks.find(permalink => permalink.pageVersion === `enterprise-server@${enterpriseServerReleases.oldestSupported}`).href).toBe(`/en/enterprise-server@${enterpriseServerReleases.oldestSupported}/github/collaborating-with-issues-and-pull-requests/about-branches`) }) - test('homepage permalinks', () => { - const page = new Page({ + test('homepage permalinks', async () => { + const page = await Page.init({ relativePath: 'index.md', basePath: path.join(__dirname, '../../content'), languageCode: 'en' @@ -242,8 +246,8 @@ describe('Page class', () => { expect(page.permalinks.find(permalink => permalink.pageVersion === 'homepage').href).toBe('/en') }) - test('permalinks for dotcom-only pages', () => { - const page = new Page({ + test('permalinks for dotcom-only pages', async () => { + const page = await Page.init({ relativePath: 'github/getting-started-with-github/signing-up-for-a-new-github-account.md', basePath: path.join(__dirname, '../../content'), languageCode: 'en' @@ -252,8 +256,8 @@ describe('Page class', () => { expect(page.permalinks.length).toBe(1) }) - test('permalinks for enterprise-only pages', () => { - const page = new Page({ + test('permalinks for enterprise-only pages', async () => { + const page = await Page.init({ relativePath: 'products/admin/some-category/some-article.md', basePath: path.join(__dirname, '../fixtures'), languageCode: 'en' @@ -264,8 +268,8 @@ describe('Page class', () => { expect(pageVersions.includes(nonEnterpriseDefaultVersion)).toBe(false) }) - test('permalinks for non-GitHub.com products without Enterprise versions', () => { - const page = new Page({ + test('permalinks for non-GitHub.com products without Enterprise versions', async () => { + const page = await Page.init({ relativePath: 'products/actions/some-category/some-article.md', basePath: path.join(__dirname, '../fixtures'), languageCode: 'en' @@ -274,8 +278,8 @@ describe('Page class', () => { expect(page.permalinks.length).toBe(1) }) - test('permalinks for non-GitHub.com products with Enterprise versions', () => { - const page = new Page({ + test('permalinks for non-GitHub.com products with Enterprise versions', async () => { + const page = await Page.init({ relativePath: '/insights/installing-and-configuring-github-insights/about-github-insights.md', basePath: path.join(__dirname, '../../content'), languageCode: 'en' @@ -318,7 +322,7 @@ describe('Page class', () => { }) test('fixes translated frontmatter that includes verdadero', async () => { - const page = new Page({ + const page = await Page.init({ relativePath: 'article-with-mislocalized-frontmatter.md', basePath: path.join(__dirname, '../fixtures'), languageCode: 'ja' @@ -333,7 +337,7 @@ describe('Page class', () => { // Note this test will go out of date when we deprecate 2.20 test('pages that apply to newer enterprise versions', async () => { - const page = new Page({ + const page = await Page.init({ relativePath: 'github/administering-a-repository/comparing-releases.md', basePath: path.join(__dirname, '../../content'), languageCode: 'en' @@ -343,7 +347,7 @@ describe('Page class', () => { }) test('index page', async () => { - const page = new Page({ + const page = await Page.init({ relativePath: 'index.md', basePath: path.join(__dirname, '../../content'), languageCode: 'en' @@ -352,7 +356,7 @@ describe('Page class', () => { }) test('enterprise admin index page', async () => { - const page = new Page({ + const page = await Page.init({ relativePath: 'admin/index.md', basePath: path.join(__dirname, '../../content'), languageCode: 'en' @@ -366,50 +370,50 @@ describe('Page class', () => { describe('catches errors thrown in Page class', () => { test('frontmatter parsing error', () => { - function getPage () { - return new Page({ + async function getPage () { + return await Page.init({ relativePath: 'page-with-frontmatter-error.md', basePath: path.join(__dirname, '../fixtures'), languageCode: 'en' }) } - expect(getPage).toThrowError('invalid frontmatter entry') + expect(getPage).rejects.toThrowError('invalid frontmatter entry') }) test('missing versions frontmatter', () => { - function getPage () { - return new Page({ + async function getPage () { + return await Page.init({ relativePath: 'page-with-missing-product-versions.md', basePath: path.join(__dirname, '../fixtures'), languageCode: 'en' }) } - expect(getPage).toThrowError('versions') + expect(getPage).rejects.toThrowError('versions') }) test('English page with a version in frontmatter that its parent product is not available in', () => { - function getPage () { - return new Page({ + async function getPage () { + return await Page.init({ relativePath: 'admin/some-category/some-article-with-mismatched-versions-frontmatter.md', basePath: path.join(__dirname, '../fixtures/products'), languageCode: 'en' }) } - expect(getPage).toThrowError(/`versions` frontmatter.*? product is not available in/) + expect(getPage).rejects.toThrowError(/`versions` frontmatter.*? product is not available in/) }) test('non-English page with a version in frontmatter that its parent product is not available in', () => { - function getPage () { - return new Page({ + async function getPage () { + return await Page.init({ relativePath: 'admin/some-category/some-article-with-mismatched-versions-frontmatter.md', basePath: path.join(__dirname, '../fixtures/products'), languageCode: 'es' }) } - expect(getPage).toThrowError(/`versions` frontmatter.*? product is not available in/) + expect(getPage).rejects.toThrowError(/`versions` frontmatter.*? product is not available in/) }) }) diff --git a/tests/unit/pages.js b/tests/unit/pages.js index f27b73ff1be2..bb405b5e9c61 100644 --- a/tests/unit/pages.js +++ b/tests/unit/pages.js @@ -10,6 +10,8 @@ const entities = new Entities() const { chain, difference } = require('lodash') describe('pages module', () => { + jest.setTimeout(60 * 1000) + let pages beforeAll(async (done) => {