1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
13 | return new (P || (P = Promise))(function (resolve, reject) {
|
14 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
15 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
16 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
17 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
18 | });
|
19 | };
|
20 | Object.defineProperty(exports, "__esModule", { value: true });
|
21 | const chai_1 = require("chai");
|
22 | const polymer_analyzer_1 = require("polymer-analyzer");
|
23 | const polymer_project_1 = require("../polymer-project");
|
24 | const prefetch_links_1 = require("../prefetch-links");
|
25 | const util_1 = require("./util");
|
26 | const mergeStream = require('merge-stream');
|
27 | suite('prefetch-links', () => {
|
28 | suite('AddPrefetchLinks', () => {
|
29 | test('adds prefetch links for transitive deps of unbundled', () => __awaiter(this, void 0, void 0, function* () {
|
30 | const project = new polymer_project_1.PolymerProject({
|
31 | root: 'test-fixtures/bundle-project/',
|
32 | entrypoint: 'index.html',
|
33 | });
|
34 | const files = yield util_1.emittedFiles(mergeStream(project.sources(), project.dependencies())
|
35 | .pipe(project.addPrefetchLinks()), project.config.root);
|
36 | const html = files.get('index.html').contents.toString();
|
37 |
|
38 | chai_1.assert.notInclude(html, '<link rel="prefetch" href="/simple-import.html">');
|
39 |
|
40 |
|
41 | chai_1.assert.include(html, '<link rel="prefetch" href="/simple-script.js">');
|
42 | chai_1.assert.include(html, '<link rel="prefetch" href="/simple-style.css">');
|
43 | chai_1.assert.include(html, '<link rel="prefetch" href="/simple-import-2.html">');
|
44 | }));
|
45 | test('add prefetch links for transitive deps of bundled', () => __awaiter(this, void 0, void 0, function* () {
|
46 | const project = new polymer_project_1.PolymerProject({
|
47 | root: 'test-fixtures/bundle-project/',
|
48 | entrypoint: 'index.html',
|
49 | fragments: ['simple-import.html'],
|
50 | });
|
51 | const files = yield util_1.emittedFiles(mergeStream(project.sources(), project.dependencies())
|
52 | .pipe(project.bundler({ inlineScripts: false }))
|
53 | .pipe(project.addPrefetchLinks()), project.config.root);
|
54 | const expectedFiles = ['index.html', 'simple-import.html', 'simple-script.js'];
|
55 | chai_1.assert.deepEqual(expectedFiles, [...files.keys()].sort());
|
56 | const html = files.get('index.html').contents.toString();
|
57 |
|
58 |
|
59 | chai_1.assert.notInclude(html, '<link rel="prefetch" href="/simple-import.html">');
|
60 |
|
61 |
|
62 |
|
63 |
|
64 | chai_1.assert.include(html, '<link rel="prefetch" href="/simple-script.js">');
|
65 | }));
|
66 | test('prefetch links do not include lazy dependencies', () => __awaiter(this, void 0, void 0, function* () {
|
67 | const project = new polymer_project_1.PolymerProject({
|
68 | root: 'test-fixtures/bundler-data/',
|
69 | entrypoint: 'index.html',
|
70 | });
|
71 | const files = yield util_1.emittedFiles(mergeStream(project.sources(), project.dependencies())
|
72 | .pipe(project.addPrefetchLinks()), project.config.root);
|
73 | const html = files.get('index.html').contents.toString();
|
74 |
|
75 | chai_1.assert.notInclude(html, '<link rel="prefetch" href="/shell.html">');
|
76 |
|
77 |
|
78 | chai_1.assert.include(html, '<link rel="prefetch" href="/framework.html">');
|
79 |
|
80 | chai_1.assert.notInclude(html, '<link rel="prefetch" href="/entrypoint-a.html">');
|
81 | chai_1.assert.notInclude(html, '<link rel="prefetch" href="/entrypoint-b.html">');
|
82 | chai_1.assert.notInclude(html, '<link rel="prefetch" href="/entrypoint-c.html">');
|
83 | chai_1.assert.notInclude(html, '<link rel="prefetch" href="/common-dependency.html">');
|
84 | chai_1.assert.notInclude(html, '<link rel="prefetch" href="/lazy-dependency.html">');
|
85 | }));
|
86 | test('prefetch links are relative when base tag present', () => __awaiter(this, void 0, void 0, function* () {
|
87 | const project = new polymer_project_1.PolymerProject({
|
88 | root: 'test-fixtures/differential-serving/',
|
89 | entrypoint: 'index.html',
|
90 | fragments: ['shell.html'],
|
91 | });
|
92 | const files = yield util_1.emittedFiles(mergeStream(project.sources(), project.dependencies())
|
93 | .pipe(project.bundler({ inlineScripts: false }))
|
94 | .pipe(project.addPrefetchLinks()), project.config.root);
|
95 | const html = files.get('index.html').contents.toString();
|
96 |
|
97 |
|
98 |
|
99 | chai_1.assert.include(html, '<link rel="prefetch" href="shell-stuff/external-script.js">');
|
100 | }));
|
101 | });
|
102 | suite('createLinks', () => {
|
103 | const urlResolver = new polymer_analyzer_1.FsUrlResolver('');
|
104 | const html = '<html><body>foo</body></html>';
|
105 | const htmlWithBase = '<html><base href="/base/"><body>foo</body></html>';
|
106 | const deps = new Set([
|
107 | 'bower_components/polymer/polymer.html',
|
108 | 'src/my-icons.html',
|
109 | ].map((u) => urlResolver.resolve(u)));
|
110 | test('with no base tag and absolute true', () => {
|
111 | const url = 'index.html';
|
112 | const expected = ('<html>' +
|
113 | '<link rel="prefetch" href="/bower_components/polymer/polymer.html">' +
|
114 | '<link rel="prefetch" href="/src/my-icons.html">' +
|
115 | '<body>foo</body></html>');
|
116 | const actual = prefetch_links_1.createLinks(urlResolver, html, urlResolver.resolve(url), deps, true);
|
117 | chai_1.assert.equal(actual, expected);
|
118 | });
|
119 | test('with a base tag and absolute true', () => {
|
120 | const url = 'index.html';
|
121 | const expected = ('<html><base href="/base/">' +
|
122 | '<link rel="prefetch" href="bower_components/polymer/polymer.html">' +
|
123 | '<link rel="prefetch" href="src/my-icons.html">' +
|
124 | '<body>foo</body></html>');
|
125 | const actual = prefetch_links_1.createLinks(urlResolver, htmlWithBase, urlResolver.resolve(url), deps, true);
|
126 | chai_1.assert.equal(actual, expected);
|
127 | });
|
128 | });
|
129 | });
|
130 |
|
\ | No newline at end of file |