Skip to content

Commit dc7ffe2

Browse files
committed
wip
1 parent ad5dd0f commit dc7ffe2

File tree

2 files changed

+25
-20
lines changed

2 files changed

+25
-20
lines changed

src/hooks/useFetch.test.ts

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,29 @@ import { useTestConfig } from "./useTestConfig.ts";
33
import useFetch from "./useFetch.ts"
44

55

6-
Deno.test("fetch user-agent header check", async () => {
7-
const UserAgent = "tests/1.2.3"
8-
useTestConfig({ UserAgent })
6+
Deno.test({
7+
name: "fetch user-agent header check",
8+
/// doesn't work inside DNT because fetch is shimmed to undici
9+
ignore: !!Deno.env.get("NODE"),
10+
async fn() {
11+
const UserAgent = "tests/1.2.3"
12+
useTestConfig({ UserAgent })
913

10-
const url = "https://example.com";
11-
const fetchStub = stub(
12-
globalThis,
13-
"fetch",
14-
() => Promise.resolve(new Response("")),
15-
);
14+
const url = "https://example.com";
15+
const fetchStub = stub(
16+
globalThis,
17+
"fetch",
18+
() => Promise.resolve(new Response("")),
19+
);
1620

17-
try {
18-
await useFetch(url, {});
19-
} finally {
20-
fetchStub.restore();
21-
}
21+
try {
22+
await useFetch(url, {});
23+
} finally {
24+
fetchStub.restore();
25+
}
2226

23-
assertSpyCallArgs(fetchStub, 0, [url, {
24-
headers: {"User-Agent": UserAgent}
25-
}]);
27+
assertSpyCallArgs(fetchStub, 0, [url, {
28+
headers: {"User-Agent": UserAgent}
29+
}]);
30+
}
2631
});

src/hooks/useTestConfig.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import usePantry from "./usePantry.ts"
2222

2323
export function useTestConfig(env?: Record<string, string>) {
2424
const conf = useBaseTestConfig(env)
25-
copyDirectory(srcroot.join("fixtures/projects").string, usePantry().prefix.parent().mkdir('p').join("projects").string)
25+
copyDirectory(srcroot.join("fixtures/projects").string, usePantry().prefix.mkdir('p').string)
2626
return conf
2727
}
2828

@@ -39,7 +39,7 @@ export const srcroot = (() => {
3939
}
4040
})()
4141

42-
import { walkSync, copySync } from 'deno/fs/mod.ts'
42+
import { walkSync } from 'deno/fs/mod.ts'
4343

4444
// deno/dnt has a broken shim for this function
4545
function copyDirectory(src: string, dest: string) {
@@ -49,7 +49,7 @@ function copyDirectory(src: string, dest: string) {
4949
if (entry.isDirectory) {
5050
Deno.mkdirSync(destPath, { recursive: true });
5151
} else {
52-
copySync(entry.path, destPath);
52+
Deno.copyFileSync(entry.path, destPath);
5353
}
5454
}
5555
}

0 commit comments

Comments
 (0)