Skip to content

Commit

Permalink
refactor(core): move browserContext and docusaurusContext out of clie…
Browse files Browse the repository at this point in the history
…nt exports (#6955)
  • Loading branch information
Josh-Cena authored Mar 22, 2022
1 parent 6b3d94a commit 0a5354d
Show file tree
Hide file tree
Showing 17 changed files with 17 additions and 19 deletions.
4 changes: 3 additions & 1 deletion jest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ export default {
'^.+\\.(css|jpe?g|png|svg|webp)$': '<rootDir>/jest/emptyModule.ts',

// Using src instead of lib, so we always get fresh source
'@docusaurus/(browserContext|BrowserOnly|ComponentCreator|constants|docusaurusContext|ExecutionEnvironment|Head|Interpolate|isInternalUrl|Link|Noop|renderRoutes|router|Translate|use.*)':
'@docusaurus/(BrowserOnly|ComponentCreator|constants|ExecutionEnvironment|Head|Interpolate|isInternalUrl|Link|Noop|renderRoutes|router|Translate|use.*)':
'@docusaurus/core/src/client/exports/$1',

// TODO create dedicated testing utility for mocking contexts
// Maybe point to a fixture?
'@generated/.*': '<rootDir>/jest/emptyModule.ts',
// TODO use "projects" + multiple configs if we work on another theme?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
useSidebarBreadcrumbs,
} from '../docsUtils';
import {StaticRouter} from 'react-router-dom';
import {Context} from '@docusaurus/docusaurusContext';
import {Context} from '@docusaurus/core/src/client/docusaurusContext';
import type {
PropSidebar,
PropSidebarItem,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import React from 'react';
import {useTitleFormatter} from '../generalUtils';
import {renderHook} from '@testing-library/react-hooks';
import {Context} from '@docusaurus/docusaurusContext';
import {Context} from '@docusaurus/core/src/client/docusaurusContext';
import type {DocusaurusContext} from '@docusaurus/types';

describe('useTitleFormatter', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import React from 'react';
import {useAlternatePageUtils} from '../useAlternatePageUtils';
import {renderHook} from '@testing-library/react-hooks';
import {StaticRouter} from 'react-router-dom';
import {Context} from '@docusaurus/docusaurusContext';
import {Context} from '@docusaurus/core/src/client/docusaurusContext';
import type {DocusaurusContext} from '@docusaurus/types';

describe('useAlternatePageUtils', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import React from 'react';
import {useLocalPathname} from '../useLocalPathname';
import {renderHook} from '@testing-library/react-hooks';
import {StaticRouter} from 'react-router-dom';
import {Context} from '@docusaurus/docusaurusContext';
import {Context} from '@docusaurus/core/src/client/docusaurusContext';
import type {DocusaurusContext} from '@docusaurus/types';

describe('useLocalPathname', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {jest} from '@jest/globals';
import React from 'react';
import {usePluralForm} from '../usePluralForm';
import {renderHook} from '@testing-library/react-hooks';
import {Context} from '@docusaurus/docusaurusContext';
import {Context} from '@docusaurus/core/src/client/docusaurusContext';
import type {DocusaurusContext} from '@docusaurus/types';

describe('usePluralForm', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus/src/client/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import React from 'react';

import routes from '@generated/routes';
import renderRoutes from './exports/renderRoutes';
import {BrowserContextProvider} from './exports/browserContext';
import {DocusaurusContextProvider} from './exports/docusaurusContext';
import {BrowserContextProvider} from './browserContext';
import {DocusaurusContextProvider} from './docusaurusContext';
import PendingNavigation from './PendingNavigation';
import BaseUrlIssueBanner from './baseUrlIssueBanner/BaseUrlIssueBanner';
import SiteMetadataDefaults from './SiteMetadataDefaults';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import React from 'react';
import {renderHook} from '@testing-library/react-hooks/server';
import {BrowserContextProvider} from '../browserContext';
import useIsBrowser from '../useIsBrowser';
import useIsBrowser from '../exports/useIsBrowser';

describe('BrowserContextProvider', () => {
const {result, hydrate} = renderHook(() => useIsBrowser(), {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import React from 'react';
import {renderHook} from '@testing-library/react-hooks/server';
import {DocusaurusContextProvider} from '../docusaurusContext';
import useDocusaurusContext from '../useDocusaurusContext';
import useDocusaurusContext from '../exports/useDocusaurusContext';

// This test currently isn't quite useful because the @generated aliases point
// to the empty modules. Maybe we can point that to fixtures in the future.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import React from 'react';
import renderer from 'react-test-renderer';
import BrowserOnly from '../BrowserOnly';
import {Context} from '../browserContext';
import {Context} from '../../browserContext';

describe('<BrowserOnly>', () => {
const originalEnv = process.env;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import React from 'react';
import {renderHook} from '@testing-library/react-hooks';
import useBaseUrl, {useBaseUrlUtils} from '../useBaseUrl';
import {Context} from '../docusaurusContext';
import {Context} from '../../docusaurusContext';
import type {DocusaurusContext} from '@docusaurus/types';
import type {BaseUrlOptions} from '@docusaurus/useBaseUrl';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import useGlobalData, {
useAllPluginInstancesData,
usePluginData,
} from '../useGlobalData';
import {Context} from '../docusaurusContext';
import {Context} from '../../docusaurusContext';

describe('useGlobalData', () => {
it('returns global data from context', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import {useContext} from 'react';
import {Context} from './docusaurusContext';
import {Context} from '../docusaurusContext';
import type {DocusaurusContext} from '@docusaurus/types';

export default function useDocusaurusContext(): DocusaurusContext {
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus/src/client/exports/useIsBrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import {useContext} from 'react';
import {Context} from './browserContext';
import {Context} from '../browserContext';

export default function useIsBrowser(): boolean {
return useContext(Context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ exports[`base webpack config creates webpack aliases 1`] = `
"@docusaurus/Link": "../../../../client/exports/Link.tsx",
"@docusaurus/Noop": "../../../../client/exports/Noop.ts",
"@docusaurus/Translate": "../../../../client/exports/Translate.tsx",
"@docusaurus/browserContext": "../../../../client/exports/browserContext.tsx",
"@docusaurus/constants": "../../../../client/exports/constants.ts",
"@docusaurus/docusaurusContext": "../../../../client/exports/docusaurusContext.tsx",
"@docusaurus/isInternalUrl": "../../../../client/exports/isInternalUrl.ts",
"@docusaurus/renderRoutes": "../../../../client/exports/renderRoutes.ts",
"@docusaurus/router": "../../../../client/exports/router.ts",
Expand Down Expand Up @@ -61,9 +59,7 @@ exports[`getDocusaurusAliases() returns appropriate webpack aliases 1`] = `
"@docusaurus/Link": "../../client/exports/Link.tsx",
"@docusaurus/Noop": "../../client/exports/Noop.ts",
"@docusaurus/Translate": "../../client/exports/Translate.tsx",
"@docusaurus/browserContext": "../../client/exports/browserContext.tsx",
"@docusaurus/constants": "../../client/exports/constants.ts",
"@docusaurus/docusaurusContext": "../../client/exports/docusaurusContext.tsx",
"@docusaurus/isInternalUrl": "../../client/exports/isInternalUrl.ts",
"@docusaurus/renderRoutes": "../../client/exports/renderRoutes.ts",
"@docusaurus/router": "../../client/exports/router.ts",
Expand Down

0 comments on commit 0a5354d

Please sign in to comment.