Skip to content

Commit ed4a1bb

Browse files
committed
Add windows test
1 parent 93c02fe commit ed4a1bb

File tree

3 files changed

+35
-17
lines changed

3 files changed

+35
-17
lines changed

.github/workflows/test.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,24 @@ jobs:
2828
env:
2929
VAL_TOWN_API_KEY: ${{ secrets.VAL_TOWN_API_KEY }}
3030

31+
test-windows:
32+
runs-on: windows-latest
33+
34+
steps:
35+
- uses: actions/checkout@v3
36+
- uses: denoland/setup-deno@v2
37+
with:
38+
deno-version: v2.x
39+
40+
- name: Run deno tests
41+
uses: nick-fields/retry@v3
42+
with:
43+
command: deno task test:lib
44+
max_attempts: 2
45+
timeout_seconds: 2000
46+
env:
47+
VAL_TOWN_API_KEY: ${{ secrets.VAL_TOWN_API_KEY }}
48+
3149
test-mac:
3250
runs-on: ubuntu-latest
3351

src/sdk.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import ValTown from "@valtown/sdk";
22
import { memoize } from "@std/cache";
33
import manifest from "../deno.json" with { type: "json" };
44
import { API_KEY_KEY, DEFAULT_BRANCH_NAME } from "~/consts.ts";
5+
import { normalize } from "@std/path";
56

67
const sdk = new ValTown({
78
// Must get set in vt.ts entrypoint if not set as an env var!
@@ -63,7 +64,7 @@ export async function branchExists(
6364
branchName: string,
6465
): Promise<boolean> {
6566
for await (const branch of sdk.vals.branches.list(valId, {})) {
66-
if (branch.name == branchName) return true;
67+
if (branch.name === branchName) return true;
6768
}
6869
return false;
6970
}
@@ -81,7 +82,7 @@ export async function branchNameToBranch(
8182
branchName: string,
8283
): Promise<ValTown.Vals.Branches.BranchListResponse> {
8384
for await (const branch of sdk.vals.branches.list(valId, {})) {
84-
if (branch.name == branchName) return branch;
85+
if (branch.name === branchName) return branch;
8586
}
8687

8788
throw new Deno.errors.NotFound(`Branch "${branchName}" not found in Val`);
@@ -118,7 +119,7 @@ export async function valItemExists(
118119
* @param valId - The ID of the Val containing the file
119120
* @param options - The options object
120121
* @param options.branchId - The ID of the Val branch to reference
121-
* @param [options.version] - The version of the Val for the file being found (optional)
122+
* @param options.version - The version of the Val for the file being found (optional)
122123
* @param options.filePath - The file path to locate
123124
* @returns Promise resolving to the file data or undefined if not found
124125
*/
@@ -140,11 +141,11 @@ export const getValItem = memoize(async (
140141
/**
141142
* Get the content of a Val item.
142143
*
143-
* @param {string} valId The ID of the Val
144-
* @param {string} branchId The ID of the Val branch to reference
145-
* @param {number} version The version of the Val
146-
* @param {string} filePath The path to the file
147-
* @returns {Promise<string>} Promise resolving to the file content
144+
* @param valId The ID of the Val
145+
* @param branchId The ID of the Val branch to reference
146+
* @param version The version of the Val
147+
* @param filePath The path to the file
148+
* @returns Promise resolving to the file content
148149
*/
149150
export const getValItemContent = memoize(
150151
async (
@@ -179,14 +180,15 @@ export const listValItems = memoize(async (
179180
(await branchNameToBranch(valId, DEFAULT_BRANCH_NAME)
180181
.then((resp) => resp.id));
181182

182-
const files = await Array.fromAsync(
183+
const files = (await Array.fromAsync(
183184
sdk.vals.files.retrieve(valId, {
184185
path: "",
185186
branch_id: branchId,
186187
version,
187188
recursive: true,
188189
}),
189-
);
190+
))
191+
.map((f) => ({ ...f, path: normalize(f.path) }));
190192

191193
return files;
192194
});

src/vt/lib/status.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { getValItemContent, listValItems } from "~/sdk.ts";
22
import { getValItemType, shouldIgnore } from "~/vt/lib/paths.ts";
3-
import * as fs from "@std/fs";
4-
import * as path from "@std/path";
53
import {
64
type CreatedItemStatus,
75
type DeletedItemStatus,
@@ -11,9 +9,9 @@ import {
119
type ModifiedItemStatus,
1210
type NotModifiedItemStatus,
1311
} from "~/vt/lib/utils/ItemStatusManager.ts";
14-
import { join } from "@std/path";
12+
import { join, relative } from "@std/path";
1513
import { isFileModified } from "~/vt/lib/utils/misc.ts";
16-
import { exists } from "@std/fs";
14+
import { exists, walk } from "@std/fs";
1715

1816
/** Result of status operation */
1917
export interface StatusResult {
@@ -88,7 +86,7 @@ export async function status(params: StatusParams): Promise<StatusResult> {
8886
result.insert(createdFileState);
8987
} else {
9088
if (localFile.type !== "directory") {
91-
const localStat = await Deno.stat(path.join(targetDir, localFile.path));
89+
const localStat = await Deno.stat(join(targetDir, localFile.path));
9290

9391
// File exists in both places, check if modified
9492
const isModified = isFileModified({
@@ -218,10 +216,10 @@ async function getLocalFiles({
218216
}): Promise<ItemInfo[]> {
219217
const filePromises: Promise<ItemInfo | null>[] = [];
220218

221-
for await (const entry of fs.walk(targetDir)) {
219+
for await (const entry of walk(targetDir)) {
222220
filePromises.push((async () => {
223221
// Check if this is on the ignore list
224-
const relativePath = path.relative(targetDir, entry.path);
222+
const relativePath = relative(targetDir, entry.path);
225223
if (shouldIgnore(relativePath, gitignoreRules)) return null;
226224
if (entry.path === targetDir) return null;
227225

0 commit comments

Comments
 (0)