|
14 | 14 | * limitations under the License.
|
15 | 15 | */
|
16 | 16 |
|
17 |
| -const {findMetaViewport} = require('../../lib/HtmlDomHelper'); |
| 17 | +const {findMetaViewport, findRuntimeScript} = require('../../lib/HtmlDomHelper'); |
18 | 18 | const treeParser = require('../../lib/TreeParser');
|
19 | 19 | const {firstChildByTag} = require('../../lib/NodeUtils');
|
20 | 20 |
|
@@ -54,3 +54,37 @@ test('findMetaViewport returns the correct tag', async () => {
|
54 | 54 | const result = findMetaViewport(head);
|
55 | 55 | expect(result).toEqual(head.children[3]);
|
56 | 56 | });
|
| 57 | + |
| 58 | +test('findRuntimeScript returns runtime v0.mjs', async () => { |
| 59 | + const root = await treeParser.parse(`<html><head> |
| 60 | + <meta charset="utf-8"> |
| 61 | + <script async src="https://cdn.ampproject.org/v0.mjs"></script> |
| 62 | + </head></html>`); |
| 63 | + const html = firstChildByTag(root, 'html'); |
| 64 | + const head = firstChildByTag(html, 'head'); |
| 65 | + const result = findRuntimeScript(head); |
| 66 | + expect(result).toEqual(head.children[3]); |
| 67 | +}); |
| 68 | + |
| 69 | +test('findRuntimeScript returns runtime v0.js', async () => { |
| 70 | + const root = await treeParser.parse(`<html><head> |
| 71 | + <meta charset="utf-8"> |
| 72 | + <script async src="https://cdn.ampproject.org/v0.js"></script> |
| 73 | + </head></html>`); |
| 74 | + const html = firstChildByTag(root, 'html'); |
| 75 | + const head = firstChildByTag(html, 'head'); |
| 76 | + const result = findRuntimeScript(head); |
| 77 | + expect(result).toEqual(head.children[3]); |
| 78 | +}); |
| 79 | + |
| 80 | +test('findRuntimeScript ignores empty src', async () => { |
| 81 | + const root = await treeParser.parse(`<html><head> |
| 82 | + <meta charset="utf-8"> |
| 83 | + <script id="amp-access" type="application/json"></script> |
| 84 | + <script async src="https://cdn.ampproject.org/v0.js"></script> |
| 85 | +</head></html>`); |
| 86 | + const html = firstChildByTag(root, 'html'); |
| 87 | + const head = firstChildByTag(html, 'head'); |
| 88 | + const result = findRuntimeScript(head); |
| 89 | + expect(result).toEqual(head.children[5]); |
| 90 | +}); |
0 commit comments