Skip to content

chore: refactor tests #753

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

Merged
merged 3 commits into from
Nov 18, 2024
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
2,146 changes: 1,274 additions & 872 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"lodash.escape": "4.0.1",
"mdast-util-to-hast": "13.2.0",
"mdast-util-to-string": "4.0.0",
"micromark-util-subtokenize": "2.0.1",
"mime": "4.0.4",
"rehype-format": "5.0.1",
"rehype-parse": "9.0.1",
Expand Down
9 changes: 4 additions & 5 deletions test/FileS3Loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,14 @@ export class FileS3Loader {
if (!dir) {
throw Error(`unknown bucketId: ${bucketId}`);
}
// eslint-disable-next-line no-console
let fileName = key.split('/').pop();
let fileName = key.split('/').slice(2).join('/');

fileName = this.rewrites.reduce((result, rewrite) => rewrite(key) || result, null) || fileName;
const status = this.statusCodeOverrides[fileName];
const headers = this.headerOverride[fileName] ?? new Map();
if (status) {
// eslint-disable-next-line no-console
console.log(`FileS3Loader: loading ${bucketId}/${key} -> ${status}`);
console.log(`FileS3Loader: loading ${bucketId}/${fileName} -> ${status}`);
return {
status,
body: '',
Expand All @@ -73,7 +72,7 @@ export class FileS3Loader {
try {
const body = await readFile(file, 'utf-8');
// eslint-disable-next-line no-console
console.log(`FileS3Loader: loading ${bucketId}/${key} -> 200`);
console.log(`FileS3Loader: loading ${bucketId}/${fileName} -> 200`);
return {
status: 200,
body,
Expand All @@ -86,7 +85,7 @@ export class FileS3Loader {
};
} catch (e) {
// eslint-disable-next-line no-console
console.log(`FileS3Loader: loading ${bucketId}/${key} -> 404 (${e.message})`);
console.log(`FileS3Loader: loading ${bucketId}/${fileName} -> 404 (${e.message})`);
return {
status: 404,
body: '',
Expand Down
17 changes: 17 additions & 0 deletions test/fixtures/code/main/helix-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"head": {
"html": "<link id=\"favicon\" rel=\"icon\" type=\"image/svg+xml\" href=\"/icons/spark.svg\">\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"/>\n<script src=\"/scripts.js\" type=\"module\"></script>\n<link rel=\"stylesheet\" href=\"/styles.css\"/>\n"
},
"fstab": {
"mountpoints": {
"/": {
"url": "https://adobe.sharepoint.com/sites/cg-helix/Shared%20Documents"
}
}
},
"content": {
"/": {
"contentBusId": "foo-id"
}
}
}
3 changes: 3 additions & 0 deletions test/fixtures/content/blog/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<!-- this is a test document -->
# Hello

66 changes: 66 additions & 0 deletions test/fixtures/content/generic-product/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
":version": 3,
":type": "multi-sheet",
":names": [
"default"
],
"default": {
"total": 2,
"offset": 0,
"limit": 2,
"data": [
{
"URL": "/page-*",
"Category": "rendering-test"
},
{
"url": "**/page-*-blocks",
"Glob Test": "match ** and * combo"
},
{
"Url": "**/marketing/**",
"Category": "Marketing"
},
{
"URL": "/page-metadata-json.html",
"Image": "/media_cf867e391c0b433ec3d416c979aafa1f8e4aae9c.png",
"Keywords": "Baz, Bar, Foo",
"og:publisher": "Adobe"
},
{
"URL": "/page-metadata-json",
"Image": "/media_cf867e391c0b433ec3d416c979aafa1f8e4aae9c.png",
"Keywords": "Baz, Bar, Foo",
"og:publisher": "Adobe"
},
{
"URL": "/exact-match.html",
"Keywords": "Exactomento",
"og:publisher": "Adobe",
"Short Title": "E"
},
{
"URL": "/page-metadata-block",
"Short Title": "global-meta"
},
{
"URL": "/exact-match",
"Keywords": "Exactomento",
"og:publisher": "Adobe",
"Short Title": "E"
},
{
"URL": "/exact-folder/",
"Keywords": "Exactomento Folder",
"og:publisher": "Adobe",
"Short Title": "E"
},
{
"URL": "/products**",
"Keywords": "Exactomento Mapped Folder",
"og:publisher": "Adobe",
"Short Title": "E"
}
]
}
}
3 changes: 3 additions & 0 deletions test/fixtures/content/one-section/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<!-- this is a test document -->
# Hello

32 changes: 31 additions & 1 deletion test/html-pipe.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('HTML Pipe Test', () => {
const resp = await htmlPipe(
new PipelineState({
log: console,
s3Loader: new FileS3Loader().status('config-all.json', 404),
s3Loader: new FileS3Loader().status('.helix/config-all.json', 404),
owner: 'adobe',
repo: 'helix-pages',
ref: 'super-test',
Expand Down Expand Up @@ -186,6 +186,36 @@ describe('HTML Pipe Test', () => {
});
});

it('serves 404 for missing resource', async () => {
const s3Loader = new FileS3Loader();
const state = new PipelineState({
log: console,
s3Loader,
owner: 'adobe',
repo: 'helix-pages',
ref: 'main',
partition: 'live',
path: '/doesnotexist.md',
timer: {
update: () => { },
},
});
const resp = await htmlPipe(
state,
new PipelineRequest(new URL('https://www.hlx.live/')),
);
assert.strictEqual(resp.status, 404);
assert.deepStrictEqual(Object.fromEntries(resp.headers.entries()), {
'access-control-allow-origin': '*',
'content-type': 'text/html; charset=utf-8',
'last-modified': 'Fri, 30 Apr 2021 03:47:18 GMT',
'x-error': 'failed to load /doesnotexist.md from content-bus: 404',
'x-surrogate-key': 'HtFBsF6g4PvudhiW foo-id main--helix-pages--adobe_404 main--helix-pages--adobe_code',
// this is coming from the config-all/headers
link: '</scripts/scripts.js>; rel=modulepreload; as=script; crossorigin=use-credentials',
});
});

it('renders /', async () => {
const s3Loader = new FileS3Loader();
const state = new PipelineState({
Expand Down
Loading