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

Run our integration tests with optimized JS. #1395

Merged
merged 1 commit into from
Jan 12, 2016
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ script:
- gulp test
# Integration tests with all saucelabs browsers
- gulp test --saucelabs --integration
- gulp test --saucelabs --integration --compiled
# All unit tests with an old chrome (best we can do right now to pass tests
# and not start relying on new features).
- gulp test --saucelabs --oldchrome
5 changes: 4 additions & 1 deletion build-system/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ var karma = {
configFile: karmaConf,
singleRun: true,
client: {
captureConsole: false
captureConsole: false,
amp: {
useCompiledJs: false
}
}
},
firefox: {
Expand Down
9 changes: 9 additions & 0 deletions build-system/tasks/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ gulp.task('test', 'Runs tests in chrome', ['build'], function(done) {
c.files = config.testPaths;
}

if (argv.compiled) {
if (!argv.integration) {
throw new Error('Compiled tests are only supported for integration tests');
}
c.client.amp.useCompiledJs = true;
}

karma.start(c, done);
}, {
options: {
Expand All @@ -93,6 +100,8 @@ gulp.task('test', 'Runs tests in chrome', ['build'], function(done) {
'safari': ' Runs tests in Safari',
'firefox': ' Runs tests in Firefox',
'integration': 'Run only integration tests.',
'compiled': 'Changes integration tests to use production JS ' +
'binaries for execution',
'oldchrome': 'Runs test with an old chrome. Saucelabs only.',
}
});
4 changes: 4 additions & 0 deletions test/_init_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ import {adopt} from '../src/runtime';

adopt(global);

// Make amp section in karma config readable by tests.
global.ampTestRuntimeConfig = parent.karma.config.amp;


// Hack for skipping tests on Travis that don't work there.
// Get permission before use!
/**
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/carousels.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
font-family: Arial;
}
</style>
<script async custom-element="amp-carousel" src="/base/dist/v0/amp-carousel-0.1.js"></script>
<script async custom-element="amp-carousel" src="/base/dist/v0/amp-carousel-0.1.max.js"></script>
<style>body {opacity: 0}</style><noscript><style>body {opacity: 1}</style></noscript>
<script async src="/base/dist/amp.js"></script>
</head>
Expand Down
23 changes: 23 additions & 0 deletions testing/iframe.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export function createFixtureIframe(fixture, initialIframeHeight, done) {
if (!html) {
throw new Error('Cannot find fixture: ' + fixture);
}
html = maybeSwitchToCompiledJs(html);
let firstLoad = true;
window.ENABLE_LOG = true;
// This global function will be called by the iframe immediately when it
Expand Down Expand Up @@ -288,3 +289,25 @@ export function expectBodyToBecomeVisible(win) {
|| win.document.body.style.opacity == '1');
});
}

/**
* Takes a HTML document that is pointing to unminified JS and HTML
* binaries and massages the URLs to pointed to compiled binaries
* instead.
* @param {string} html
* @return {string}
*/
function maybeSwitchToCompiledJs(html) {
if (window.ampTestRuntimeConfig.useCompiledJs) {
return html
// Main JS
.replace(/\/dist\/amp\.js/, '/dist/v0.js')
// Extensions
.replace(/\.max\.js/g, '.js')
// 3p html binary
.replace(/\.max\.html/g, '.html')
// 3p path
.replace(/dist\.3p\/current\//g, 'dist.3p/current-min/');
}
return html;
}