Skip to content

Commit

Permalink
Fixes the flaky tests (#24)
Browse files Browse the repository at this point in the history
* better offlin page test

* fixing unknown values

* fixing postMessage test

* smaller timeout
  • Loading branch information
prateekbh authored Apr 24, 2019
1 parent 2730aef commit 45e0b59
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
9 changes: 7 additions & 2 deletions test/modules/amp-caching/amp-caching-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ import { buildSW } from '../../../lib/builder/index';
import { promisify } from 'util';
import * as fs from 'fs';
import { join } from 'path';
const fetch = require('node-fetch');
import { testStaleWhileRevalidate } from '../../strategy-tests/strategy-tests';

const METADATA_URL = 'https://cdn.ampproject.org/rtv/metadata';
const writeFile = promisify(fs.writeFile);

describe('AMP caching module', function() {
Expand Down Expand Up @@ -135,11 +137,14 @@ describe('AMP caching module', function() {
});

it('should cache AMP scripts given by postMessage', async () => {
const ampRuntimeVersion = (await (await fetch(METADATA_URL)).json())[
'ampRuntimeVersion'
];
await driver.get('http://localhost:6881/test/index.html');
const cacheName = 'AMP-VERSIONED-CACHE';
const payload = [
'https://cdn.ampproject.org/rtv/001525381599226/v0.js',
'https://cdn.ampproject.org/rtv/001810022028350/v0/amp-mustache-0.1.js',
`https://cdn.ampproject.org/rtv/${ampRuntimeVersion}/v0.js`,
`https://cdn.ampproject.org/rtv/${ampRuntimeVersion}/v0/amp-mustache-0.1.js`,
'https://code.jquery.com/jquery-3.3.1.min.js',
];
let hasVersionJSInCache = await driver.executeAsyncScript(
Expand Down
13 changes: 10 additions & 3 deletions test/modules/offline-page/offline-page-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,19 @@ describe('Offline page module', function() {
});

it('should use offline page when navigating to an uncached page', async () => {
global.__AMPSW.server.stop();
await sleep(5000);
await driver.setNetworkConditions({
offline: true,
latency: 5,
throughput: 500 * 1024,
});
await driver.navigate().refresh();
const title = await driver.getTitle();
expect(title).to.be.equal('Offline page');
global.__AMPSW.server.start();
await driver.setNetworkConditions({
offline: false,
latency: 0,
throughput: 500 * 1024,
});
await driver.navigate().refresh();
});
});
Expand Down

0 comments on commit 45e0b59

Please sign in to comment.