UNPKG

3.9 kBJavaScriptView Raw
1/*
2 * Copyright 2018 Adobe. All rights reserved.
3 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License. You may obtain a copy
5 * of the License at http://www.apache.org/licenses/LICENSE-2.0
6 *
7 * Unless required by applicable law or agreed to in writing, software distributed under
8 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9 * OF ANY KIND, either express or implied. See the License for the specific language
10 * governing permissions and limitations under the License.
11 */
12/* eslint-env mocha */
13const assert = require('assert');
14const winston = require('winston');
15const { pipe } = require('../src/defaults/html.pipe.js');
16
17const logger = winston.createLogger({
18 // tune this for debugging
19 level: 'debug',
20 // and turn this on if you want the output
21 silent: true,
22 format: winston.format.simple(),
23 transports: [
24 new winston.transports.Console(),
25 ],
26});
27
28const params = {
29 path: '/hello.md',
30 __ow_method: 'get',
31 owner: 'trieloff',
32 __ow_headers: {
33 'X-Forwarded-Port': '443',
34 'X-CDN-Request-Id': '2a208a89-e071-44cf-aee9-220880da4c1e',
35 'Fastly-Client': '1',
36 'X-Forwarded-Host': 'runtime.adobe.io',
37 'Upgrade-Insecure-Requests': '1',
38 Host: 'controller-a',
39 Connection: 'close',
40 'Fastly-SSL': '1',
41 'X-Request-Id': 'RUss5tPdgOfw74a68aNc24FeTipGpVfW',
42 'X-Branch': 'master',
43 'Accept-Language': 'en-US, en;q=0.9, de;q=0.8',
44 'X-Forwarded-Proto': 'https',
45 'Fastly-Orig-Accept-Encoding': 'gzip',
46 'X-Varnish': '267021320',
47 DNT: '1',
48 'X-Forwarded-For':
49 '192.147.117.11, 157.52.92.27, 23.235.46.33, 10.64.221.107',
50 'X-Host': 'www.primordialsoup.life',
51 Accept:
52 'text/html, application/xhtml+xml, application/xml;q=0.9, image/webp, image/apng, */*;q=0.8',
53 'X-Real-IP': '10.64.221.107',
54 'X-Forwarded-Server': 'cache-lcy19249-LCY, cache-iad2127-IAD',
55 'Fastly-Client-IP': '192.147.117.11',
56 'Perf-Br-Req-In': '1529585370.116',
57 'X-Timer': 'S1529585370.068237,VS0,VS0',
58 'Fastly-FF':
59 'dc/x3e9z8KMmlHLQr8BEvVMmTcpl3y2YY5y6gjSJa3g=!LCY!cache-lcy19249-LCY, dc/x3e9z8KMmlHLQr8BEvVMmTcpl3y2YY5y6gjSJa3g=!LCY!cache-lcy19227-LCY, dc/x3e9z8KMmlHLQr8BEvVMmTcpl3y2YY5y6gjSJa3g=!IAD!cache-iad2127-IAD, dc/x3e9z8KMmlHLQr8BEvVMmTcpl3y2YY5y6gjSJa3g=!IAD!cache-iad2133-IAD',
60 'Accept-Encoding': 'gzip',
61 'User-Agent':
62 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36',
63 },
64 repo: 'soupdemo',
65 ref: 'master',
66 selector: 'md',
67 branch: 'master',
68};
69
70const secrets = {
71 REPO_RAW_ROOT: 'https://raw.githubusercontent.com/',
72};
73
74describe('Testing HTML Pipeline', () => {
75 it('html.pipe is a function', () => {
76 assert.ok(pipe);
77 assert.strictEqual(typeof pipe, 'function');
78 });
79
80 it('html.pipe makes HTTP requests', (done) => {
81 const result = pipe(
82 ({ content }) => {
83 // this is the main function (normally it would be the template function)
84 // but we use it to assert that pre-processing has happened
85 assert.ok(content.body);
86 assert.ok(content.mdast);
87 assert.ok(content.meta);
88 assert.equal('Medium', content.meta.template);
89 assert.equal('Project Helix', content.intro);
90 assert.equal('Bill, Welcome to the future', content.title);
91 // and return a different status code
92 return { response: { status: 201, body: content.html } };
93 },
94 {},
95 {
96 request: { params },
97 secrets,
98 logger,
99 },
100 );
101
102 result.then((res) => {
103 assert.equal(201, res.statusCode);
104 assert.equal('text/html', res.headers['Content-Type']);
105 assert.equal('<', res.body[0]);
106 assert.ok(res.body.match(/srcset/));
107 done();
108 });
109 });
110});