Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow firebase for 3p frames #25092

Merged
merged 7 commits into from Oct 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -333,6 +333,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