-
Notifications
You must be signed in to change notification settings - Fork 16
/
deno_dir_test.ts
121 lines (110 loc) · 3.1 KB
/
deno_dir_test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// Copyright 2018-2024 the Deno authors. MIT license.
import { assertEquals, assertThrows } from "@std/assert";
import { DenoDir } from "./deno_dir.ts";
import { withTempDir } from "./deps_test.ts";
Deno.test({
name: "DenoDir - basic",
async fn() {
const expectedText =
`// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
// Copyright the Browserify authors. MIT License.
/**
* Ported mostly from https://github.com/browserify/path-browserify/
* This module is browser compatible.
* @module
*/
import { isWindows } from "../_util/os.ts";
import * as _win32 from "./win32.ts";
import * as _posix from "./posix.ts";
const path = isWindows ? _win32 : _posix;
export const win32 = _win32;
export const posix = _posix;
export const {
basename,
delimiter,
dirname,
extname,
format,
fromFileUrl,
isAbsolute,
join,
normalize,
parse,
relative,
resolve,
sep,
toFileUrl,
toNamespacedPath,
} = path;
export * from "./common.ts";
export { SEP, SEP_PATTERN } from "./separator.ts";
export * from "./_interface.ts";
export * from "./glob.ts";
`;
const denoDir = new DenoDir();
const url = new URL("https://deno.land/[email protected]/path/mod.ts");
const expectedHeaders = {
"content-type": "application/typescript",
};
const deps = await denoDir.createHttpCache();
deps.set(url, expectedHeaders, new TextEncoder().encode(expectedText));
const headers = deps.getHeaders(url)!;
assertEquals(headers, expectedHeaders);
const cacheEntry = deps.get(url)!;
assertEquals(cacheEntry.headers, expectedHeaders);
const text = new TextDecoder().decode(cacheEntry.content);
assertEquals(text, expectedText);
// ok
deps.get(
url,
{
checksum:
"d3e68d0abb393fb0bf94a6d07c46ec31dc755b544b13144dee931d8d5f06a52d",
},
);
// not ok
assertThrows(() =>
deps.get(url, {
checksum: "invalid",
})
);
},
});
Deno.test({
name: "HttpCache - global cache - get",
async fn() {
const denoDir = new DenoDir();
const url = new URL("https://deno.land/[email protected]/path/mod.ts");
const deps = await denoDir.createHttpCache();
// disallow will still work because we're using a global cache
// which is not affected by this option
const entry = await deps.get(url);
assertEquals(entry!.content.length, 820);
},
});
Deno.test({
name: "HttpCache - local cache- allowCopyGlobalToLocal",
async fn() {
await withTempDir(async (tempDir) => {
const denoDir = new DenoDir();
const url = new URL("https://deno.land/[email protected]/path/mod.ts");
// disallow copy from global to local because readonly
{
using deps = await denoDir.createHttpCache({
vendorRoot: tempDir,
readOnly: true,
});
const text = deps.get(url);
assertEquals(text, undefined);
}
// this should be fine though
{
using deps = await denoDir.createHttpCache({
vendorRoot: tempDir,
});
const entry = deps.get(url);
assertEquals(entry!.content.length, 820);
}
});
},
});