Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(rosetta): 'extract' does not translate samples in submodule READMEs #2712

Merged
merged 7 commits into from
Mar 18, 2021
12 changes: 12 additions & 0 deletions packages/jsii-rosetta/lib/jsii/assemblies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ export function allSnippetSources(
});
}

for (const [submoduleFqn, submodule] of Object.entries(
assembly.submodules ?? {},
)) {
if (submodule.readme) {
ret.push({
type: 'markdown',
markdown: submodule.readme.markdown,
where: removeSlashes(`${submoduleFqn}-README`),
});
}
}

if (assembly.types) {
Object.values(assembly.types).forEach((type) => {
emitDocs(type.docs, `${assembly.name}.${type.name}`);
Expand Down
27 changes: 27 additions & 0 deletions packages/jsii-rosetta/test/jsii/assemblies.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,33 @@ test('Extract snippet from README', () => {
expect(snippets[0].visibleSource).toEqual('someExample();');
});

test('Extract snippet from submodule READMEs', () => {
const snippets = Array.from(
allTypeScriptSnippets([
{
assembly: fakeAssembly({
submodules: {
'my.submodule': {
readme: {
markdown: [
'Before the example.',
'```ts',
'someExample();',
'```',
'After the example.',
].join('\n'),
},
},
},
}),
directory: path.join(__dirname, 'fixtures'),
},
]),
);

expect(snippets[0].visibleSource).toEqual('someExample();');
});

test('Extract snippet from type docstring', () => {
const snippets = Array.from(
allTypeScriptSnippets([
Expand Down