mirror of
https://github.com/denoland/deno.git
synced 2025-01-22 06:09:25 -05:00
fix(std/tesing/asserts): assertEquals/NotEquals should use milliseconds in Date (#6644)
This commit is contained in:
parent
714b894370
commit
63b81f97cf
3 changed files with 49 additions and 3 deletions
|
@ -14,7 +14,11 @@ import { ensureSymlink, ensureSymlinkSync } from "./ensure_symlink.ts";
|
|||
|
||||
const testdataDir = path.resolve("fs", "testdata");
|
||||
|
||||
function testCopy(name: string, cb: (tempDir: string) => Promise<void>): void {
|
||||
function testCopy(
|
||||
name: string,
|
||||
cb: (tempDir: string) => Promise<void>,
|
||||
ignore = false
|
||||
): void {
|
||||
Deno.test({
|
||||
name,
|
||||
async fn(): Promise<void> {
|
||||
|
@ -24,9 +28,17 @@ function testCopy(name: string, cb: (tempDir: string) => Promise<void>): void {
|
|||
await cb(tempDir);
|
||||
await Deno.remove(tempDir, { recursive: true });
|
||||
},
|
||||
ignore,
|
||||
});
|
||||
}
|
||||
|
||||
function testCopyIgnore(
|
||||
name: string,
|
||||
cb: (tempDir: string) => Promise<void>
|
||||
): void {
|
||||
testCopy(name, cb, true);
|
||||
}
|
||||
|
||||
function testCopySync(name: string, cb: (tempDir: string) => void): void {
|
||||
Deno.test({
|
||||
name,
|
||||
|
@ -132,7 +144,8 @@ testCopy(
|
|||
}
|
||||
);
|
||||
|
||||
testCopy(
|
||||
// TODO(#6644) This case is ignored because of the issue #5065.
|
||||
testCopyIgnore(
|
||||
"[fs] copy with preserve timestamps",
|
||||
async (tempDir: string): Promise<void> => {
|
||||
const srcFile = path.join(testdataDir, "copy_file.txt");
|
||||
|
|
|
@ -82,11 +82,13 @@ export function equal(c: unknown, d: unknown): boolean {
|
|||
a &&
|
||||
b &&
|
||||
((a instanceof RegExp && b instanceof RegExp) ||
|
||||
(a instanceof Date && b instanceof Date) ||
|
||||
(a instanceof URL && b instanceof URL))
|
||||
) {
|
||||
return String(a) === String(b);
|
||||
}
|
||||
if (a instanceof Date && b instanceof Date) {
|
||||
return a.getTime() === b.getTime();
|
||||
}
|
||||
if (Object.is(a, b)) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -41,6 +41,12 @@ Deno.test("testingEqual", function (): void {
|
|||
assert(!equal(/deno/, /node/));
|
||||
assert(equal(new Date(2019, 0, 3), new Date(2019, 0, 3)));
|
||||
assert(!equal(new Date(2019, 0, 3), new Date(2019, 1, 3)));
|
||||
assert(
|
||||
!equal(
|
||||
new Date(2019, 0, 3, 4, 20, 1, 10),
|
||||
new Date(2019, 0, 3, 4, 20, 1, 20)
|
||||
)
|
||||
);
|
||||
assert(equal(new Set([1]), new Set([1])));
|
||||
assert(!equal(new Set([1]), new Set([2])));
|
||||
assert(equal(new Set([1, 2, 3]), new Set([3, 2, 1])));
|
||||
|
@ -128,6 +134,10 @@ Deno.test("testingNotEquals", function (): void {
|
|||
const b = { bar: "foo" };
|
||||
assertNotEquals(a, b);
|
||||
assertNotEquals("Denosaurus", "Tyrannosaurus");
|
||||
assertNotEquals(
|
||||
new Date(2019, 0, 3, 4, 20, 1, 10),
|
||||
new Date(2019, 0, 3, 4, 20, 1, 20)
|
||||
);
|
||||
let didThrow;
|
||||
try {
|
||||
assertNotEquals("Raptor", "Raptor");
|
||||
|
@ -364,6 +374,27 @@ Deno.test({
|
|||
},
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "failed with date",
|
||||
fn(): void {
|
||||
assertThrows(
|
||||
(): void =>
|
||||
assertEquals(
|
||||
new Date(2019, 0, 3, 4, 20, 1, 10),
|
||||
new Date(2019, 0, 3, 4, 20, 1, 20)
|
||||
),
|
||||
AssertionError,
|
||||
[
|
||||
"Values are not equal:",
|
||||
...createHeader(),
|
||||
removed(`- ${new Date(2019, 0, 3, 4, 20, 1, 10).toISOString()}`),
|
||||
added(`+ ${new Date(2019, 0, 3, 4, 20, 1, 20).toISOString()}`),
|
||||
"",
|
||||
].join("\n")
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "strict pass case",
|
||||
fn(): void {
|
||||
|
|
Loading…
Add table
Reference in a new issue