test(testing): correct test names (#4585)

This commit is contained in:
Asher Gomez 2024-04-15 16:39:17 +10:00 committed by GitHub
parent e299c8b689
commit bfefdd713d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 189 additions and 189 deletions

View File

@ -1,6 +1,6 @@
export const snapshot = {}; export const snapshot = {};
snapshot[`Snapshot Test - Options > path > relative 1`] = ` snapshot[`assertSnapshot() - options > path > relative 1`] = `
[ [
1, 1,
2, 2,
@ -8,7 +8,7 @@ snapshot[`Snapshot Test - Options > path > relative 1`] = `
] ]
`; `;
snapshot[`Snapshot Test - Options > path > absolute 1`] = ` snapshot[`assertSnapshot() - options > path > absolute 1`] = `
[ [
1, 1,
2, 2,

View File

@ -1,6 +1,6 @@
export const snapshot = {}; export const snapshot = {};
snapshot[`Snapshot Test - Options > dir > relative 1`] = ` snapshot[`assertSnapshot() - options > dir > relative 1`] = `
[ [
1, 1,
2, 2,
@ -8,7 +8,7 @@ snapshot[`Snapshot Test - Options > dir > relative 1`] = `
] ]
`; `;
snapshot[`Snapshot Test - Options > dir > absolute 1`] = ` snapshot[`assertSnapshot() - options > dir > absolute 1`] = `
[ [
1, 1,
2, 2,

View File

@ -1,20 +1,20 @@
export const snapshot = {}; export const snapshot = {};
snapshot[`Snapshot Test 1`] = ` snapshot[`assertSnapshot() 1`] = `
{ {
a: 1, a: 1,
b: 2, b: 2,
} }
`; `;
snapshot[`Snapshot Test 2`] = ` snapshot[`assertSnapshot() 2`] = `
TestClass { TestClass {
a: 1, a: 1,
b: 2, b: 2,
} }
`; `;
snapshot[`Snapshot Test 3`] = ` snapshot[`assertSnapshot() 3`] = `
Map(3) { Map(3) {
"Hello" => "World!", "Hello" => "World!",
1 => 2, 1 => 2,
@ -22,7 +22,7 @@ Map(3) {
} }
`; `;
snapshot[`Snapshot Test 4`] = ` snapshot[`assertSnapshot() 4`] = `
Set(3) { Set(3) {
1, 1,
2, 2,
@ -30,15 +30,15 @@ Set(3) {
} }
`; `;
snapshot[`Snapshot Test 5`] = ` snapshot[`assertSnapshot() 5`] = `
{ {
fn: [Function: fn], fn: [Function: fn],
} }
`; `;
snapshot[`Snapshot Test 6`] = `[Function: fn]`; snapshot[`assertSnapshot() 6`] = `[Function: fn]`;
snapshot[`Snapshot Test 7`] = ` snapshot[`assertSnapshot() 7`] = `
[ [
1, 1,
2, 2,
@ -46,23 +46,23 @@ snapshot[`Snapshot Test 7`] = `
] ]
`; `;
snapshot[`Snapshot Test 8`] = `"hello world"`; snapshot[`assertSnapshot() 8`] = `"hello world"`;
snapshot[`Snapshot Test - step 1`] = ` snapshot[`assertSnapshot() - step 1`] = `
{ {
a: 1, a: 1,
b: 2, b: 2,
} }
`; `;
snapshot[`Snapshot Test - step > Nested 1`] = ` snapshot[`assertSnapshot() - step > nested 1`] = `
TestClass { TestClass {
a: 1, a: 1,
b: 2, b: 2,
} }
`; `;
snapshot[`Snapshot Test - step > Nested 2`] = ` snapshot[`assertSnapshot() - step > nested 2`] = `
Map(3) { Map(3) {
"Hello" => "World!", "Hello" => "World!",
1 => 2, 1 => 2,
@ -70,7 +70,7 @@ Map(3) {
} }
`; `;
snapshot[`Snapshot Test - step > Nested > Nested Nested 1`] = ` snapshot[`assertSnapshot() - step > nested > double-nested 1`] = `
Set(3) { Set(3) {
1, 1,
2, 2,
@ -78,15 +78,15 @@ Set(3) {
} }
`; `;
snapshot[`Snapshot Test - step > Nested > Nested Nested 2`] = ` snapshot[`assertSnapshot() - step > nested > double-nested 2`] = `
{ {
fn: [Function: fn], fn: [Function: fn],
} }
`; `;
snapshot[`Snapshot Test - step > Nested > Nested Nested 3`] = `[Function: fn]`; snapshot[`assertSnapshot() - step > nested > double-nested 3`] = `[Function: fn]`;
snapshot[`Snapshot Test - step > Nested 3`] = ` snapshot[`assertSnapshot() - step > nested 3`] = `
[ [
1, 1,
2, 2,
@ -94,16 +94,16 @@ snapshot[`Snapshot Test - step > Nested 3`] = `
] ]
`; `;
snapshot[`Snapshot Test - step 2`] = `"hello world"`; snapshot[`assertSnapshot() - step 2`] = `"hello world"`;
snapshot[`Snapshot Test - Adverse String \\ \` \${} 1`] = `"\\\\ \` \${}"`; snapshot[`assertSnapshot() - adverse string \\ \` \${} 1`] = `"\\\\ \` \${}"`;
snapshot[`Snapshot Test - Default serializer 1`] = ` snapshot[`assertSnapshot() - default serializer 1`] = `
"a "a
b c" b c"
`; `;
snapshot[`Snapshot Test - Multi-Line Strings > string 1`] = ` snapshot[`assertSnapshot() - multi-line strings > string 1`] = `
" "
<html> <html>
<head> <head>
@ -120,7 +120,7 @@ snapshot[`Snapshot Test - Multi-Line Strings > string 1`] = `
</html>" </html>"
`; `;
snapshot[`Snapshot Test - Multi-Line Strings > string in array 1`] = ` snapshot[`assertSnapshot() - multi-line strings > string in array 1`] = `
[ [
" "
<h1> <h1>
@ -133,7 +133,7 @@ snapshot[`Snapshot Test - Multi-Line Strings > string in array 1`] = `
] ]
`; `;
snapshot[`Snapshot Test - Multi-Line Strings > string in object 1`] = ` snapshot[`assertSnapshot() - multi-line strings > string in object 1`] = `
{ {
str: " str: "
Line #1 Line #1
@ -142,7 +142,7 @@ snapshot[`Snapshot Test - Multi-Line Strings > string in object 1`] = `
} }
`; `;
snapshot[`Snapshot Test - Failed Assertion > Object 1`] = ` snapshot[`assertSnapshot() - failed assertion > object 1`] = `
"Snapshot does not match: "Snapshot does not match:
@ -157,7 +157,7 @@ snapshot[`Snapshot Test - Failed Assertion > Object 1`] = `
" "
`; `;
snapshot[`Snapshot Test - Failed Assertion > String 1`] = ` snapshot[`assertSnapshot() - failed assertion > string 1`] = `
'Snapshot does not match: 'Snapshot does not match:
@ -186,7 +186,7 @@ snapshot[`custom name 2`] = `
] ]
`; `;
snapshot[`Snapshot Test - Options > serializer 1`] = ` snapshot[`assertSnapshot() - options > serializer 1`] = `
Array Length: 3 Array Length: 3
[ [
@ -196,11 +196,11 @@ Array Length: 3
] ]
`; `;
snapshot[`Snapshot Test - Options > msg > missing snapshot 1`] = `"[CUSTOM ERROR MESSAGE - MISSING SNAPSHOT]"`; snapshot[`assertSnapshot() - options > msg > missing snapshot 1`] = `"[CUSTOM ERROR MESSAGE - MISSING SNAPSHOT]"`;
snapshot[`Snapshot Test - Options > msg > missing snapshot file 1`] = `"[CUSTOM ERROR MESSAGE - MISSING SNAPSHOT]"`; snapshot[`assertSnapshot() - options > msg > missing snapshot file 1`] = `"[CUSTOM ERROR MESSAGE - MISSING SNAPSHOT]"`;
snapshot[`Snapshot Test - Options > mode 1`] = ` snapshot[`assertSnapshot() - options > mode 1`] = `
" "
[ [
1, 1,
@ -210,7 +210,7 @@ snapshot[`Snapshot Test - Options > mode 1`] = `
" "
`; `;
snapshot[`Snapshot Test - Options > mode 2`] = ` snapshot[`assertSnapshot() - options > mode 2`] = `
"running 1 test from <tempDir>/test.ts "running 1 test from <tempDir>/test.ts
snapshot ... ok (--ms) snapshot ... ok (--ms)
------- post-test output ------- ------- post-test output -------
@ -223,9 +223,9 @@ ok | 1 passed | 0 failed (--ms)
" "
`; `;
snapshot[`Snapshot Test - Update - New snapshot 1`] = ` snapshot[`assertSnapshot() - update - New snapshot 1`] = `
"running 1 test from <tempDir>/test.ts "running 1 test from <tempDir>/test.ts
Snapshot Test - Update ... ok (--ms) assertSnapshot() - update ... ok (--ms)
------- post-test output ------- ------- post-test output -------
> 1 snapshot updated. > 1 snapshot updated.
@ -236,10 +236,10 @@ ok | 1 passed | 0 failed (--ms)
" "
`; `;
snapshot[`Snapshot Test - Update - New snapshot 2`] = ` snapshot[`assertSnapshot() - update - New snapshot 2`] = `
"export const snapshot = {}; "export const snapshot = {};
snapshot[\`Snapshot Test - Update 1\`] = \` snapshot[\`assertSnapshot() - update 1\`] = \`
[ [
1, 1,
2, 2,
@ -248,19 +248,19 @@ snapshot[\`Snapshot Test - Update 1\`] = \`
" "
`; `;
snapshot[`Snapshot Test - Update - Existing snapshot - no changes 1`] = ` snapshot[`assertSnapshot() - update - Existing snapshot - no changes 1`] = `
"running 1 test from <tempDir>/test.ts "running 1 test from <tempDir>/test.ts
Snapshot Test - Update ... ok (--ms) assertSnapshot() - update ... ok (--ms)
ok | 1 passed | 0 failed (--ms) ok | 1 passed | 0 failed (--ms)
" "
`; `;
snapshot[`Snapshot Test - Update - Existing snapshot - no changes 2`] = ` snapshot[`assertSnapshot() - update - Existing snapshot - no changes 2`] = `
"export const snapshot = {}; "export const snapshot = {};
snapshot[\`Snapshot Test - Update 1\`] = \` snapshot[\`assertSnapshot() - update 1\`] = \`
[ [
1, 1,
2, 2,
@ -269,9 +269,9 @@ snapshot[\`Snapshot Test - Update 1\`] = \`
" "
`; `;
snapshot[`Snapshot Test - Update - Existing snapshot - updates 1`] = ` snapshot[`assertSnapshot() - update - Existing snapshot - updates 1`] = `
"running 1 test from <tempDir>/test.ts "running 1 test from <tempDir>/test.ts
Snapshot Test - Update ... ok (--ms) assertSnapshot() - update ... ok (--ms)
------- post-test output ------- ------- post-test output -------
> 1 snapshot updated. > 1 snapshot updated.
@ -282,10 +282,10 @@ ok | 1 passed | 0 failed (--ms)
" "
`; `;
snapshot[`Snapshot Test - Update - Existing snapshot - updates 2`] = ` snapshot[`assertSnapshot() - update - Existing snapshot - updates 2`] = `
"export const snapshot = {}; "export const snapshot = {};
snapshot[\`Snapshot Test - Update 1\`] = \` snapshot[\`assertSnapshot() - update 1\`] = \`
[ [
1, 1,
2, 2,
@ -296,7 +296,7 @@ snapshot[\`Snapshot Test - Update 1\`] = \`
" "
`; `;
snapshot[`Snapshot Test - Update - Existing snapshots - reverse order 1 1`] = ` snapshot[`assertSnapshot() - update - Existing snapshots - reverse order 1 1`] = `
"running 2 tests from <tempDir>/test.ts "running 2 tests from <tempDir>/test.ts
Snapshot Test - First ... ok (--ms) Snapshot Test - First ... ok (--ms)
Snapshot Test - Second ... ok (--ms) Snapshot Test - Second ... ok (--ms)
@ -305,7 +305,7 @@ Snapshot Test - Second ... ok (--ms)
> 2 snapshots updated. > 2 snapshots updated.
> 1 snapshot removed. > 1 snapshot removed.
Snapshot Test - Update 1 assertSnapshot() - update 1
----- post-test output end ----- ----- post-test output end -----
ok | 2 passed | 0 failed (--ms) ok | 2 passed | 0 failed (--ms)
@ -313,7 +313,7 @@ ok | 2 passed | 0 failed (--ms)
" "
`; `;
snapshot[`Snapshot Test - Update - Existing snapshots - reverse order 1 2`] = ` snapshot[`assertSnapshot() - update - Existing snapshots - reverse order 1 2`] = `
'export const snapshot = {}; 'export const snapshot = {};
snapshot[\`Snapshot Test - First 1\`] = \`"FIRST"\`; snapshot[\`Snapshot Test - First 1\`] = \`"FIRST"\`;
@ -322,7 +322,7 @@ snapshot[\`Snapshot Test - Second 1\`] = \`"SECOND"\`;
' '
`; `;
snapshot[`Snapshot Test - Update - Existing snapshots - reverse order 2 1`] = ` snapshot[`assertSnapshot() - update - Existing snapshots - reverse order 2 1`] = `
"running 2 tests from <tempDir>/test.ts "running 2 tests from <tempDir>/test.ts
Snapshot Test - Second ... ok (--ms) Snapshot Test - Second ... ok (--ms)
Snapshot Test - First ... ok (--ms) Snapshot Test - First ... ok (--ms)
@ -332,7 +332,7 @@ ok | 2 passed | 0 failed (--ms)
" "
`; `;
snapshot[`Snapshot Test - Update - Existing snapshots - reverse order 2 2`] = ` snapshot[`assertSnapshot() - update - Existing snapshots - reverse order 2 2`] = `
'export const snapshot = {}; 'export const snapshot = {};
snapshot[\`Snapshot Test - Second 1\`] = \`"SECOND"\`; snapshot[\`Snapshot Test - Second 1\`] = \`"SECOND"\`;
@ -341,13 +341,13 @@ snapshot[\`Snapshot Test - First 1\`] = \`"FIRST"\`;
' '
`; `;
snapshot[`Snapshot Test - Remove - New snapshot 1`] = ` snapshot[`assertSnapshot() - remove - New snapshot 1`] = `
"running 5 tests from <tempDir>/test.ts "running 5 tests from <tempDir>/test.ts
Snapshot Test - Remove - First ... ok (--ms) assertSnapshot() - remove - First ... ok (--ms)
Snapshot Test - Remove - Second ... ok (--ms) assertSnapshot() - remove - Second ... ok (--ms)
Snapshot Test - Remove - Third ... ok (--ms) assertSnapshot() - remove - Third ... ok (--ms)
Snapshot Test - Remove - Fourth ... ok (--ms) assertSnapshot() - remove - Fourth ... ok (--ms)
Snapshot Test - Remove - Fifth ... ok (--ms) assertSnapshot() - remove - Fifth ... ok (--ms)
------- post-test output ------- ------- post-test output -------
> 5 snapshots updated. > 5 snapshots updated.
@ -358,16 +358,16 @@ ok | 5 passed | 0 failed (--ms)
" "
`; `;
snapshot[`Snapshot Test - Remove - Existing snapshot - removed one 1`] = ` snapshot[`assertSnapshot() - remove - Existing snapshot - removed one 1`] = `
"running 4 tests from <tempDir>/test.ts "running 4 tests from <tempDir>/test.ts
Snapshot Test - Remove - First ... ok (--ms) assertSnapshot() - remove - First ... ok (--ms)
Snapshot Test - Remove - Second ... ok (--ms) assertSnapshot() - remove - Second ... ok (--ms)
Snapshot Test - Remove - Fourth ... ok (--ms) assertSnapshot() - remove - Fourth ... ok (--ms)
Snapshot Test - Remove - Fifth ... ok (--ms) assertSnapshot() - remove - Fifth ... ok (--ms)
------- post-test output ------- ------- post-test output -------
> 1 snapshot removed. > 1 snapshot removed.
Snapshot Test - Remove - Third 1 assertSnapshot() - remove - Third 1
----- post-test output end ----- ----- post-test output end -----
ok | 4 passed | 0 failed (--ms) ok | 4 passed | 0 failed (--ms)
@ -375,15 +375,15 @@ ok | 4 passed | 0 failed (--ms)
" "
`; `;
snapshot[`Snapshot Test - Remove - Existing snapshot - removed several 1`] = ` snapshot[`assertSnapshot() - remove - Existing snapshot - removed several 1`] = `
"running 1 test from <tempDir>/test.ts "running 1 test from <tempDir>/test.ts
Snapshot Test - Remove - First ... ok (--ms) assertSnapshot() - remove - First ... ok (--ms)
------- post-test output ------- ------- post-test output -------
> 3 snapshots removed. > 3 snapshots removed.
Snapshot Test - Remove - Second 1 assertSnapshot() - remove - Second 1
Snapshot Test - Remove - Fourth 1 assertSnapshot() - remove - Fourth 1
Snapshot Test - Remove - Fifth 1 assertSnapshot() - remove - Fifth 1
----- post-test output end ----- ----- post-test output end -----
ok | 1 passed | 0 failed (--ms) ok | 1 passed | 0 failed (--ms)
@ -391,7 +391,7 @@ ok | 1 passed | 0 failed (--ms)
" "
`; `;
snapshot[`Snapshot Test - Different Dir - New snapshot 1`] = ` snapshot[`assertSnapshot() - different directory - New snapshot 1`] = `
"running 2 tests from <tempDir>/test.ts "running 2 tests from <tempDir>/test.ts
Snapshot Test - First ... ok (--ms) Snapshot Test - First ... ok (--ms)
Snapshot Test - Second ... ok (--ms) Snapshot Test - Second ... ok (--ms)
@ -412,7 +412,7 @@ ok | 4 passed | 0 failed (--ms)
" "
`; `;
snapshot[`Snapshot Test - Different Dir - Existing snapshot - update 1`] = ` snapshot[`assertSnapshot() - different directory - Existing snapshot - update 1`] = `
"running 2 tests from <tempDir>/test.ts "running 2 tests from <tempDir>/test.ts
Snapshot Test - First ... ok (--ms) Snapshot Test - First ... ok (--ms)
Snapshot Test - Second ... ok (--ms) Snapshot Test - Second ... ok (--ms)
@ -433,7 +433,7 @@ ok | 4 passed | 0 failed (--ms)
" "
`; `;
snapshot[`Snapshot Test - Regression #2140 1`] = ` snapshot[`assertSnapshot() - regression #2140 1`] = `
{ {
content: " content: "
<h1>Testing a page</h1> <h1>Testing a page</h1>
@ -449,7 +449,7 @@ snapshot[`Snapshot Test - Regression #2140 1`] = `
} }
`; `;
snapshot[`Snapshot Test - Regression #2144 1`] = ` snapshot[`assertSnapshot() - regression #2144 1`] = `
{ {
fmt: { fmt: {
files: { files: {
@ -461,12 +461,12 @@ snapshot[`Snapshot Test - Regression #2144 1`] = `
} }
`; `;
snapshot[`Snapshot Test - Empty #2245 1`] = ``; snapshot[`assertSnapshot() - empty #2245 1`] = ``;
snapshot[`SnapshotTest - createAssertSnapshot > No Options 1`] = `This green text has had it's colours stripped`; snapshot[`createAssertSnapshot() > no options 1`] = `This green text has had it's colours stripped`;
snapshot[`SnapshotTest - createAssertSnapshot - Options Object - Custom Name 1`] = `This green text has had it's colours stripped`; snapshot[`createAssertSnapshot() - options object - custom name 1`] = `This green text has had it's colours stripped`;
snapshot[`SnapshotTest - createAssertSnapshot > Message 1`] = `"This snapshot has failed as expected"`; snapshot[`createAssertSnapshot() > message 1`] = `"This snapshot has failed as expected"`;
snapshot[`SnapshotTest - createAssertSnapshot - Composite - Custom Name 1`] = `This green text has had it's colours stripped`; snapshot[`createAssertSnapshot() - composite - custom Name 1`] = `This green text has had it's colours stripped`;

View File

@ -30,7 +30,7 @@ import {
} from "./mock.ts"; } from "./mock.ts";
import { Point, type PointWithExtra, stringifyPoint } from "./_test_utils.ts"; import { Point, type PointWithExtra, stringifyPoint } from "./_test_utils.ts";
Deno.test("spy default", () => { Deno.test("spy()", () => {
const func = spy(); const func = spy();
assertSpyCalls(func, 0); assertSpyCalls(func, 0);
@ -84,7 +84,7 @@ Deno.test("spy default", () => {
assertEquals(func.restored, false); assertEquals(func.restored, false);
}); });
Deno.test("spy function", () => { Deno.test("spy() works on function", () => {
const func = spy((value) => value); const func = spy((value) => value);
assertSpyCalls(func, 0); assertSpyCalls(func, 0);
@ -148,7 +148,7 @@ Deno.test("spy function", () => {
}); });
}); });
Deno.test("spy instance method", () => { Deno.test("spy() works on instance method", () => {
const point = new Point(2, 3); const point = new Point(2, 3);
const func = spy(point, "action"); const func = spy(point, "action");
assertSpyCalls(func, 0); assertSpyCalls(func, 0);
@ -244,7 +244,7 @@ Deno.test("spy instance method", () => {
assertEquals(func.restored, true); assertEquals(func.restored, true);
}); });
Deno.test("spy instance method symbol", () => { Deno.test("spy() works on instance method symbol", () => {
const point = new Point(2, 3); const point = new Point(2, 3);
const func = spy(point, Symbol.iterator); const func = spy(point, Symbol.iterator);
assertSpyCalls(func, 0); assertSpyCalls(func, 0);
@ -282,7 +282,7 @@ Deno.test("spy instance method symbol", () => {
assertEquals(func.restored, true); assertEquals(func.restored, true);
}); });
Deno.test("spy instance method property descriptor", () => { Deno.test("spy() works on instance method property descriptor", () => {
const point = new Point(2, 3); const point = new Point(2, 3);
const actionDescriptor: PropertyDescriptor = { const actionDescriptor: PropertyDescriptor = {
configurable: true, configurable: true,
@ -347,7 +347,7 @@ Deno.test("spy instance method property descriptor", () => {
assertEquals(action.restored, true); assertEquals(action.restored, true);
}); });
Deno.test("spy explicit resource management", () => { Deno.test("spy() supports explicit resource management", () => {
const point = new Point(2, 3); const point = new Point(2, 3);
let funcRef: MethodSpy<Point> | null = null; let funcRef: MethodSpy<Point> | null = null;
{ {
@ -450,7 +450,7 @@ Deno.test("spy explicit resource management", () => {
} }
}); });
Deno.test("spy constructor", () => { Deno.test("spy() works on constructor", () => {
const PointSpy = spy(Point); const PointSpy = spy(Point);
assertSpyCalls(PointSpy, 0); assertSpyCalls(PointSpy, 0);
@ -482,7 +482,7 @@ Deno.test("spy constructor", () => {
); );
}); });
Deno.test("spy constructor of child class", () => { Deno.test("spy() works on constructor of child class", () => {
const PointSpy = spy(Point); const PointSpy = spy(Point);
const PointSpyChild = class extends PointSpy { const PointSpyChild = class extends PointSpy {
override action() { override action() {
@ -510,7 +510,7 @@ Deno.test("spy constructor of child class", () => {
assertSpyCalls(PointSpy, 1); assertSpyCalls(PointSpy, 1);
}); });
Deno.test("stub default", () => { Deno.test("stub()", () => {
const point = new Point(2, 3); const point = new Point(2, 3);
const func = stub(point, "action"); const func = stub(point, "action");
@ -547,7 +547,7 @@ Deno.test("stub default", () => {
assertEquals(func.restored, true); assertEquals(func.restored, true);
}); });
Deno.test("stub function", () => { Deno.test("stub() works on function", () => {
const point = new Point(2, 3); const point = new Point(2, 3);
const returns = [1, "b", 2, "d"]; const returns = [1, "b", 2, "d"];
const func = stub(point, "action", () => returns.shift()); const func = stub(point, "action", () => returns.shift());
@ -585,7 +585,7 @@ Deno.test("stub function", () => {
assertEquals(func.restored, true); assertEquals(func.restored, true);
}); });
Deno.test("stub explicit resource management", () => { Deno.test("stub() supports explicit resource management", () => {
const point = new Point(2, 3); const point = new Point(2, 3);
const returns = [1, "b", 2, "d"]; const returns = [1, "b", 2, "d"];
let funcRef: Stub<Point> | null = null; let funcRef: Stub<Point> | null = null;
@ -630,7 +630,7 @@ Deno.test("stub explicit resource management", () => {
} }
}); });
Deno.test("stub non existent function", () => { Deno.test("stub() handles non existent function", () => {
const point = new Point(2, 3); const point = new Point(2, 3);
const castPoint = point as PointWithExtra; const castPoint = point as PointWithExtra;
let i = 0; let i = 0;
@ -673,7 +673,7 @@ Deno.test("stub non existent function", () => {
}); });
// This doesn't test any runtime code, only if the TypeScript types are correct. // This doesn't test any runtime code, only if the TypeScript types are correct.
Deno.test("stub types", () => { Deno.test("stub() correctly handles types", () => {
// @ts-expect-error Stubbing with incorrect argument types should cause a type error // @ts-expect-error Stubbing with incorrect argument types should cause a type error
stub(new Point(2, 3), "explicitTypes", (_x: string, _y: number) => true); stub(new Point(2, 3), "explicitTypes", (_x: string, _y: number) => true);
@ -714,7 +714,7 @@ Deno.test("stub types", () => {
}); });
}); });
Deno.test("mockSession and mockSessionAsync", async () => { Deno.test("mockSession() and mockSessionAsync()", async () => {
const points = [ const points = [
new Point(2, 3), new Point(2, 3),
new Point(2, 3), new Point(2, 3),
@ -759,7 +759,7 @@ Deno.test("mockSession and mockSessionAsync", async () => {
assertRestored(Array(6).fill(true)); assertRestored(Array(6).fill(true));
}); });
Deno.test("mockSession and restore current session", () => { Deno.test("mockSession() and restore current session", () => {
const points = [ const points = [
new Point(2, 3), new Point(2, 3),
new Point(2, 3), new Point(2, 3),
@ -820,7 +820,7 @@ Deno.test("mockSession and restore current session", () => {
} }
}); });
Deno.test("mockSession and restore multiple sessions", () => { Deno.test("mockSession() and restore multiple sessions", () => {
const points = [ const points = [
new Point(2, 3), new Point(2, 3),
new Point(2, 3), new Point(2, 3),
@ -861,7 +861,7 @@ Deno.test("mockSession and restore multiple sessions", () => {
} }
}); });
Deno.test("assertSpyCalls", () => { Deno.test("assertSpyCalls()", () => {
const spyFunc = spy(); const spyFunc = spy();
assertSpyCalls(spyFunc, 0); assertSpyCalls(spyFunc, 0);
@ -885,7 +885,7 @@ Deno.test("assertSpyCalls", () => {
); );
}); });
Deno.test("assertSpyCall function", () => { Deno.test("assertSpyCall() works with function", () => {
const spyFunc = spy((multiplier?: number) => 5 * (multiplier ?? 1)); const spyFunc = spy((multiplier?: number) => 5 * (multiplier ?? 1));
assertThrows( assertThrows(
@ -960,7 +960,7 @@ Deno.test("assertSpyCall function", () => {
); );
}); });
Deno.test("assertSpyCall method", () => { Deno.test("assertSpyCall() works with method", () => {
const point = new Point(2, 3); const point = new Point(2, 3);
const spyMethod = spy(point, "action"); const spyMethod = spy(point, "action");
@ -1096,7 +1096,7 @@ Deno.test("assertSpyCall method", () => {
class ExampleError extends Error {} class ExampleError extends Error {}
class OtherError extends Error {} class OtherError extends Error {}
Deno.test("assertSpyCall error", () => { Deno.test("assertSpyCall() works with error", () => {
const spyFunc = spy((_value?: number) => { const spyFunc = spy((_value?: number) => {
throw new ExampleError("failed"); throw new ExampleError("failed");
}); });
@ -1228,7 +1228,7 @@ Deno.test("assertSpyCall error", () => {
); );
}); });
Deno.test("assertSpyCallAsync function", async () => { Deno.test("assertSpyCallAsync() works with function", async () => {
const spyFunc = spy((multiplier?: number) => const spyFunc = spy((multiplier?: number) =>
Promise.resolve(5 * (multiplier ?? 1)) Promise.resolve(5 * (multiplier ?? 1))
); );
@ -1310,7 +1310,7 @@ Deno.test("assertSpyCallAsync function", async () => {
); );
}); });
Deno.test("assertSpyCallAsync method", async () => { Deno.test("assertSpyCallAsync() works with method", async () => {
const point: Point = new Point(2, 3); const point: Point = new Point(2, 3);
const spyMethod = stub( const spyMethod = stub(
point, point,
@ -1471,7 +1471,7 @@ Deno.test("assertSpyCallAsync method", async () => {
); );
}); });
Deno.test("assertSpyCallAync on sync value", async () => { Deno.test("assertSpyCallAsync() rejects on sync value", async () => {
const spyFunc = spy(() => 4 as unknown as Promise<number>); const spyFunc = spy(() => 4 as unknown as Promise<number>);
spyFunc(); spyFunc();
@ -1482,7 +1482,7 @@ Deno.test("assertSpyCallAync on sync value", async () => {
); );
}); });
Deno.test("assertSpyCallAync on sync error", async () => { Deno.test("assertSpyCallAsync() rejects on sync error", async () => {
const spyFunc = spy(() => { const spyFunc = spy(() => {
throw new ExampleError("failed"); throw new ExampleError("failed");
}); });
@ -1495,7 +1495,7 @@ Deno.test("assertSpyCallAync on sync error", async () => {
); );
}); });
Deno.test("assertSpyCallAync error", async () => { Deno.test("assertSpyCallAsync() works with error", async () => {
const spyFunc = spy((..._args: number[]): Promise<number> => const spyFunc = spy((..._args: number[]): Promise<number> =>
Promise.reject(new ExampleError("failed")) Promise.reject(new ExampleError("failed"))
); );
@ -1636,7 +1636,7 @@ Deno.test("assertSpyCallAync error", async () => {
); );
}); });
Deno.test("assertSpyArg", () => { Deno.test("assertSpyCallArg()", () => {
const spyFunc = spy(); const spyFunc = spy();
assertThrows( assertThrows(
@ -1703,7 +1703,7 @@ Deno.test("assertSpyArg", () => {
); );
}); });
Deno.test("assertSpyArgs without range", () => { Deno.test("assertSpyCallArgs() throws without range", () => {
const spyFunc = spy(); const spyFunc = spy();
assertThrows( assertThrows(
@ -1775,7 +1775,7 @@ Deno.test("assertSpyArgs without range", () => {
); );
}); });
Deno.test("assertSpyArgs with start only", () => { Deno.test("assertSpyCallArgs() throws with start only", () => {
const spyFunc = spy(); const spyFunc = spy();
assertThrows( assertThrows(
@ -1847,7 +1847,7 @@ Deno.test("assertSpyArgs with start only", () => {
); );
}); });
Deno.test("assertSpyArgs with range", () => { Deno.test("assertSpyCallArgs() throws with range", () => {
const spyFunc = spy(); const spyFunc = spy();
assertThrows( assertThrows(
@ -1921,7 +1921,7 @@ Deno.test("assertSpyArgs with range", () => {
); );
}); });
Deno.test("returnsThis", () => { Deno.test("returnsThis()", () => {
const callback = returnsThis(); const callback = returnsThis();
const obj = { callback, x: 1, y: 2 }; const obj = { callback, x: 1, y: 2 };
const obj2 = { x: 2, y: 3 }; const obj2 = { x: 2, y: 3 };
@ -1930,7 +1930,7 @@ Deno.test("returnsThis", () => {
assertEquals(callback.apply(obj2, []), obj2); assertEquals(callback.apply(obj2, []), obj2);
}); });
Deno.test("returnsArg", () => { Deno.test("returnsArg()", () => {
let callback = returnsArg(0); let callback = returnsArg(0);
assertEquals(callback(), undefined); assertEquals(callback(), undefined);
assertEquals(callback("a"), "a"); assertEquals(callback("a"), "a");
@ -1942,7 +1942,7 @@ Deno.test("returnsArg", () => {
assertEquals(callback("d", "e", "f"), "e"); assertEquals(callback("d", "e", "f"), "e");
}); });
Deno.test("returnsArgs", () => { Deno.test("returnsArgs()", () => {
let callback = returnsArgs(); let callback = returnsArgs();
assertEquals(callback(), []); assertEquals(callback(), []);
assertEquals(callback("a"), ["a"]); assertEquals(callback("a"), ["a"]);
@ -1959,7 +1959,7 @@ Deno.test("returnsArgs", () => {
assertEquals(callback("d", "e", "f", "g"), ["e", "f"]); assertEquals(callback("d", "e", "f", "g"), ["e", "f"]);
}); });
Deno.test("returnsNext with array", () => { Deno.test("returnsNext() works with array", () => {
let results = [1, 2, new Error("oops"), 3]; let results = [1, 2, new Error("oops"), 3];
let callback = returnsNext(results); let callback = returnsNext(results);
assertEquals(callback(), 1); assertEquals(callback(), 1);
@ -1999,7 +1999,7 @@ Deno.test("returnsNext with array", () => {
); );
}); });
Deno.test("returnsNext with iterator", () => { Deno.test("returnsNext() works with iterator", () => {
let results = [1, 2, new Error("oops"), 3]; let results = [1, 2, new Error("oops"), 3];
let callback = returnsNext(results.values()); let callback = returnsNext(results.values());
assertEquals(callback(), 1); assertEquals(callback(), 1);
@ -2039,7 +2039,7 @@ Deno.test("returnsNext with iterator", () => {
); );
}); });
Deno.test("returnsNext with generator", () => { Deno.test("returnsNext() works with generator", () => {
let results = [1, 2, new Error("oops"), 3]; let results = [1, 2, new Error("oops"), 3];
const generator = function* () { const generator = function* () {
yield* results; yield* results;
@ -2082,7 +2082,7 @@ Deno.test("returnsNext with generator", () => {
); );
}); });
Deno.test("resolvesNext with array", async () => { Deno.test("resolvesNext() works with array", async () => {
let results = [ let results = [
1, 1,
new Error("oops"), new Error("oops"),
@ -2138,7 +2138,7 @@ Deno.test("resolvesNext with array", async () => {
); );
}); });
Deno.test("resolvesNext with iterator", async () => { Deno.test("resolvesNext() works with iterator", async () => {
let results = [ let results = [
1, 1,
new Error("oops"), new Error("oops"),
@ -2194,7 +2194,7 @@ Deno.test("resolvesNext with iterator", async () => {
); );
}); });
Deno.test("resolvesNext with async generator", async () => { Deno.test("resolvesNext() works with async generator", async () => {
let results = [ let results = [
1, 1,
new Error("oops"), new Error("oops"),

View File

@ -78,7 +78,7 @@ map.set("Hello", "World!");
map.set(() => "Hello", "World!"); map.set(() => "Hello", "World!");
map.set(1, 2); map.set(1, 2);
Deno.test("Snapshot Test", async (t) => { Deno.test("assertSnapshot()", async (t) => {
await assertSnapshot(t, { a: 1, b: 2 }); await assertSnapshot(t, { a: 1, b: 2 });
await assertSnapshot(t, new TestClass()); await assertSnapshot(t, new TestClass());
await assertSnapshot(t, map); await assertSnapshot(t, map);
@ -89,12 +89,12 @@ Deno.test("Snapshot Test", async (t) => {
await assertSnapshot(t, "hello world"); await assertSnapshot(t, "hello world");
}); });
Deno.test("Snapshot Test - step", async (t) => { Deno.test("assertSnapshot() - step", async (t) => {
await assertSnapshot(t, { a: 1, b: 2 }); await assertSnapshot(t, { a: 1, b: 2 });
await t.step("Nested", async (t) => { await t.step("nested", async (t) => {
await assertSnapshot(t, new TestClass()); await assertSnapshot(t, new TestClass());
await assertSnapshot(t, map); await assertSnapshot(t, map);
await t.step("Nested Nested", async (t) => { await t.step("double-nested", async (t) => {
await assertSnapshot(t, new Set([1, 2, 3])); await assertSnapshot(t, new Set([1, 2, 3]));
await assertSnapshot(t, { fn() {} }); await assertSnapshot(t, { fn() {} });
await assertSnapshot(t, function fn() {}); await assertSnapshot(t, function fn() {});
@ -104,15 +104,15 @@ Deno.test("Snapshot Test - step", async (t) => {
await assertSnapshot(t, "hello world"); await assertSnapshot(t, "hello world");
}); });
Deno.test("Snapshot Test - Adverse String \\ ` ${}", async (t) => { Deno.test("assertSnapshot() - adverse string \\ ` ${}", async (t) => {
await assertSnapshot(t, "\\ ` ${}"); await assertSnapshot(t, "\\ ` ${}");
}); });
Deno.test("Snapshot Test - Default serializer", async (t) => { Deno.test("assertSnapshot() - default serializer", async (t) => {
await assertSnapshot(t, "a\nb\tc"); await assertSnapshot(t, "a\nb\tc");
}); });
Deno.test("Snapshot Test - Multi-Line Strings", async (t) => { Deno.test("assertSnapshot() - multi-line strings", async (t) => {
await t.step("string", async (t) => { await t.step("string", async (t) => {
await assertSnapshot( await assertSnapshot(
t, t,
@ -157,7 +157,7 @@ Deno.test("Snapshot Test - Multi-Line Strings", async (t) => {
}); });
Deno.test( Deno.test(
"Snapshot Test - Failed Assertion", "assertSnapshot() - failed assertion",
testFnWithTempDir(async (t, tempDir) => { testFnWithTempDir(async (t, tempDir) => {
let count = 0; let count = 0;
async function testFailedAssertion<T>( async function testFailedAssertion<T>(
@ -188,19 +188,19 @@ ${serialize(snapshot)}
} }
} }
await t.step("Object", async (t) => { await t.step("object", async (t) => {
const error = await testFailedAssertion([1, 2, 3], [1, 2]); const error = await testFailedAssertion([1, 2, 3], [1, 2]);
await assertSnapshot(t, stripAnsiCode(error.message)); await assertSnapshot(t, stripAnsiCode(error.message));
}); });
await t.step("String", async (t) => { await t.step("string", async (t) => {
const error = await testFailedAssertion("Hello World!", "Hello!"); const error = await testFailedAssertion("Hello World!", "Hello!");
await assertSnapshot(t, stripAnsiCode(error.message)); await assertSnapshot(t, stripAnsiCode(error.message));
}); });
}), }),
); );
Deno.test("Snapshot Test - Options", async (t) => { Deno.test("assertSnapshot() - options", async (t) => {
const VALUE = [1, 2, 3]; const VALUE = [1, 2, 3];
await t.step("dir", async (t) => { await t.step("dir", async (t) => {
@ -334,7 +334,7 @@ Deno.test("Snapshot Test - Options", async (t) => {
}); });
Deno.test( Deno.test(
"Snapshot Test - Update", "assertSnapshot() - update",
testFnWithTempDir(async (t, tempDir) => { testFnWithTempDir(async (t, tempDir) => {
const tempTestFileName = "test.ts"; const tempTestFileName = "test.ts";
const tempTestFilePath = join(tempDir, tempTestFileName); const tempTestFilePath = join(tempDir, tempTestFileName);
@ -379,7 +379,7 @@ Deno.test(
` `
import { assertSnapshot } from "${SNAPSHOT_MODULE_URL}"; import { assertSnapshot } from "${SNAPSHOT_MODULE_URL}";
Deno.test("Snapshot Test - Update", async (t) => { Deno.test("assertSnapshot() - update", async (t) => {
await assertSnapshot(t, [ await assertSnapshot(t, [
1, 1,
2, 2,
@ -389,10 +389,10 @@ Deno.test(
assertNoError(result1.error); assertNoError(result1.error);
await assertSnapshot(t, formatTestOutput(result1.output), { await assertSnapshot(t, formatTestOutput(result1.output), {
name: "Snapshot Test - Update - New snapshot", name: "assertSnapshot() - update - New snapshot",
}); });
await assertSnapshot(t, result1.snapshots, { await assertSnapshot(t, result1.snapshots, {
name: "Snapshot Test - Update - New snapshot", name: "assertSnapshot() - update - New snapshot",
}); });
/** /**
@ -402,7 +402,7 @@ Deno.test(
` `
import { assertSnapshot } from "${SNAPSHOT_MODULE_URL}"; import { assertSnapshot } from "${SNAPSHOT_MODULE_URL}";
Deno.test("Snapshot Test - Update", async (t) => { Deno.test("assertSnapshot() - update", async (t) => {
await assertSnapshot(t, [ await assertSnapshot(t, [
1, 1,
2, 2,
@ -412,10 +412,10 @@ Deno.test(
assertNoError(result2.error); assertNoError(result2.error);
await assertSnapshot(t, formatTestOutput(result2.output), { await assertSnapshot(t, formatTestOutput(result2.output), {
name: "Snapshot Test - Update - Existing snapshot - no changes", name: "assertSnapshot() - update - Existing snapshot - no changes",
}); });
await assertSnapshot(t, result2.snapshots, { await assertSnapshot(t, result2.snapshots, {
name: "Snapshot Test - Update - Existing snapshot - no changes", name: "assertSnapshot() - update - Existing snapshot - no changes",
}); });
/** /**
@ -424,7 +424,7 @@ Deno.test(
const result3 = await runTestWithUpdateFlag(` const result3 = await runTestWithUpdateFlag(`
import { assertSnapshot } from "${SNAPSHOT_MODULE_URL}"; import { assertSnapshot } from "${SNAPSHOT_MODULE_URL}";
Deno.test("Snapshot Test - Update", async (t) => { Deno.test("assertSnapshot() - update", async (t) => {
await assertSnapshot(t, [ await assertSnapshot(t, [
1, 1,
2, 2,
@ -436,10 +436,10 @@ Deno.test(
assertNoError(result3.error); assertNoError(result3.error);
await assertSnapshot(t, formatTestOutput(result3.output), { await assertSnapshot(t, formatTestOutput(result3.output), {
name: "Snapshot Test - Update - Existing snapshot - updates", name: "assertSnapshot() - update - Existing snapshot - updates",
}); });
await assertSnapshot(t, result3.snapshots, { await assertSnapshot(t, result3.snapshots, {
name: "Snapshot Test - Update - Existing snapshot - updates", name: "assertSnapshot() - update - Existing snapshot - updates",
}); });
/** /**
@ -459,10 +459,10 @@ Deno.test(
assertNoError(result4.error); assertNoError(result4.error);
await assertSnapshot(t, formatTestOutput(result4.output), { await assertSnapshot(t, formatTestOutput(result4.output), {
name: "Snapshot Test - Update - Existing snapshots - reverse order 1", name: "assertSnapshot() - update - Existing snapshots - reverse order 1",
}); });
await assertSnapshot(t, result4.snapshots, { await assertSnapshot(t, result4.snapshots, {
name: "Snapshot Test - Update - Existing snapshots - reverse order 1", name: "assertSnapshot() - update - Existing snapshots - reverse order 1",
}); });
/** /**
@ -482,16 +482,16 @@ Deno.test(
assertNoError(result5.error); assertNoError(result5.error);
await assertSnapshot(t, formatTestOutput(result5.output), { await assertSnapshot(t, formatTestOutput(result5.output), {
name: "Snapshot Test - Update - Existing snapshots - reverse order 2", name: "assertSnapshot() - update - Existing snapshots - reverse order 2",
}); });
await assertSnapshot(t, result5.snapshots, { await assertSnapshot(t, result5.snapshots, {
name: "Snapshot Test - Update - Existing snapshots - reverse order 2", name: "assertSnapshot() - update - Existing snapshots - reverse order 2",
}); });
}), }),
); );
Deno.test( Deno.test(
"Snapshot Test - Remove", "assertSnapshot() - remove",
testFnWithTempDir(async (t, tempDir) => { testFnWithTempDir(async (t, tempDir) => {
const tempTestFileName = "test.ts"; const tempTestFileName = "test.ts";
const tempTestFilePath = join(tempDir, tempTestFileName); const tempTestFilePath = join(tempDir, tempTestFileName);
@ -530,23 +530,23 @@ Deno.test(
` `
import { assertSnapshot } from "${SNAPSHOT_MODULE_URL}"; import { assertSnapshot } from "${SNAPSHOT_MODULE_URL}";
Deno.test("Snapshot Test - Remove - First", async (t) => { Deno.test("assertSnapshot() - remove - First", async (t) => {
await assertSnapshot(t, { a: 1, b: 2 }); await assertSnapshot(t, { a: 1, b: 2 });
}); });
Deno.test("Snapshot Test - Remove - Second", async (t) => { Deno.test("assertSnapshot() - remove - Second", async (t) => {
await assertSnapshot(t, { c: 3, d: 4 }); await assertSnapshot(t, { c: 3, d: 4 });
}); });
Deno.test("Snapshot Test - Remove - Third", async (t) => { Deno.test("assertSnapshot() - remove - Third", async (t) => {
await assertSnapshot(t, { e: 5, f: 6 }); await assertSnapshot(t, { e: 5, f: 6 });
}); });
Deno.test("Snapshot Test - Remove - Fourth", async (t) => { Deno.test("assertSnapshot() - remove - Fourth", async (t) => {
await assertSnapshot(t, { g: 7, h: 8 }); await assertSnapshot(t, { g: 7, h: 8 });
}); });
Deno.test("Snapshot Test - Remove - Fifth", async (t) => { Deno.test("assertSnapshot() - remove - Fifth", async (t) => {
await assertSnapshot(t, { i: 9, j: 10 }); await assertSnapshot(t, { i: 9, j: 10 });
}); });
`, `,
@ -554,7 +554,7 @@ Deno.test(
assertNoError(result1.error); assertNoError(result1.error);
await assertSnapshot(t, formatTestOutput(result1.output), { await assertSnapshot(t, formatTestOutput(result1.output), {
name: "Snapshot Test - Remove - New snapshot", name: "assertSnapshot() - remove - New snapshot",
}); });
/** /**
@ -564,19 +564,19 @@ Deno.test(
` `
import { assertSnapshot } from "${SNAPSHOT_MODULE_URL}"; import { assertSnapshot } from "${SNAPSHOT_MODULE_URL}";
Deno.test("Snapshot Test - Remove - First", async (t) => { Deno.test("assertSnapshot() - remove - First", async (t) => {
await assertSnapshot(t, { a: 1, b: 2 }); await assertSnapshot(t, { a: 1, b: 2 });
}); });
Deno.test("Snapshot Test - Remove - Second", async (t) => { Deno.test("assertSnapshot() - remove - Second", async (t) => {
await assertSnapshot(t, { c: 3, d: 4 }); await assertSnapshot(t, { c: 3, d: 4 });
}); });
Deno.test("Snapshot Test - Remove - Fourth", async (t) => { Deno.test("assertSnapshot() - remove - Fourth", async (t) => {
await assertSnapshot(t, { g: 7, h: 8 }); await assertSnapshot(t, { g: 7, h: 8 });
}); });
Deno.test("Snapshot Test - Remove - Fifth", async (t) => { Deno.test("assertSnapshot() - remove - Fifth", async (t) => {
await assertSnapshot(t, { i: 9, j: 10 }); await assertSnapshot(t, { i: 9, j: 10 });
}); });
`, `,
@ -584,7 +584,7 @@ Deno.test(
assertNoError(result2.error); assertNoError(result2.error);
await assertSnapshot(t, formatTestOutput(result2.output), { await assertSnapshot(t, formatTestOutput(result2.output), {
name: "Snapshot Test - Remove - Existing snapshot - removed one", name: "assertSnapshot() - remove - Existing snapshot - removed one",
}); });
/** /**
@ -594,7 +594,7 @@ Deno.test(
` `
import { assertSnapshot } from "${SNAPSHOT_MODULE_URL}"; import { assertSnapshot } from "${SNAPSHOT_MODULE_URL}";
Deno.test("Snapshot Test - Remove - First", async (t) => { Deno.test("assertSnapshot() - remove - First", async (t) => {
await assertSnapshot(t, { a: 1, b: 2 }); await assertSnapshot(t, { a: 1, b: 2 });
}); });
`, `,
@ -602,13 +602,13 @@ Deno.test(
assertNoError(result3.error); assertNoError(result3.error);
await assertSnapshot(t, formatTestOutput(result3.output), { await assertSnapshot(t, formatTestOutput(result3.output), {
name: "Snapshot Test - Remove - Existing snapshot - removed several", name: "assertSnapshot() - remove - Existing snapshot - removed several",
}); });
}), }),
); );
Deno.test( Deno.test(
"Snapshot Test - Different Dir", "assertSnapshot() - different directory",
testFnWithDifferentTempDir(async (t, tempDir1, tempDir2) => { testFnWithDifferentTempDir(async (t, tempDir1, tempDir2) => {
const tempTestFileName = "test.ts"; const tempTestFileName = "test.ts";
const tempTestFilePath1 = join(tempDir1, tempTestFileName); const tempTestFilePath1 = join(tempDir1, tempTestFileName);
@ -681,7 +681,7 @@ Deno.test(
assertNoError(result1.error); assertNoError(result1.error);
await assertSnapshot(t, formatTestOutput(result1.output), { await assertSnapshot(t, formatTestOutput(result1.output), {
name: "Snapshot Test - Different Dir - New snapshot", name: "assertSnapshot() - different directory - New snapshot",
}); });
/** /**
@ -721,14 +721,15 @@ Deno.test(
); );
assertNoError(result2.error); assertNoError(result2.error);
await assertSnapshot(t, formatTestOutput(result2.output), { await assertSnapshot(t, formatTestOutput(result2.output), {
name: "Snapshot Test - Different Dir - Existing snapshot - update", name:
"assertSnapshot() - different directory - Existing snapshot - update",
}); });
}), }),
); );
// Regression test for https://github.com/denoland/deno_std/issues/2140 // Regression test for https://github.com/denoland/deno_std/issues/2140
// Long strings should not be truncated with ellipsis // Long strings should not be truncated with ellipsis
Deno.test("Snapshot Test - Regression #2140", async (t) => { Deno.test("assertSnapshot() - regression #2140", async (t) => {
await assertSnapshot(t, { await assertSnapshot(t, {
title: "Testing a page", title: "Testing a page",
content: ` content: `
@ -746,7 +747,7 @@ Deno.test("Snapshot Test - Regression #2140", async (t) => {
// Regression test for https://github.com/denoland/deno_std/issues/2144 // Regression test for https://github.com/denoland/deno_std/issues/2144
// Empty arrays should be compacted // Empty arrays should be compacted
Deno.test("Snapshot Test - Regression #2144", async (t) => { Deno.test("assertSnapshot() - regression #2144", async (t) => {
const config = { const config = {
fmt: { fmt: {
files: { files: {
@ -759,34 +760,33 @@ Deno.test("Snapshot Test - Regression #2144", async (t) => {
await assertSnapshot(t, config); await assertSnapshot(t, config);
}); });
Deno.test("Snapshot Test - Empty #2245", async (t) => { Deno.test("assertSnapshot() - empty #2245", async (t) => {
await assertSnapshot(t, "", { serializer: (x) => x }); await assertSnapshot(t, "", { serializer: (x) => x });
}); });
Deno.test("SnapshotTest - createAssertSnapshot", async (t) => { Deno.test("createAssertSnapshot()", async (t) => {
const assertMonochromeSnapshot = createAssertSnapshot<string>({ const assertMonochromeSnapshot = createAssertSnapshot<string>({
serializer: stripAnsiCode, serializer: stripAnsiCode,
}); });
await t.step("No Options", async (t) => { await t.step("no options", async (t) => {
await assertMonochromeSnapshot( await assertMonochromeSnapshot(
t, t,
"\x1b[32mThis green text has had it's colours stripped\x1b[39m", "\x1b[32mThis green text has had it's colours stripped\x1b[39m",
); );
}); });
await t.step("Options Object", async (t) => { await t.step("options object", async (t) => {
await assertMonochromeSnapshot( await assertMonochromeSnapshot(
t, t,
"\x1b[32mThis green text has had it's colours stripped\x1b[39m", "\x1b[32mThis green text has had it's colours stripped\x1b[39m",
{ {
name: name: "createAssertSnapshot() - options object - custom name",
"SnapshotTest - createAssertSnapshot - Options Object - Custom Name",
}, },
); );
}); });
await t.step("Message", async (t) => { await t.step("message", async (t) => {
const assertMissingSnapshot = createAssertSnapshot<string>({ const assertMissingSnapshot = createAssertSnapshot<string>({
mode: "assert", mode: "assert",
name: "[MISSING SNAPSHOT]", name: "[MISSING SNAPSHOT]",
@ -803,9 +803,9 @@ Deno.test("SnapshotTest - createAssertSnapshot", async (t) => {
await assertSnapshot(t, err.message); await assertSnapshot(t, err.message);
}); });
await t.step("Composite", async (t) => { await t.step("composite", async (t) => {
const assertMonochromeSnapshotComposite = createAssertSnapshot<string>({ const assertMonochromeSnapshotComposite = createAssertSnapshot<string>({
name: "SnapshotTest - createAssertSnapshot - Composite - Custom Name", name: "createAssertSnapshot() - composite - custom Name",
}, assertMonochromeSnapshot); }, assertMonochromeSnapshot);
await assertMonochromeSnapshotComposite( await assertMonochromeSnapshotComposite(

View File

@ -16,11 +16,11 @@ function fromNow(): () => number {
return () => Date.now() - start; return () => Date.now() - start;
} }
Deno.test("Date unchanged if FakeTime is uninitialized", () => { Deno.test("FakeTime doesn't affect Date unchanged if uninitialized", () => {
assertStrictEquals(Date, _internals.Date); assertStrictEquals(Date, _internals.Date);
}); });
Deno.test("Date is fake if FakeTime is initialized", () => { Deno.test("FakeTime fakes Date", () => {
{ {
using _time = new FakeTime(9001); using _time = new FakeTime(9001);
assertNotEquals(Date, _internals.Date); assertNotEquals(Date, _internals.Date);
@ -28,7 +28,7 @@ Deno.test("Date is fake if FakeTime is initialized", () => {
assertStrictEquals(Date, _internals.Date); assertStrictEquals(Date, _internals.Date);
}); });
Deno.test("Fake Date parse and UTC behave the same", () => { Deno.test("FakeTime causes date parse and UTC behave the same", () => {
const expectedUTC = Date.UTC(96, 1, 2, 3, 4, 5); const expectedUTC = Date.UTC(96, 1, 2, 3, 4, 5);
const expectedParse = Date.parse("04 Dec 1995 00:12:00 GMT"); const expectedParse = Date.parse("04 Dec 1995 00:12:00 GMT");
@ -43,7 +43,7 @@ Deno.test("Fake Date parse and UTC behave the same", () => {
); );
}); });
Deno.test("Fake Date.now returns current fake time", () => { Deno.test("FakeTime causes Date.now() returns current fake time", () => {
const time: FakeTime = new FakeTime(9001); const time: FakeTime = new FakeTime(9001);
const now = spy(_internals.Date, "now"); const now = spy(_internals.Date, "now");
try { try {
@ -63,7 +63,7 @@ Deno.test("Fake Date.now returns current fake time", () => {
} }
}); });
Deno.test("Fake Date instance methods passthrough to real Date instance methods", () => { Deno.test("FakeTime causes Date instance methods passthrough to real Date instance methods", () => {
using _time = new FakeTime(); using _time = new FakeTime();
const now = new Date("2020-05-25T05:00:00.12345Z"); const now = new Date("2020-05-25T05:00:00.12345Z");
assertEquals(now.toISOString(), "2020-05-25T05:00:00.123Z"); assertEquals(now.toISOString(), "2020-05-25T05:00:00.123Z");
@ -98,12 +98,12 @@ Deno.test("Fake Date instance methods passthrough to real Date instance methods"
} }
}); });
Deno.test("timeout functions unchanged if FakeTime is uninitialized", () => { Deno.test("FakeTime timeout functions unchanged if FakeTime is uninitialized", () => {
assertStrictEquals(setTimeout, _internals.setTimeout); assertStrictEquals(setTimeout, _internals.setTimeout);
assertStrictEquals(clearTimeout, _internals.clearTimeout); assertStrictEquals(clearTimeout, _internals.clearTimeout);
}); });
Deno.test("timeout functions are fake if FakeTime is initialized", () => { Deno.test("FakeTime timeout functions are fake if FakeTime is initialized", () => {
{ {
using _time: FakeTime = new FakeTime(); using _time: FakeTime = new FakeTime();
assertNotEquals(setTimeout, _internals.setTimeout); assertNotEquals(setTimeout, _internals.setTimeout);
@ -170,12 +170,12 @@ Deno.test("FakeTime controls timeouts", () => {
assertEquals(cb.calls, expected); assertEquals(cb.calls, expected);
}); });
Deno.test("interval functions unchanged if FakeTime is uninitialized", () => { Deno.test("FakeTime interval functions unchanged if FakeTime is uninitialized", () => {
assertStrictEquals(setInterval, _internals.setInterval); assertStrictEquals(setInterval, _internals.setInterval);
assertStrictEquals(clearInterval, _internals.clearInterval); assertStrictEquals(clearInterval, _internals.clearInterval);
}); });
Deno.test("interval functions are fake if FakeTime is initialized", () => { Deno.test("FakeTime fakes interval functions", () => {
{ {
using _time: FakeTime = new FakeTime(); using _time: FakeTime = new FakeTime();
assertNotEquals(setInterval, _internals.setInterval); assertNotEquals(setInterval, _internals.setInterval);
@ -257,7 +257,7 @@ Deno.test("FakeTime calls timeout and interval callbacks in correct order", () =
assertEquals(intervalCb.calls, intervalExpected); assertEquals(intervalCb.calls, intervalExpected);
}); });
Deno.test("FakeTime restoreFor restores real time temporarily", async () => { Deno.test("FakeTime.restoreFor() restores real time temporarily", async () => {
using time: FakeTime = new FakeTime(); using time: FakeTime = new FakeTime();
const start: number = Date.now(); const start: number = Date.now();
@ -272,7 +272,7 @@ Deno.test("FakeTime restoreFor restores real time temporarily", async () => {
assert(_internals.Date.now() < start + 1000); assert(_internals.Date.now() < start + 1000);
}); });
Deno.test("FakeTime restoreFor restores real time and re-overridden atomically", async () => { Deno.test("FakeTime.restoreFor() restores real time and re-overridden atomically", async () => {
using _time: FakeTime = new FakeTime(); using _time: FakeTime = new FakeTime();
const fakeSetTimeout = setTimeout; const fakeSetTimeout = setTimeout;
const actualSetTimeouts: (typeof setTimeout)[] = []; const actualSetTimeouts: (typeof setTimeout)[] = [];
@ -296,7 +296,7 @@ Deno.test("FakeTime restoreFor restores real time and re-overridden atomically",
]); ]);
}); });
Deno.test("FakeTime restoreFor returns promise that resolved to result of callback", async () => { Deno.test("FakeTime.restoreFor() returns promise that resolved to result of callback", async () => {
using _time: FakeTime = new FakeTime(); using _time: FakeTime = new FakeTime();
const resultSync = await FakeTime.restoreFor(() => "a"); const resultSync = await FakeTime.restoreFor(() => "a");
@ -305,7 +305,7 @@ Deno.test("FakeTime restoreFor returns promise that resolved to result of callba
assertEquals(resultAsync, "b"); assertEquals(resultAsync, "b");
}); });
Deno.test("FakeTime restoreFor returns promise that rejected to error in callback", async () => { Deno.test("FakeTime.restoreFor() returns promise that rejected to error in callback", async () => {
using _time: FakeTime = new FakeTime(); using _time: FakeTime = new FakeTime();
await assertRejects( await assertRejects(
@ -326,7 +326,7 @@ Deno.test("FakeTime restoreFor returns promise that rejected to error in callbac
); );
}); });
Deno.test("FakeTime restoreFor returns promise that rejected to TimeError if FakeTime is uninitialized", async () => { Deno.test("FakeTime.restoreFor() returns promise that rejected to TimeError if FakeTime is uninitialized", async () => {
await assertRejects( await assertRejects(
() => FakeTime.restoreFor(() => {}), () => FakeTime.restoreFor(() => {}),
TimeError, TimeError,
@ -334,7 +334,7 @@ Deno.test("FakeTime restoreFor returns promise that rejected to TimeError if Fak
); );
}); });
Deno.test("delay uses real time", async () => { Deno.test("FakeTime.delay() uses real time", async () => {
using time: FakeTime = new FakeTime(); using time: FakeTime = new FakeTime();
const start: number = Date.now(); const start: number = Date.now();
@ -344,7 +344,7 @@ Deno.test("delay uses real time", async () => {
assertEquals(Date.now(), start); assertEquals(Date.now(), start);
}); });
Deno.test("delay runs all microtasks before resolving", async () => { Deno.test("FakeTime.delay() runs all microtasks before resolving", async () => {
using time: FakeTime = new FakeTime(); using time: FakeTime = new FakeTime();
const seq = []; const seq = [];
@ -356,7 +356,7 @@ Deno.test("delay runs all microtasks before resolving", async () => {
assertEquals(seq, [1, 2, 3, 4]); assertEquals(seq, [1, 2, 3, 4]);
}); });
Deno.test("delay with abort", async () => { Deno.test("FakeTime.delay() works with abort", async () => {
using time: FakeTime = new FakeTime(); using time: FakeTime = new FakeTime();
const seq = []; const seq = [];
@ -379,7 +379,7 @@ Deno.test("delay with abort", async () => {
assertEquals(seq, [1, 2, 3]); assertEquals(seq, [1, 2, 3]);
}); });
Deno.test("runMicrotasks runs all microtasks before resolving", async () => { Deno.test("FakeTime.runMicrotasks() runs all microtasks before resolving", async () => {
using time: FakeTime = new FakeTime(); using time: FakeTime = new FakeTime();
const start: number = Date.now(); const start: number = Date.now();
@ -393,7 +393,7 @@ Deno.test("runMicrotasks runs all microtasks before resolving", async () => {
assertEquals(Date.now(), start); assertEquals(Date.now(), start);
}); });
Deno.test("tickAsync runs all microtasks and runs timers if ticks past due", async () => { Deno.test("FakeTime.tickAsync() runs all microtasks and runs timers if ticks past due", async () => {
using time: FakeTime = new FakeTime(); using time: FakeTime = new FakeTime();
const start: number = Date.now(); const start: number = Date.now();
const cb = spy(fromNow()); const cb = spy(fromNow());
@ -419,7 +419,7 @@ Deno.test("tickAsync runs all microtasks and runs timers if ticks past due", asy
assertEquals(seq, [1, 2, 3, 4, 5, 6, 7]); assertEquals(seq, [1, 2, 3, 4, 5, 6, 7]);
}); });
Deno.test("next runs next timer without running microtasks", async () => { Deno.test("FakeTime.next() runs next timer without running microtasks", async () => {
using time: FakeTime = new FakeTime(); using time: FakeTime = new FakeTime();
const start: number = Date.now(); const start: number = Date.now();
const cb = spy(fromNow()); const cb = spy(fromNow());
@ -489,7 +489,7 @@ Deno.test("next runs next timer without running microtasks", async () => {
assertEquals(seq, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]); assertEquals(seq, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
}); });
Deno.test("nextAsync runs all microtasks and next timer", async () => { Deno.test("FakeTime.nextAsync() runs all microtasks and next timer", async () => {
using time: FakeTime = new FakeTime(); using time: FakeTime = new FakeTime();
const start: number = Date.now(); const start: number = Date.now();
const cb = spy(fromNow()); const cb = spy(fromNow());
@ -556,7 +556,7 @@ Deno.test("nextAsync runs all microtasks and next timer", async () => {
assertEquals(seq, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]); assertEquals(seq, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
}); });
Deno.test("runAll runs all timers without running microtasks", async () => { Deno.test("FakeTime.runAll() runs all timers without running microtasks", async () => {
using time: FakeTime = new FakeTime(); using time: FakeTime = new FakeTime();
const start: number = Date.now(); const start: number = Date.now();
const cb = spy(fromNow()); const cb = spy(fromNow());
@ -589,7 +589,7 @@ Deno.test("runAll runs all timers without running microtasks", async () => {
assertEquals(seq, [1, 2, 3, 4, 5, 6, 7, 8]); assertEquals(seq, [1, 2, 3, 4, 5, 6, 7, 8]);
}); });
Deno.test("runAllAsync runs all microtasks and timers", async () => { Deno.test("FakeTime.runAllAsync() runs all microtasks and timers", async () => {
using time: FakeTime = new FakeTime(); using time: FakeTime = new FakeTime();
const start: number = Date.now(); const start: number = Date.now();
const cb = spy(fromNow()); const cb = spy(fromNow());