Skip to content

Commit

Permalink
add integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
tiendt committed Jul 28, 2017
1 parent 1730d70 commit 21402f1
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 1 deletion.
14 changes: 13 additions & 1 deletion build-system/amp4test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,15 @@
'use strict';

const app = module.exports = require('express').Router();
let extensionString;

app.get('/compose-doc', function(req, res) {

// for (const extension of req.query.extensions) {
// extensionString += '<script async custom-element=' + extension + 'src="https://cdn.ampproject.org/v0/' + extension + '-0.1.js"></script>';
// }
//extensionString = req.query.extensions;
console.log(req.query.extensions);
res.send(`
<!doctype html>
<html ⚡>
Expand All @@ -26,7 +33,12 @@ app.get('/compose-doc', function(req, res) {
<link rel="canonical" href="http://nonblocking.io/" >
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
<script async src="/dist/${process.env.SERVE_MODE == 'compiled' ? 'v0' : 'amp'}.js"></script>
<script async src="/dist/${process.env.SERVE_MODE == 'compiled' ? 'v0' : 'amp'}.js"></script>`

//+ extensionString +
+ '<script async custom-element=' + req.query.extensions + 'src="https://cdn.ampproject.org/v0/' + req.query.extensions + '-0.1.js"></script>'
+
`
</head>
<body>
${req.query.body}
Expand Down
60 changes: 60 additions & 0 deletions test/fixtures/analytics-error-reporting.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<!doctype html>
<html >
<head>
<meta charset="utf-8">
<title>Lorem Ipsum</title>
<link rel="canonical" href="amps.html" >
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<script async src="https://cdn.ampproject.org/v0.js"></script>
<script async custom-element="amp-analytics" src="https://cdn.ampproject.org/v0/amp-analytics-0.1.js"></script>
<style amp-custom>
body {
font-family: 'Georgia', Serif;
}
h1 {
padding: 10px;
}
p {
padding: 15px;
}
</style>
</head>
<body>
<h1>Lorem Ipsum</h1>
<amp-img
src="img/sea@1x.jpg"
srcset="img/sea@1x.jpg 1x, img/sea@2x.jpg 2x"
alt="Fusce pretium tempor justo, vitae consequat dolor maximus eget."
placeholder
width="360" height="216" layout="responsive"
role='img'>
</amp-img>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Curabitur ullamcorper turpis vel commodo scelerisque. Phasellus
luctus nunc ut elit cursus, et imperdiet diam vehicula.
Duis et nisi sed urna blandit bibendum et sit amet erat.
</p>

<amp-analytics>
<script type="application/json">
{
"requests": {
"user-error": "http://localhost:9876/amp4test/request-bank/deposit/user-error-report-Mozilla%2F5.0%20(Macintosh%3B%20Intel%20Mac%20OS%20X%2010_12_6)%20AppleWebKit%2F537.36%20(KHTML%2C%20like%20Gecko)%20Chrome%2F59.0.3071.115%20Safari%2F537.36"
},
"triggers": {
"user-error": {
"on": "user-error",
"request": "user-error"
}
}
}
</script>
</amp-analytics>

<amp-pixel src="https://foo.com/tracker/foo"
layout="nodisplay"
referrerpolicy="referrer-fail"></amp-pixel>

</body>
</html>
105 changes: 105 additions & 0 deletions test/integration/test-user-error-reporting.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/**
* Copyright 2017 The AMP HTML Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS-IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import {
withdrawRequest,
//composeDocWithExtension,
depositRequestUrl,
} from '../../testing/test-helper';

import {createFixtureIframe} from '../../testing/iframe.js';


describe('user-error-reporting', function() {
//this.timeout(15000);

// describes.integration('amp-pixel integration test', {
// body: `<amp-analytics>
// {
// "requests": {
// "user-error": "${depositRequestUrl('user-error-repor')}"
// },
//
// "triggers": {
// "user-error": {
// "on": "user-error",
// "request": "user-error"
// }
// },
//
// "transport": {
// "beacon": "false",
// "xhrpost": "false",
// "image": "true"
// }
// }
// </amp-analytics>
// <amp-pixel src="${depositRequestUrl('has-referrer')}">`,
// }, env => {
// it('should keep referrer if no referrerpolicy specified', () => {
// return withdrawRequest(env.win, 'has-referrer').then(request => {
// expect(request.headers.referer).to.be.ok;
// });
// });
// });


// describes.integration('user-error-reporting integration test', {
// extensions: 'amp-analytics',
// body:
// `<amp-analytics><script type="application/json">
// {
// "requests": {
// "user-error": "${depositRequestUrl('user-error-report')}"
// },
// "triggers": {
// "user-error": {
// "on": "user-error",
// "request": "user-error"
// }
// }
// }
// </script></amp-analytics>
//
// <amp-pixel src="https://foo.com/tracker/foo"
// layout="nodisplay"
// referrerpolicy="referrer-fail"></amp-pixel>`,
// }, env => {
// it('should ping correct host', () => {
// return withdrawRequest(env.win, 'user-error-report').then(request => {
// expect(request).to.be.ok;
// });
// });
// });

describe('User-Error', function() {
let fixture;

beforeEach(() => {
return createFixtureIframe(
'test/fixtures/analytics-error-reporting.html', 500)
.then(f => {
fixture = f;
});
});

it('should ping correct host', () => {
return withdrawRequest(fixture.win, 'user-error-report').then(request => {
expect(request).to.be.ok;
});
});
});
});
3 changes: 3 additions & 0 deletions testing/test-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,6 @@ export function withdrawRequest(win, id) {
credentials: 'omit',
}).then(res => res.json());
}



0 comments on commit 21402f1

Please sign in to comment.