Skip to content

Commit

Permalink
Move integration tests from test/functional/ to test/integration/ (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
rsimha committed Aug 4, 2017
1 parent e3785bf commit 009bc86
Show file tree
Hide file tree
Showing 10 changed files with 255 additions and 247 deletions.
2 changes: 1 addition & 1 deletion build-system/config.js
Expand Up @@ -59,7 +59,7 @@ var testPaths = commonTestPaths.concat([
var unitTestPaths = commonTestPaths.concat([
'test/functional/**/*.js',
'ads/**/test/test-*.js',
'extensions/**/test/**/*.js',
'extensions/**/test/*.js',
]);

var integrationTestPaths = commonTestPaths.concat([
Expand Down
3 changes: 1 addition & 2 deletions build-system/tasks/presubmit-checks.js
Expand Up @@ -855,8 +855,7 @@ var requiredTerms = {
*/
function isInTestFolder(path) {
var dirs = path.split('/');
var folder = dirs[dirs.length - 2];
return path.startsWith('test/') || folder == 'test';
return dirs.indexOf('test') >= 0;
}

function stripComments(contents) {
Expand Down
Expand Up @@ -15,12 +15,12 @@
*/

import * as sinon from 'sinon';
import {AmpEvents} from '../../../../src/amp-events';
import {Bind} from '../bind-impl';
import {BindEvents} from '../bind-events';
import {chunkInstanceForTesting} from '../../../../src/chunk';
import {toArray} from '../../../../src/types';
import {user} from '../../../../src/log';
import {AmpEvents} from '../../../../../src/amp-events';
import {Bind} from '../../bind-impl';
import {BindEvents} from '../../bind-events';
import {chunkInstanceForTesting} from '../../../../../src/chunk';
import {toArray} from '../../../../../src/types';
import {user} from '../../../../../src/log';

/**
* @param {!Object} env
Expand Down Expand Up @@ -99,7 +99,7 @@ function waitForEvent(env, name) {
});
}

describe('Bind', function() {
describe.configure().skipSauceLabs().run('Bind', function() {
// Give more than default 2000ms timeout for local testing.
const TIMEOUT = Math.max(window.ampTestRuntimeConfig.mochaTimeout, 4000);
this.timeout(TIMEOUT);
Expand Down
Expand Up @@ -14,19 +14,19 @@
* limitations under the License.
*/

import {AmpViewerIntegration} from '../amp-viewer-integration';
import {AmpViewerIntegration} from '../../amp-viewer-integration';
import {
Messaging,
WindowPortEmulator,
parseMessage,
} from '../messaging/messaging';
import {ViewerForTesting} from './viewer-for-testing';
import {getSourceUrl} from '../../../../src/url';
} from '../../messaging/messaging';
import {ViewerForTesting} from '../viewer-for-testing';
import {getSourceUrl} from '../../../../../src/url';


describes.sandboxed('AmpViewerIntegration', {}, () => {
const ampDocSrc = '/test/fixtures/served/ampdoc-with-messaging.html';
describe('Handshake', function() {
describe.configure().skipSauceLabs().run('Handshake', function() {
let viewerEl;
let viewer;
let ampDocUrl;
Expand Down Expand Up @@ -139,7 +139,8 @@ describes.sandboxed('AmpViewerIntegration', {}, () => {
});
});

describe('Unit Tests for messaging.js', () => {
describe.configure().skipSauceLabs().run(`Unit Tests for
messaging.js`, () => {
const viewerOrigin = 'http://localhost:9876';
const requestProcessor = function() {
return Promise.resolve({});
Expand Down
Expand Up @@ -14,13 +14,13 @@
* limitations under the License.
*/

import {AmpViewerIntegration} from '../amp-viewer-integration';
import {WebviewViewerForTesting} from './webview-viewer-for-testing.js';
import {AmpViewerIntegration} from '../../amp-viewer-integration';
import {WebviewViewerForTesting} from '../webview-viewer-for-testing.js';


describes.sandboxed('AmpWebviewViewerIntegration', {}, () => {
const ampDocSrc = '/test/fixtures/served/ampdoc-with-messaging.html';
describe('Handshake', function() {
describe.configure().skipSauceLabs().run('Handshake', function() {
let viewerEl;
let viewer;

Expand Down
Expand Up @@ -16,12 +16,12 @@

import {
WebviewViewerForTesting,
} from './viewer-initiated-handshake-viewer-for-testing';
} from '../viewer-initiated-handshake-viewer-for-testing';


describes.sandboxed('AmpWebviewViewerIntegration', {}, () => {
const ampDocSrc = '/test/fixtures/served/ampdoc-with-messaging.html';
describe('Handshake', function() {
describe.configure().skipSauceLabs().run('Handshake', function() {
let viewerEl;
let viewer;

Expand Down
80 changes: 0 additions & 80 deletions test/functional/test-3p-nameframe.js

This file was deleted.

Expand Up @@ -36,7 +36,7 @@ import {validateData} from '../../3p/3p';
import {DomFingerprint} from '../../src/utils/dom-fingerprint';
import * as sinon from 'sinon';

describe('3p-frame', () => {
describe.configure().skipSauceLabs().run('3p-frame', () => {

let clock;
let sandbox;
Expand Down
82 changes: 82 additions & 0 deletions test/integration/test-3p-nameframe.js
@@ -0,0 +1,82 @@
/**
* Copyright 2016 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.
*/

describe.configure().skipSauceLabs().run('alt nameframe', function() {
describes.sandboxed('alt nameframe', {}, () => {
describes.realWin('nameframe', {allowExternalResources: true}, env => {
let fixture;
let win;
let doc;
let iframe;
beforeEach(() => {
fixture = env;
win = fixture.win;
doc = win.document;
iframe = doc.createElement('iframe');
iframe.src = 'http://localhost:9876/dist.3p/current/nameframe.max.html';
});

it('should load remote nameframe and succeed w/ valid JSON', () => {
let messageContent;
iframe.name = JSON.stringify({
creative: `<html>
<body>
<script>
window.parent.postMessage(
{type: 'creative rendered'}, '*');
</script>
</body>
</html>`,
});
doc.body.appendChild(iframe);
return new Promise(resolve => {
win.addEventListener('message', content => {
messageContent = content;
resolve();
});
}).then(() => {
expect(messageContent.data.type).to.equal('creative rendered');
});
});

it('should fail if JSON is not paresable', done => {
iframe.name = 'not valid JSON';
expectNoContent(win, done);
doc.body.appendChild(iframe);
});

it('should fail if JSON is valid, but missing creative field', done => {
iframe.name = JSON.stringify({fnord: 'some meaningless data'});
expectNoContent(win, done);
doc.body.appendChild(iframe);
});

it('should fail if JSON is missing altogether', done => {
iframe.name = null;
expectNoContent(win, done);
doc.body.appendChild(iframe);
});
});
});
});

function expectNoContent(win, done) {
win.addEventListener('message', content => {
expect(content.data).to.have.property('type');
expect(content.data.type).to.equal('no-content');
done();
});
}

0 comments on commit 009bc86

Please sign in to comment.