Skip to content
This repository has been archived by the owner on May 17, 2019. It is now read-only.

Commit

Permalink
tests and flow typing (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
angus-c authored Jan 25, 2019
1 parent 79268ce commit 5943960
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 11 deletions.
31 changes: 27 additions & 4 deletions src/__tests__/fixtures/swTemplate.js

Large diffs are not rendered by default.

37 changes: 34 additions & 3 deletions src/__tests__/index.browser.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,38 @@
// @flow
import test from 'tape-cup';
import type {Context} from 'fusion-core';
import plugin from '../browser.js';

test('ok', t => {
t.ok(true);
t.end();
const addEventListener = window.addEventListener;
window.addEventListener = function(_, fn) {
fn();
window.addEventListener = addEventListener;
};

if (window.navigator && window.navigator.serviceWorker) {
window.navigator.serviceWorker.register = function(path) {
return new Promise(function(resolve, reject) {
setTimeout(function() {
resolve(path);
}, 300);
});
};
}

const mockContext: Context = ({}: any);
let logged = '';

test('registers sw', t => {
const next = () => {
return t.pass('Called next()');
};
if (plugin.middleware) {
plugin.middleware({
log(...args) {
logged += args.join(' ');
t.equal(logged, '*** sw registered: /sw.js');
t.end();
},
})(mockContext, next);
}
});
2 changes: 1 addition & 1 deletion src/__tests__/index.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ test('/health request', async t => {
t.ok(
ctx_1.body
.replace(/\n/g, '')
.startsWith('var sw =/******/ (function(modules) {'),
.startsWith(`var sw = (assetInfo: AssetInfo) => {`),
'sends correct response'
);
t.end();
Expand Down
2 changes: 1 addition & 1 deletion src/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function getOutdatedKeys(cache, cacheablePaths) {
return cache.keys().then(requests =>
requests.filter(request => {
return !cacheablePaths.find(key => {
return location.origin + key === request.url;
return location.origin + String(key) === request.url;
});
})
);
Expand Down
6 changes: 4 additions & 2 deletions src/types.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @flow
import type {Token} from 'fusion-core';

import type {Context} from 'fusion-core';

Expand All @@ -13,7 +14,8 @@ export type PluginServiceType = {

export type AssetInfo = {
precachePaths: Array<RequestInfo>,
cacheablePaths: Array<string>,
cacheablePaths: Array<RequestInfo>,
};

export type ConfigTokenType = any;
type ConfigType = AssetInfo => string;
export type ConfigTokenType = Token<ConfigType>;

0 comments on commit 5943960

Please sign in to comment.