Skip to content

Commit

Permalink
add extension to return value
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasecdb committed Aug 7, 2019
1 parent d51340b commit cfaef0a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
16 changes: 10 additions & 6 deletions src/__tests__/react-amphtml.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,13 @@ describe('react-amphtml', (): void => {
const ampScriptSources = ampScripts.getScripts();

expect(ampScriptSources).toEqual(
expect.arrayContaining([
'https://cdn.ampproject.org/v0/amp-youtube-latest.js',
'https://cdn.ampproject.org/v0/amp-script-latest.js',
'https://cdn.ampproject.org/v0/amp-accordion-latest.js',
]),
expect.arrayContaining(
[
'https://cdn.ampproject.org/v0/amp-youtube-latest.js',
'https://cdn.ampproject.org/v0/amp-script-latest.js',
'https://cdn.ampproject.org/v0/amp-accordion-latest.js',
].map((src): any => expect.objectContaining({ src })),
),
);
});

Expand All @@ -87,7 +89,9 @@ describe('react-amphtml', (): void => {
const ampScriptsSources = ampScripts.getScripts();
expect(ampScriptsSources).toEqual(
expect.arrayContaining([
'https://cdn.ampproject.org/v0/amp-mustache-0.2.js',
expect.objectContaining({
src: 'https://cdn.ampproject.org/v0/amp-mustache-0.2.js',
}),
]),
);
});
Expand Down
14 changes: 11 additions & 3 deletions src/setup/AmpScripts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ import { Script, ScriptProps } from '../amphtml/amphtml';
import { getScriptSource } from '../amphtml/components/Script';
import { AMP, AMP_SRCS, Formats } from '../constants';

export interface ScriptSource {
src: string;
extension: string;
}

export default class AmpScripts {
private scripts: Map<string, ScriptProps>;

Expand All @@ -28,10 +33,13 @@ export default class AmpScripts {
this.scripts.set(extension, { specName: extension, version });
}

public getScripts(): string[] {
public getScripts(): ScriptSource[] {
return Array.from(this.scripts.values()).map(
({ specName, version, src }): string => {
return getScriptSource({ extension: specName, version, src });
({ specName, version, src }): ScriptSource => {
return {
src: getScriptSource({ extension: specName, version, src }),
extension: specName,
};
},
);
}
Expand Down

0 comments on commit cfaef0a

Please sign in to comment.