Skip to content

Commit bef9f45

Browse files
committed
fix tests
Signed-off-by: flakey5 <[email protected]>
1 parent 70f9e7a commit bef9f45

File tree

6 files changed

+26
-14
lines changed

6 files changed

+26
-14
lines changed

scripts/build-r2-symlinks.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env bash
1+
#!/usr/bin/env node
22
'use strict';
33

44
import { join } from 'node:path';

src/middleware/subtituteMiddleware.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ export class SubtitutionMiddleware implements Middleware {
3939
new Request(request)
4040
);
4141

42-
return this.router.handle(substitutedRequest, ctx);
42+
return this.router.handle(substitutedRequest, ctx, request.urlObj);
4343
}
4444
}

src/providers/r2Provider.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ export class R2Provider implements Provider {
8787
options?: ReadDirectoryOptions
8888
): Promise<ReadDirectoryResult | undefined> {
8989
if (path in CACHED_DIRECTORIES) {
90-
// @ts-expect-error
90+
// @ts-expect-error dates may not be parsed at this point, we take care
91+
// of it below
9192
const result: ReadDirectoryResult = CACHED_DIRECTORIES[path];
9293

9394
for (const file of result.files) {

tests/e2e/directory.test.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { after, before, describe, it } from 'node:test';
22
import assert from 'node:assert';
3-
import { readFileSync, writeFileSync } from 'node:fs';
3+
import { readFileSync } from 'node:fs';
44
import { readFile } from 'node:fs/promises';
55
import http from 'http';
66
import { Miniflare } from 'miniflare';
@@ -24,7 +24,7 @@ async function startS3Mock(): Promise<http.Server> {
2424
const r2Prefix = url.searchParams.get('prefix')!;
2525

2626
let doesFolderExist =
27-
['nodejs/release/', 'nodejs/', 'nodejs/docs/', 'metrics/'].includes(
27+
['nodejs/release/v1.0.0/', 'nodejs/', 'nodejs/docs/', 'metrics/'].includes(
2828
r2Prefix
2929
) || r2Prefix.endsWith('/docs/api/');
3030

@@ -76,15 +76,26 @@ describe('Directory Tests (Restricted Directory Listing)', () => {
7676
});
7777

7878
it('redirects `/dist` to `/dist/` and returns expected html', async () => {
79-
const [originalRes, expectedHtml] = await Promise.all([
80-
mf.dispatchFetch(`${url}dist`, { redirect: 'manual' }),
79+
const originalRes = await
80+
mf.dispatchFetch(`${url}dist`, { redirect: 'manual' })
81+
82+
assert.strictEqual(originalRes.status, 301);
83+
const res = await mf.dispatchFetch(originalRes.headers.get('location')!);
84+
assert.strictEqual(res.status, 200);
85+
assert.strictEqual(
86+
res.headers.get('cache-control'),
87+
'public, max-age=3600, s-maxage=14400'
88+
);
89+
});
90+
91+
it('`/dist/v1.0.0/` returns expected html', async () => {
92+
const [res, expectedHtml] = await Promise.all([
93+
mf.dispatchFetch(`${url}dist/v1.0.0/`),
8194
readFile('./tests/e2e/test-data/expected-html/dist.txt', {
8295
encoding: 'utf-8',
8396
}),
8497
]);
8598

86-
assert.strictEqual(originalRes.status, 301);
87-
const res = await mf.dispatchFetch(originalRes.headers.get('location')!);
8899
assert.strictEqual(res.status, 200);
89100
assert.strictEqual(
90101
res.headers.get('cache-control'),

tests/e2e/test-data/expected-html/dist.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!DOCTYPE html><html>
22
<head>
3-
<title>Index of /dist/</title>
3+
<title>Index of /dist/v1.0.0/</title>
44
<style>
55
@media (prefers-color-scheme: dark) {
66
body {
@@ -17,8 +17,8 @@
1717
</style>
1818
</head>
1919
<body>
20-
<h1>Index of /dist/</h1><hr><pre><a href="../">../</a>
20+
<h1>Index of /dist/v1.0.0/</h1><hr><pre><a href="../">../</a>
2121
<a href="latest/">latest/</a> - -
22-
<a href="/dist/index.json">index.json</a> 12 Sept 2023, 05:43 18 B
22+
<a href="/dist/v1.0.0/index.json">index.json</a> 12 Sept 2023, 05:43 18 B
2323
</pre><hr /></body>
2424
</html>

tests/e2e/test-data/expected-s3/ListObjectsV2-exists.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
<MaxKeys>1000</MaxKeys>
66
<IsTruncated>false</IsTruncated>
77
<CommonPrefixes>
8-
<Prefix>nodejs/release/latest/</Prefix>
8+
<Prefix>nodejs/release/v1.0.0/latest/</Prefix>
99
</CommonPrefixes>
1010
<Contents>
1111
<ETag>"asd123"</ETag>
12-
<Key>nodejs/release/index.json</Key>
12+
<Key>nodejs/release/v1.0.0/index.json</Key>
1313
<LastModified>2023-09-12T05:43:00.000Z</LastModified>
1414
<Size>18</Size>
1515
</Contents>

0 commit comments

Comments
 (0)