/
githubmirror
/
docusaurus
Обзор
Документация
Войти
/
githubmirror
/
docusaurus
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
packages/docusaurus-plugin-content-docs/src/sidebars/__tests__/normalization.test.ts
121 строка
4 KB
Sébastien Lorber
refactor(test): use explicit Vitest imports, disable globals (#12019)
15 май 2026, 11:01
Не верифицирован
15 май 2026, 11:01
057ab88
Код
Авторство
О чём код?
/** * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ import {describe, expect, it} from 'vitest'; import {normalizeSidebars} from '../normalization'; describe('normalization', () => { it('normalizes shorthands', () => { expect( normalizeSidebars({ sidebar: { Category: ['doc1', 'doc2'], 'Category 2': { 'Subcategory 1': ['doc3', 'doc4'], 'Subcategory 2': ['doc5', 'doc6'], }, }, }), ).toMatchSnapshot(); expect( normalizeSidebars({ sidebar: [ { type: 'link', label: 'Google', href: 'https://google.com', }, { 'Category 1': ['doc1', 'doc2'], 'Category 2': ['doc3', 'doc4'], }, ], }), ).toMatchSnapshot(); }); it('rejects some invalid cases', () => { expect(() => normalizeSidebars({ sidebar: { // @ts-expect-error: test Category: {type: 'autogenerated', dirName: 'foo'}, // @ts-expect-error: test Category2: {type: 'autogenerated', dirName: 'bar'}, }, }), ).toThrowErrorMatchingInlineSnapshot( `[Error: Invalid sidebar items collection \`{"type":"autogenerated","dirName":"foo"}\` in \`items\` of the category Category: it must either be an array of sidebar items or a shorthand notation (which doesn't contain a \`type\` property). See https://docusaurus.io/docs/sidebar/items for all valid syntaxes.]`, ); expect(() => normalizeSidebars({ sidebar: [ 'foo', { Category: { // @ts-expect-error: test type: 'category', items: ['bar', 'baz'], }, }, ], }), ).toThrowErrorMatchingInlineSnapshot( `[Error: Invalid sidebar items collection \`{"type":"category","items":["bar","baz"]}\` in \`items\` of the category Category: it must either be an array of sidebar items or a shorthand notation (which doesn't contain a \`type\` property). See https://docusaurus.io/docs/sidebar/items for all valid syntaxes.]`, ); expect(() => normalizeSidebars({ sidebar: [ 'foo', { // @ts-expect-error: test Category: 'bar', }, ], }), ).toThrowErrorMatchingInlineSnapshot( `[Error: Invalid sidebar items collection \`"bar"\` in \`items\` of the category Category: it must either be an array of sidebar items or a shorthand notation (which doesn't contain a \`type\` property). See https://docusaurus.io/docs/sidebar/items for all valid syntaxes.]`, ); expect(() => normalizeSidebars({ // @ts-expect-error: test sidebar: 'item', }), ).toThrowErrorMatchingInlineSnapshot( `[Error: Invalid sidebar items collection \`"item"\` in sidebar sidebar: it must either be an array of sidebar items or a shorthand notation (which doesn't contain a \`type\` property). See https://docusaurus.io/docs/sidebar/items for all valid syntaxes.]`, ); }); it('adds a translatable marker for labels defined in sidebars.js', () => { expect( normalizeSidebars({ sidebar: [ { type: 'doc', id: 'google', label: 'Google', }, { 'Category 1': ['doc1', 'doc2'], 'Category 2': [ 'doc3', 'doc4', { type: 'ref', id: 'msft', label: 'Microsoft', }, ], }, ], }), ).toMatchSnapshot(); }); });