fix: current version not updated in update check (#1482)
This commit is contained in:
+1
-1
@@ -11,7 +11,7 @@ export {
|
|||||||
SEP,
|
SEP,
|
||||||
toFileUrl,
|
toFileUrl,
|
||||||
} from "https://deno.land/std@0.193.0/path/mod.ts";
|
} from "https://deno.land/std@0.193.0/path/mod.ts";
|
||||||
export { DAY } from "https://deno.land/std@0.193.0/datetime/constants.ts";
|
export { DAY, WEEK } from "https://deno.land/std@0.193.0/datetime/constants.ts";
|
||||||
export * as colors from "https://deno.land/std@0.193.0/fmt/colors.ts";
|
export * as colors from "https://deno.land/std@0.193.0/fmt/colors.ts";
|
||||||
export { walk, WalkError } from "https://deno.land/std@0.193.0/fs/walk.ts";
|
export { walk, WalkError } from "https://deno.land/std@0.193.0/fs/walk.ts";
|
||||||
export { parse } from "https://deno.land/std@0.193.0/flags/mod.ts";
|
export { parse } from "https://deno.land/std@0.193.0/flags/mod.ts";
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { colors, join } from "./deps.ts";
|
import { colors, join } from "./deps.ts";
|
||||||
|
|
||||||
interface CheckFile {
|
export interface CheckFile {
|
||||||
last_checked: string;
|
last_checked: string;
|
||||||
latest_version: string;
|
latest_version: string;
|
||||||
current_version: string;
|
current_version: string;
|
||||||
@@ -88,6 +88,9 @@ export async function updateCheck(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update current version
|
||||||
|
checkFile.current_version = versions[0];
|
||||||
|
|
||||||
// Only check in the specificed interval
|
// Only check in the specificed interval
|
||||||
if (Date.now() >= new Date(checkFile.last_checked).getTime() + interval) {
|
if (Date.now() >= new Date(checkFile.last_checked).getTime() + interval) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import {
|
|||||||
assertNotMatch,
|
assertNotMatch,
|
||||||
} from "$std/testing/asserts.ts";
|
} from "$std/testing/asserts.ts";
|
||||||
import versions from "../versions.json" assert { type: "json" };
|
import versions from "../versions.json" assert { type: "json" };
|
||||||
|
import { CheckFile } from "$fresh/src/dev/update_check.ts";
|
||||||
|
import { WEEK } from "$fresh/src/dev/deps.ts";
|
||||||
|
|
||||||
Deno.test({
|
Deno.test({
|
||||||
name: "stores update check file in $HOME/fresh",
|
name: "stores update check file in $HOME/fresh",
|
||||||
@@ -78,20 +80,20 @@ Deno.test({
|
|||||||
env: {
|
env: {
|
||||||
CI: "false",
|
CI: "false",
|
||||||
HOME: tmpDirName,
|
HOME: tmpDirName,
|
||||||
LATEST_VERSION: "1.30.0",
|
LATEST_VERSION: "999.999.0",
|
||||||
},
|
},
|
||||||
}).output();
|
}).output();
|
||||||
|
|
||||||
const decoder = new TextDecoder();
|
const decoder = new TextDecoder();
|
||||||
|
|
||||||
const stdout = colors.stripColor(decoder.decode(out.stdout));
|
const stdout = colors.stripColor(decoder.decode(out.stdout));
|
||||||
assertMatch(stdout, /Fresh 1\.30\.0 is available/);
|
assertMatch(stdout, /Fresh 999\.999\.0 is available/);
|
||||||
|
|
||||||
// Updates check file
|
// Updates check file
|
||||||
const text = JSON.parse(await Deno.readTextFile(filePath));
|
const text = JSON.parse(await Deno.readTextFile(filePath));
|
||||||
assertEquals(text, {
|
assertEquals(text, {
|
||||||
current_version: "1.1.0",
|
current_version: versions[0],
|
||||||
latest_version: "1.30.0",
|
latest_version: "999.999.0",
|
||||||
last_checked: text.last_checked,
|
last_checked: text.last_checked,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -154,3 +156,35 @@ Deno.test({
|
|||||||
await Deno.remove(tmpDirName, { recursive: true });
|
await Deno.remove(tmpDirName, { recursive: true });
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Deno.test({
|
||||||
|
name: "updates current version in cache file",
|
||||||
|
async fn() {
|
||||||
|
const tmpDirName = await Deno.makeTempDir();
|
||||||
|
|
||||||
|
const checkFile: CheckFile = {
|
||||||
|
current_version: "1.2.0",
|
||||||
|
latest_version: "1.2.0",
|
||||||
|
last_checked: new Date(Date.now() - WEEK).toISOString(),
|
||||||
|
};
|
||||||
|
|
||||||
|
await Deno.writeTextFile(
|
||||||
|
join(tmpDirName, "latest.json"),
|
||||||
|
JSON.stringify(checkFile, null, 2),
|
||||||
|
);
|
||||||
|
|
||||||
|
const out = await new Deno.Command(Deno.execPath(), {
|
||||||
|
args: ["run", "-A", "./tests/fixture_update_check/mod.ts"],
|
||||||
|
env: {
|
||||||
|
HOME: tmpDirName,
|
||||||
|
LATEST_VERSION: versions[0],
|
||||||
|
},
|
||||||
|
}).output();
|
||||||
|
|
||||||
|
const decoder = new TextDecoder();
|
||||||
|
const stdout = colors.stripColor(decoder.decode(out.stdout));
|
||||||
|
assertNotMatch(stdout, /Fresh .* is available/);
|
||||||
|
|
||||||
|
await Deno.remove(tmpDirName, { recursive: true });
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user