Skip to content

Commit

Permalink
allow firebase for 3p frames (ampproject#25092)
Browse files Browse the repository at this point in the history
* allow firebase for 3p frames

* Prepend AMP_CONFIG to integration.js

* Add comments

* Add f.js for consistency

* localize changes to firebase only

* Wait for async function

* Add documentation
  • Loading branch information
cathyxz authored and joshuarrrr committed Oct 22, 2019
1 parent db3d8c6 commit f17233e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
23 changes: 12 additions & 11 deletions build-system/tasks/firebase.js
Expand Up @@ -21,6 +21,7 @@ const path = require('path');
const {build} = require('./build');
const {clean} = require('./clean');
const {dist} = require('./dist');
const {enableLocalTesting} = require('./helpers');

async function walk(dest) {
const filelist = [];
Expand All @@ -47,16 +48,6 @@ async function copyAndReplaceUrls(src, dest) {
await Promise.all(promises);
}

async function modifyThirdPartyUrl() {
const filePath = 'firebase/dist/amp.js';
const data = await fs.readFile('firebase/dist/amp.js', 'utf8');
const result = data.replace(
'self.AMP_CONFIG={',
'self.AMP_CONFIG={"thirdPartyUrl":location.origin,'
);
await fs.writeFile(filePath, result, 'utf8');
}

async function firebase() {
if (!argv.nobuild) {
await clean();
Expand All @@ -75,6 +66,7 @@ async function firebase() {
});
await replaceUrls('firebase/index.html');
} else {
log(colors.green('Copying test/manual and examples folders.'));
await Promise.all([
copyAndReplaceUrls('test/manual', 'firebase/manual'),
copyAndReplaceUrls('examples', 'firebase/examples'),
Expand All @@ -85,8 +77,15 @@ async function firebase() {
fs.copy('dist', 'firebase/dist', {overwrite: true}),
fs.copy('dist.3p/current', 'firebase/dist.3p/current', {overwrite: true}),
]);

if (argv.fortesting) {
await Promise.all([
enableLocalTesting('firebase/dist.3p/current/integration.js'),
enableLocalTesting('firebase/dist/amp.js'),
]);
}

await Promise.all([
modifyThirdPartyUrl(),
fs.copyFile('firebase/dist/ww.max.js', 'firebase/dist/ww.js', {
overwrite: true,
}),
Expand Down Expand Up @@ -122,4 +121,6 @@ firebase.flags = {
'file': 'File to deploy to firebase as index.html',
'min': 'Source from minified files',
'nobuild': 'Skips the gulp build|dist step.',
'fortesting':
'Expects an env var AMP_TESTING_HOST and writes this to AMP_CONFIG',
};
10 changes: 10 additions & 0 deletions contributing/TESTING.md
Expand Up @@ -337,6 +337,16 @@ After deploying, you can access your project publically at its hosting URL `http

Additionally, you can create multiple projects and switch between them in the CLI using `firebase use your-project-name`.

#### Testing Ads
Testing ads in deployed demos requires whitelisting of 3p urls. You can do this by adding your intended deployment hostname as an environemnt variable `AMP_TESTING_HOST` and using the `fortesting` flag. For example:

```
export AMP_TESTING_HOST="my-project.firebaseapp.com"
gulp firebase --fortesting
firebase deploy
```
This will write "my-project.firebaseapp.com" as a third party url to relevant attributes in `AMP_CONFIG`, which is prepended to `amp.js` and `integration.js` files in the firebase folder. If you're curious about how this is done, feel free to inspect `build-system/tasks/firebase.js`.

## End-to-End Tests

You can run and create E2E tests locally during development. Currently tests only run on Chrome, but support for additional browsers is underway. These tests have not been added to our CI build yet - but they will be added soon.
Expand Down

0 comments on commit f17233e

Please sign in to comment.