Skip to content

Commit a973f55

Browse files
Fix web tests
1 parent e8d23a0 commit a973f55

File tree

14 files changed

+1492
-1926
lines changed

14 files changed

+1492
-1926
lines changed

package-lock.json

Lines changed: 1421 additions & 1800 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@
2626
"prepublishOnly": "npm run build",
2727
"test": "run-s test:node test:web test:format",
2828
"test:format": "prettier --check '{source,test}/**/*.{js,ts}'",
29-
"test:node": "vitest --watch=false",
30-
"test:node:watch": "nodemon --exec 'npm run test:node' --ignore 'dist/'",
31-
"test:web": "echo OK",
32-
"xtest:web": "vitest --watch=false --config vitest.web.config.ts"
29+
"test:node": "vitest --watch=false --project node-unit",
30+
"test:node:watch": "vitest --watch=true --project node-unit",
31+
"test:web": "npm run clean && npm run build:web && concurrently -k 'npm run test:web:server' 'npm run test:web:specs'",
32+
"test:web:server": "npx -y tsx ./test/server.web.ts",
33+
"test:web:specs": "vitest --watch=false --project browser"
3334
},
3435
"files": [
3536
"dist/",
@@ -92,6 +93,7 @@
9293
"babel-loader": "^9.2.1",
9394
"babel-plugin-transform-async-to-promises": "^0.8.18",
9495
"buffer-equals": "^2.0.0",
96+
"concurrently": "^9.1.2",
9597
"copy-dir": "^1.3.0",
9698
"directory-exists": "^2.0.1",
9799
"exists-file": "^3.0.2",
@@ -109,6 +111,7 @@
109111
"ts-node": "^10.9.2",
110112
"tsx": "^4.19.2",
111113
"typescript": "^5.7.3",
114+
"vite": "^6.3.5",
112115
"vitest": "^3.2.2",
113116
"wait-on": "^7.2.0",
114117
"webdav-server": "^2.6.2",

source/compat/env.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
declare var TARGET: "web" | "react-native" | undefined;
22

3-
export function getDebugBuildName(): string {
4-
if (typeof TARGET === "string") {
5-
return TARGET;
6-
}
7-
return "node";
8-
}
9-
103
export function isReactNative(): boolean {
114
return typeof TARGET === "string" && TARGET === "react-native";
125
}

source/factory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import {
2525
CreateReadStreamOptions,
2626
CreateWriteStreamCallback,
2727
CreateWriteStreamOptions,
28-
GetDirectoryContentsOptions,
2928
GetDirectoryContentsOptionsWithDetails,
3029
GetDirectoryContentsOptionsWithoutDetails,
3130
GetFileContentsOptions,
@@ -109,6 +108,7 @@ export function createClient(remoteURL: string, options: WebDAVClientOptions = {
109108
options?:
110109
| GetDirectoryContentsOptionsWithDetails
111110
| GetDirectoryContentsOptionsWithoutDetails
111+
// @ts-ignore
112112
) => getDirectoryContents(context, path, options),
113113
getFileContents: (filename: string, options?: GetFileContentsOptions) =>
114114
getFileContents(context, filename, options),

source/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ export { getPatcher } from "./compat/patcher.js";
33
export * from "./types.js";
44

55
export { parseStat, parseXML, translateDiskSpace, prepareFileFromProps } from "./tools/dav.js";
6+
export { calculateDataLength } from "./tools/size.js";
67
export { processResponsePayload } from "./response.js";

test/server.web.ts

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,29 @@ import path from "path";
22
import { fileURLToPath } from "url";
33
import { rimraf } from "rimraf";
44
import copyDir from "copy-dir";
5+
import { WEB_PORT } from "./server/credentials.js";
56
import { createWebDAVServer } from "./server/index.js";
67

7-
const dirname = path.dirname(fileURLToPath(import.meta.url));
8+
(async () => {
9+
const dirname = path.dirname(fileURLToPath(import.meta.url));
810

9-
rimraf.sync(path.resolve(dirname, "./testContents"));
10-
copyDir.sync(path.resolve(dirname, "./serverContents"), path.resolve(dirname, "./testContents"));
11+
rimraf.sync(path.resolve(dirname, "./testContents"));
12+
copyDir.sync(
13+
path.resolve(dirname, "./serverContents"),
14+
path.resolve(dirname, "./testContents")
15+
);
1116

12-
const server = createWebDAVServer(45000, "basic");
13-
server.start().then(() => {
14-
console.log("Server started");
15-
});
17+
const server = createWebDAVServer(WEB_PORT, "basic");
18+
server.start().then(() => {
19+
console.log("Server started");
20+
});
1621

17-
process.on("SIGTERM", function () {
18-
server.stop();
19-
process.exit(0);
20-
});
21-
process.on("SIGINT", function () {
22-
server.stop();
23-
process.exit(0);
24-
});
22+
process.on("SIGTERM", function () {
23+
server.stop();
24+
process.exit(0);
25+
});
26+
process.on("SIGINT", function () {
27+
server.stop();
28+
process.exit(0);
29+
});
30+
})().catch(console.error);

test/server/credentials.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export const PASSWORD = "pa$$w0rd!";
22
export const USERNAME = "webdav-user";
3+
export const WEB_PORT = 45000;

test/web/compat/env.spec.ts

Lines changed: 0 additions & 8 deletions
This file was deleted.

test/web/exists.spec.ts

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,16 @@
11
import { beforeEach, describe, expect, it } from "vitest";
2+
import { createClient } from "../../dist/web/index.js";
23
import { WebDAVClient } from "../../source/types.js";
3-
import {
4-
clean,
5-
createWebDAVClient,
6-
createWebDAVServer,
7-
FetchSpy,
8-
nextPort,
9-
SERVER_PASSWORD,
10-
SERVER_USERNAME,
11-
useFetchSpy,
12-
WebDAVServer
13-
} from "../helpers.node.js";
4+
import { PASSWORD, WEB_PORT, USERNAME } from "../server/credentials.js";
145

156
describe("exists", function () {
16-
let client: WebDAVClient, server: WebDAVServer, requestSpy: FetchSpy;
7+
let client: WebDAVClient;
178

189
beforeEach(async function () {
19-
const port = await nextPort();
20-
clean();
21-
client = createWebDAVClient(`http://localhost:${port}/webdav/server`, {
22-
username: SERVER_USERNAME,
23-
password: SERVER_PASSWORD
10+
client = createClient(`http://localhost:${WEB_PORT}/webdav/server`, {
11+
username: USERNAME,
12+
password: PASSWORD
2413
});
25-
server = createWebDAVServer(port);
26-
requestSpy = useFetchSpy();
27-
await server.start();
2814
});
2915

3016
it("correctly detects existing files", async function () {

test/web/getDirectoryContents.spec.ts

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,16 @@
11
import { beforeEach, describe, expect, it } from "vitest";
2-
import {
3-
clean,
4-
createWebDAVClient,
5-
createWebDAVServer,
6-
FetchSpy,
7-
nextPort,
8-
SERVER_PASSWORD,
9-
SERVER_USERNAME,
10-
useFetchSpy,
11-
WebDAVServer
12-
} from "../helpers.node.js";
2+
import { createClient } from "../../dist/web/index.js";
133
import { WebDAVClient } from "../../source/types.js";
4+
import { PASSWORD, WEB_PORT, USERNAME } from "../server/credentials.js";
145

156
describe("getDirectoryContents", function () {
16-
let client: WebDAVClient, server: WebDAVServer, requestSpy: FetchSpy;
7+
let client: WebDAVClient;
178

189
beforeEach(async function () {
19-
const port = await nextPort();
20-
clean();
21-
client = createWebDAVClient(`http://localhost:${port}/webdav/server`, {
22-
username: SERVER_USERNAME,
23-
password: SERVER_PASSWORD
10+
client = createClient(`http://localhost:${WEB_PORT}/webdav/server`, {
11+
username: USERNAME,
12+
password: PASSWORD
2413
});
25-
server = createWebDAVServer(port);
26-
requestSpy = useFetchSpy();
27-
await server.start();
2814
});
2915

3016
it("returns an array of items", function () {

0 commit comments

Comments
 (0)