Skip to content

Commit

Permalink
add tests for resolveModuleName
Browse files Browse the repository at this point in the history
  • Loading branch information
slorber committed Dec 3, 2021
1 parent 0b6fb24 commit ddd3385
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
34 changes: 33 additions & 1 deletion packages/docusaurus/src/server/__tests__/moduleShorthand.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import {getNamePatterns} from '../moduleShorthand';
import {getNamePatterns, resolveModuleName} from '../moduleShorthand';

describe('getNamePatterns', () => {
test('should resolve plain names', () => {
Expand Down Expand Up @@ -56,3 +56,35 @@ describe('getNamePatterns', () => {
]);
});
});

describe('resolveModuleName', () => {
test('should resolve longhand', () => {
expect(
resolveModuleName('@docusaurus/plugin-content-docs', require, 'plugin'),
).toBeDefined();
});

test('should resolve shorthand', () => {
expect(resolveModuleName('content-docs', require, 'plugin')).toBeDefined();
});

test('should throw good error message for longhand', () => {
expect(() =>
resolveModuleName('@docusaurus/plugin-content-doc', require, 'plugin'),
).toThrowErrorMatchingInlineSnapshot(`
"Docusaurus was unable to resolve the \\"@docusaurus/plugin-content-doc\\" plugin. Make sure one of the following packages are installed:
- @docusaurus/plugin-content-doc
- @docusaurus/docusaurus-plugin-plugin-content-doc"
`);
});

test('should throw good error message for shorthand', () => {
expect(() => resolveModuleName('content-doc', require, 'plugin'))
.toThrowErrorMatchingInlineSnapshot(`
"Docusaurus was unable to resolve the \\"content-doc\\" plugin. Make sure one of the following packages are installed:
- content-doc
- @docusaurus/plugin-content-doc
- docusaurus-plugin-content-doc"
`);
});
});
2 changes: 1 addition & 1 deletion packages/docusaurus/src/server/moduleShorthand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ export function resolveModuleName(
} catch (e) {}
}
throw new Error(`Docusaurus was unable to resolve the "${moduleName}" ${moduleType}. Make sure one of the following packages are installed:
${modulePatterns.map((module) => `- ${module}`).join('\n')}`);
${modulePatterns.map((module) => `- ${module}`).join('\n')}`);
}

0 comments on commit ddd3385

Please sign in to comment.