1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | Object.defineProperty(exports, "__esModule", { value: true });
|
16 | const chai_1 = require("chai");
|
17 | const polymer_analyzer_1 = require("polymer-analyzer");
|
18 | const path = require("path");
|
19 | const util_1 = require("./util");
|
20 | const polymer_project_1 = require("../polymer-project");
|
21 | const streams_1 = require("../streams");
|
22 | const testProjectRoot = path.resolve('test-fixtures/test-project');
|
23 | suite('PolymerProject', () => {
|
24 | let defaultProject;
|
25 | const unroot = ((p) => p.substring(testProjectRoot.length + 1));
|
26 | setup(() => {
|
27 | defaultProject = new polymer_project_1.PolymerProject({
|
28 | root: 'test-fixtures/test-project/',
|
29 | entrypoint: 'index.html',
|
30 | shell: 'shell.html',
|
31 | sources: [
|
32 | 'source-dir/**',
|
33 | ],
|
34 | });
|
35 | });
|
36 | test('will not throw an exception when created with minimum options', () => {
|
37 | new polymer_project_1.PolymerProject({
|
38 | root: 'test-fixtures/test-project/',
|
39 | });
|
40 | });
|
41 | test('reads sources', (done) => {
|
42 | const files = [];
|
43 | defaultProject.sources()
|
44 | .on('data', (f) => files.push(f))
|
45 | .on('end', () => {
|
46 | const names = files.map((f) => unroot(f.path));
|
47 | const expected = [
|
48 | 'index.html',
|
49 | 'shell.html',
|
50 | path.join('source-dir', 'my-app.html'),
|
51 | path.join('source-dir', 'shell.js'),
|
52 | path.join('source-dir', 'style.css'),
|
53 | ];
|
54 | chai_1.assert.deepEqual(names.sort(), expected);
|
55 | done();
|
56 | });
|
57 | });
|
58 | test('the sources & dependencies streams remain paused until use', () => {
|
59 |
|
60 | const sourcesStream = defaultProject.sources();
|
61 | chai_1.assert.isNull(util_1.getFlowingState(sourcesStream));
|
62 | sourcesStream.on('data', () => { });
|
63 | chai_1.assert.isTrue(util_1.getFlowingState(sourcesStream));
|
64 |
|
65 | const dependencyStream = defaultProject.dependencies();
|
66 | chai_1.assert.isNull(util_1.getFlowingState(dependencyStream));
|
67 | dependencyStream.on('data', () => { });
|
68 | chai_1.assert.isTrue(util_1.getFlowingState(dependencyStream));
|
69 | });
|
70 | suite('.bundler()', () => {
|
71 | test('returns a different bundler each time', () => {
|
72 | const bundlerA = defaultProject.bundler();
|
73 | const bundlerB = defaultProject.bundler();
|
74 | chai_1.assert.notEqual(bundlerA, bundlerB);
|
75 | });
|
76 | test('takes options to configure bundler', () => {
|
77 | const urlResolver = new polymer_analyzer_1.FsUrlResolver('test-fixtures/test-project');
|
78 | const bundler = defaultProject.bundler({
|
79 | analyzer: new polymer_analyzer_1.Analyzer({
|
80 | urlResolver,
|
81 | urlLoader: new polymer_analyzer_1.FsUrlLoader('test-fixtures/test-project')
|
82 | }),
|
83 | excludes: ['bower_components/loads-external-dependencies.html'].map((p) => urlResolver.resolve(p)),
|
84 | inlineCss: true,
|
85 | inlineScripts: false,
|
86 | rewriteUrlsInTemplates: true,
|
87 | stripComments: true,
|
88 | strategy: (b) => b,
|
89 |
|
90 |
|
91 | urlMapper: (b) => new Map(b.map((b) => ['x', b])),
|
92 | });
|
93 | chai_1.assert.isOk(bundler);
|
94 | });
|
95 | });
|
96 | suite('.dependencies()', () => {
|
97 | test('reads dependencies', (done) => {
|
98 | const files = [];
|
99 | const dependencyStream = defaultProject.dependencies();
|
100 | dependencyStream.on('data', (f) => files.push(f));
|
101 | dependencyStream.on('end', () => {
|
102 | const names = files.map((f) => unroot(f.path));
|
103 | const expected = [
|
104 | path.join('bower_components', 'dep.html'),
|
105 | path.join('bower_components', 'loads-external-dependencies.html'),
|
106 | ];
|
107 | chai_1.assert.deepEqual(names.sort(), expected);
|
108 | done();
|
109 | });
|
110 | });
|
111 | const testName = 'reads dependencies in a monolithic (non-shell) application without timing out';
|
112 | test(testName, () => {
|
113 | const project = new polymer_project_1.PolymerProject({
|
114 | root: testProjectRoot,
|
115 | entrypoint: 'index.html',
|
116 | sources: [
|
117 | 'source-dir/**',
|
118 | 'index.html',
|
119 | 'shell.html',
|
120 | ],
|
121 | });
|
122 | const sourcesStream = project.sources();
|
123 | const dependencyStream = project.dependencies();
|
124 | sourcesStream.on('data', () => { });
|
125 | dependencyStream.on('data', () => { });
|
126 | return Promise.all([streams_1.waitFor(project.sources()), streams_1.waitFor(dependencyStream)]);
|
127 | });
|
128 | test('reads dependencies and includes additionally provided files', (done) => {
|
129 | const files = [];
|
130 | const projectWithIncludedDeps = new polymer_project_1.PolymerProject({
|
131 | root: testProjectRoot,
|
132 | entrypoint: 'index.html',
|
133 | shell: 'shell.html',
|
134 | sources: [
|
135 | 'source-dir/**',
|
136 | ],
|
137 | extraDependencies: [
|
138 | 'bower_components/unreachable*',
|
139 | ],
|
140 | });
|
141 | const dependencyStream = projectWithIncludedDeps.dependencies();
|
142 | dependencyStream.on('data', (f) => files.push(f));
|
143 | dependencyStream.on('error', done);
|
144 | dependencyStream.on('end', () => {
|
145 | const names = files.map((f) => unroot(f.path));
|
146 | const expected = [
|
147 | path.join('bower_components', 'dep.html'),
|
148 | path.join('bower_components', 'loads-external-dependencies.html'),
|
149 | path.join('bower_components', 'unreachable-dep.html'),
|
150 | ];
|
151 | chai_1.assert.deepEqual(names.sort(), expected);
|
152 | done();
|
153 | });
|
154 | });
|
155 | });
|
156 | });
|
157 |
|
\ | No newline at end of file |