Skip to content

Commit

Permalink
Merge 167f4f9 into 7e66101
Browse files Browse the repository at this point in the history
  • Loading branch information
papandreou committed Apr 19, 2019
2 parents 7e66101 + 167f4f9 commit 2504d2b
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 24 deletions.
23 changes: 21 additions & 2 deletions lib/index.js
Expand Up @@ -513,7 +513,7 @@ async function hyperlink(
});
}
}
} else if (relation.to.type === 'Html') {
} else {
(relation.to.incomingFragments =
relation.to.incomingFragments || []).push({
fragment,
Expand Down Expand Up @@ -656,14 +656,33 @@ async function hyperlink(
})();
});

// Forward incomingFragments through redirects:
for (const redirectAsset of ag.findAssets({ isRedirect: true })) {
if (redirectAsset.incomingFragments) {
const assetQueue = new Set([redirectAsset]);
for (const asset of assetQueue) {
if (asset.isRedirect) {
for (const relation of asset.outgoingRelations) {
assetQueue.add(relation.to);
}
} else {
(asset.incomingFragments = asset.incomingFragments || []).push(
...redirectAsset.incomingFragments
);
}
}
delete redirectAsset.incomingFragments;
}
}

// Check fragments

for (const asset of ag.findAssets()) {
if (internalOnly && !asset.isLoaded) {
continue;
}

if (asset.incomingFragments) {
if (asset.incomingFragments && asset.type === 'Html') {
for (const {
fragment,
relationDebugDescription,
Expand Down
42 changes: 42 additions & 0 deletions test/index.js
Expand Up @@ -703,6 +703,48 @@ describe('hyperlink', function() {
});
});
});

describe('on a local file system', function() {
it('should report missing fragments through a FileRedirect', async function() {
const t = new TapRender();
sinon.spy(t, 'push');
await hyperlink(
{
recursive: true,
root: pathModule.resolve(
__dirname,
'..',
'testdata',
'fragmentIdentifier'
),
inputUrls: ['index.html']
},
t
);

expect(t.close(), 'to satisfy', {
count: 5,
pass: 4,
fail: 1,
skip: 0,
todo: 0
});
expect(t.push, 'to have a call satisfying', () => {
t.push(null, {
ok: false,
operator: 'fragment-check',
name:
'fragment-check testdata/fragmentIdentifier/index.html --> /subdir#definitely-broken',
expected: 'id="definitely-broken"'
});
}).and('to have no calls satisfying', () => {
t.push(null, {
name: expect.it('to contain', '#fine'),
ok: false
});
});
});
});
});

describe('with a relation that points at an asset that returns 404', function() {
Expand Down
26 changes: 4 additions & 22 deletions testdata/fragmentIdentifier/index.html
@@ -1,30 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<a href="/subdir#fine"></a>

<div id="one"></div>
<div id="two"></div>
<div id="three"></div>

<a href="#one"></a>
<a href="#two"></a>
<a href="#three"></a>

<a href="#broken-one"></a>
<a href="#broken-two"></a>
<a href="#broken-three"></a>

<a href="page.html#one"></a>
<a href="page.html#two"></a>
<a href="page.html#three"></a>

<a href="page.html#broken-one"></a>
<a href="page.html#broken-two"></a>
<a href="page.html#broken-three"></a>

<a href="/subdir#definitely-broken"></a>
</body>
</html>
10 changes: 10 additions & 0 deletions testdata/fragmentIdentifier/subdir/index.html
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<div id="fine"></div>
</body>
</html>

0 comments on commit 2504d2b

Please sign in to comment.