Skip to content
This repository was archived by the owner on Apr 18, 2022. It is now read-only.

Commit 476fd7a

Browse files
committed
Upgrade Deno to 1.3.2 and lint
1 parent dad00bb commit 476fd7a

File tree

9 files changed

+66
-51
lines changed

9 files changed

+66
-51
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
- name: Install deno
2323
uses: denolib/setup-deno@master
2424
with:
25-
deno-version: 1.3.0
25+
deno-version: 1.3.2
2626
- name: Check formatting
2727
if: matrix.config.kind == 'lint'
2828
run: |

.vscode/launch.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22
"version": "0.2.0",
33
"configurations": [
44
{
5-
"name": "Launch via deno run",
6-
"type": "node",
5+
"name": "deno run",
6+
"type": "pwa-node",
77
"request": "launch",
88
"cwd": "${workspaceFolder}",
99
"runtimeExecutable": "deno",
1010
"runtimeArgs": ["run", "--inspect-brk", "${file}"],
11-
"port": 9229
11+
"attachSimplePort": 9229
1212
},
1313
{
14-
"name": "Launch via deno test",
15-
"type": "node",
14+
"name": "deno test",
15+
"type": "pwa-node",
1616
"request": "launch",
1717
"cwd": "${workspaceFolder}",
1818
"runtimeExecutable": "deno",
1919
"runtimeArgs": ["test", "--inspect-brk", "${file}"],
20-
"port": 9229
20+
"attachSimplePort": 9229
2121
}
2222
]
2323
}

README.md

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Mock
22

3-
[![version](https://img.shields.io/badge/release-v0.4.0-success)](https://github.com/udibo/mock/tree/v0.4.0)
3+
[![version](https://img.shields.io/badge/release-v0.5.0-success)](https://github.com/udibo/mock/tree/v0.5.0)
4+
[![deno doc](https://img.shields.io/badge/deno-doc-success?logo=deno)](https://doc.deno.land/https/deno.land/x/[email protected]/mod.ts)
5+
[![deno version](https://img.shields.io/badge/deno-v1.3.2-success?logo=deno)](https://github.com/denoland/deno/tree/v1.3.2)
46
[![CI](https://github.com/udibo/mock/workflows/CI/badge.svg)](https://github.com/udibo/mock/actions?query=workflow%3ACI)
5-
[![deno version](https://img.shields.io/badge/deno-v1.3.0-success)](https://github.com/denoland/deno/tree/v1.3.0)
6-
[![deno doc](https://doc.deno.land/badge.svg)](https://doc.deno.land/https/deno.land/x/[email protected]/mod.ts)
77
[![license](https://img.shields.io/github/license/udibo/mock)](https://github.com/udibo/mock/blob/master/LICENSE)
88

99
This module provides utilities to help mock behavior and spy on function calls for tests.
@@ -26,18 +26,18 @@ but can also be imported directly from GitHub using raw content URLs.
2626

2727
```ts
2828
// Import from Deno's third party module registry
29-
import { spy, Spy } from "https://deno.land/x/mock@v0.4.0/mod.ts";
29+
import { spy, Spy } from "https://deno.land/x/mock@v0.5.0/mod.ts";
3030
// Import from GitHub
31-
import { spy, Spy } "https://raw.githubusercontent.com/udibo/mock/v0.4.0/mod.ts";
31+
import { spy, Spy } "https://raw.githubusercontent.com/udibo/mock/v0.5.0/mod.ts";
3232
```
3333
3434
If you do not need all of the sub-modules, you can choose to just import the sub-modules you need.
3535
3636
```ts
3737
// Import from Deno's third party module registry
38-
import { spy, Spy } from "https://deno.land/x/mock@v0.4.0/spy.ts";
38+
import { spy, Spy } from "https://deno.land/x/mock@v0.5.0/spy.ts";
3939
// Import from GitHub
40-
import { spy, Spy } from "https://raw.githubusercontent.com/udibo/mock/v0.4.0/spy.ts";
40+
import { spy, Spy } from "https://raw.githubusercontent.com/udibo/mock/v0.5.0/spy.ts";
4141
```
4242

4343
#### Sub-modules
@@ -57,14 +57,14 @@ Node.js fully supports ES Modules.
5757
If a Node.js package has the type "module" specified in its package.json file, the JavaScript bundle can be imported as a `.js` file.
5858

5959
```js
60-
import { spy, Spy } from "./mock_v0.4.0.js";
60+
import { spy, Spy } from "./mock_v0.5.0.js";
6161
```
6262

6363
The default type for Node.js packages is "commonjs".
6464
To import the bundle into a commonjs package, the file extension of the JavaScript bundle must be changed from `.js` to `.mjs`.
6565

6666
```js
67-
import { spy, Spy } from "./mock_v0.4.0.mjs";
67+
import { spy, Spy } from "./mock_v0.5.0.mjs";
6868
```
6969

7070
See [Node.js Documentation](https://nodejs.org/api/esm.html) for more information.
@@ -82,15 +82,15 @@ Script tags for ES modules must have the type attribute set to "module".
8282

8383
```js
8484
// main.js
85-
import { spy, Spy } from "./mock_v0.4.0.js";
85+
import { spy, Spy } from "./mock_v0.5.0.js";
8686
```
8787

8888
You can also embed a module script directly into an HTML file by placing the JavaScript code
8989
within the body of the script tag.
9090

9191
```html
9292
<script type="module">
93-
import { spy, Spy } from "./mock_v0.4.0.js";
93+
import { spy, Spy } from "./mock_v0.5.0.js";
9494
</script>
9595
```
9696

@@ -100,7 +100,7 @@ See [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/
100100

101101
Below are some examples of how to use Spys, Stubs, and FakeTime in tests. When spying/stubing instance methods, you should wrap the calls and expectations with a try block then restore the function in a finally block to ensure the original instance method is restored before continuing to other tests. The same applies when using fake time.
102102

103-
See [deno docs](https://doc.deno.land/https/deno.land/x/mock@v0.4.0/mod.ts) for more information.
103+
See [deno docs](https://doc.deno.land/https/deno.land/x/mock@v0.5.0/mod.ts) for more information.
104104

105105
### Spy
106106

@@ -109,8 +109,8 @@ When spying on a function or instance method, all arguments and return values ar
109109
If you have a function that takes a callback but you don't need it to do anything, you can create an empty spy. An empty spy will just return undefined for any calls made to it.
110110

111111
```ts
112-
import { assertEquals } from "https://deno.land/std@0.65.0/testing/asserts.ts";
113-
import { spy, Spy } from "https://deno.land/x/mock@v0.4.0/spy.ts";
112+
import { assertEquals } from "https://deno.land/std@0.67.0/testing/asserts.ts";
113+
import { spy, Spy } from "https://deno.land/x/mock@v0.5.0/spy.ts";
114114

115115
function add(
116116
a: number,
@@ -137,8 +137,8 @@ Deno.test("calls fake callback", () => {
137137
If you have a function that takes a callback that needs to still behave normally, you can wrap it with a spy.
138138

139139
```ts
140-
import { assertEquals } from "https://deno.land/std@0.65.0/testing/asserts.ts";
141-
import { spy, Spy } from "https://deno.land/x/mock@v0.4.0/spy.ts";
140+
import { assertEquals } from "https://deno.land/std@0.67.0/testing/asserts.ts";
141+
import { spy, Spy } from "https://deno.land/x/mock@v0.5.0/spy.ts";
142142

143143
function filter<T>(values: T[], callback: (value: T) => boolean): any[] {
144144
return values.filter(callback);
@@ -165,8 +165,8 @@ Deno.test("calls real callback", () => {
165165
If you have an instance method that needs to still behave normally, you can wrap it with a spy. When you are done spying on a method, you need to call the restore function on the spy object to remove the wrapper from the instance method. If it is not restored and you attempt to wrap it again, it will throw a spy error saying "already spying on function".
166166

167167
```ts
168-
import { assertEquals } from "https://deno.land/std@0.65.0/testing/asserts.ts";
169-
import { spy, Spy } from "https://deno.land/x/mock@v0.4.0/spy.ts";
168+
import { assertEquals } from "https://deno.land/std@0.67.0/testing/asserts.ts";
169+
import { spy, Spy } from "https://deno.land/x/mock@v0.5.0/spy.ts";
170170

171171
class Database {
172172
private queries: any;
@@ -249,8 +249,8 @@ When stubbing an instance method, all arguments and return values are recorded b
249249
If you have an instance method but you don't need it to do or return anything, you can create an empty stub. An empty stub will just return undefined for any calls made to it. If you need it to return specific values instead, you can add return values after initialization by replacing or adding to the `stub.returns` queue. When the returns queue is empty, it will return undefined.
250250

251251
```ts
252-
import { assertEquals } from "https://deno.land/std@0.65.0/testing/asserts.ts";
253-
import { stub, Stub } from "https://deno.land/x/mock@v0.4.0/stub.ts";
252+
import { assertEquals } from "https://deno.land/std@0.67.0/testing/asserts.ts";
253+
import { stub, Stub } from "https://deno.land/x/mock@v0.5.0/stub.ts";
254254

255255
class Cat {
256256
action(name: string): any {
@@ -283,8 +283,8 @@ Deno.test("doAction", () => {
283283
If you have an instance method but need it to return specific values for each call, you can create a stub with an array of values in the order that you want them returned. You can add more return values after initialization by replacing or adding to the `stub.returns` queue.
284284

285285
```ts
286-
import { assertEquals } from "https://deno.land/std@0.65.0/testing/asserts.ts";
287-
import { stub, Stub } from "https://deno.land/x/mock@v0.4.0/stub.ts";
286+
import { assertEquals } from "https://deno.land/std@0.67.0/testing/asserts.ts";
287+
import { stub, Stub } from "https://deno.land/x/mock@v0.5.0/stub.ts";
288288

289289
class Database {
290290
query(query: string, params: any[]): any[][] {
@@ -355,8 +355,8 @@ Deno.test("getUsers", () => {
355355
If you have an instance method but need it to call a replacement function instead of the original, you can create a stub with a replacement function. If you need it to return specific values instead, you can add return values after initialization by replacing or adding to the `stub.returns` queue. When the returns queue is empty, it will call the replacement function.
356356

357357
```ts
358-
import { assertEquals } from "https://deno.land/std@0.65.0/testing/asserts.ts";
359-
import { stub, Stub } from "https://deno.land/x/mock@v0.4.0/stub.ts";
358+
import { assertEquals } from "https://deno.land/std@0.67.0/testing/asserts.ts";
359+
import { stub, Stub } from "https://deno.land/x/mock@v0.5.0/stub.ts";
360360

361361
class Database {
362362
query(query: string, params: any[]): any[][] {
@@ -431,9 +431,9 @@ Overrides the real Date object and timer functions with fake ones that can be
431431
controlled through the fake time instance.
432432

433433
```ts
434-
import { assertEquals } from "https://deno.land/std@0.65.0/testing/asserts.ts";
435-
import { spy, Spy } from "https://deno.land/x/mock@v0.4.0/spy.ts";
436-
import { FakeTime } from "https://deno.land/x/mock@v0.4.0/time.ts";
434+
import { assertEquals } from "https://deno.land/std@0.67.0/testing/asserts.ts";
435+
import { spy, Spy } from "https://deno.land/x/mock@v0.5.0/spy.ts";
436+
import { FakeTime } from "https://deno.land/x/mock@v0.5.0/time.ts";
437437

438438
function secondInterval(cb: () => void): void {
439439
setInterval(cb, 1000);

asserts.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ interface PassthroughOptionsInstance<T, U> {
2727
returned?: any;
2828
}
2929
interface PassthroughOptionsFunc<T, U> {
30-
func: Function;
30+
// deno-lint-ignore no-explicit-any
31+
func: (...args: any[]) => any;
3132
target: PassthroughTarget<T, U>;
3233
// deno-lint-ignore no-explicit-any
3334
args?: any[];
@@ -64,11 +65,13 @@ export function assertPassthrough<T, U>(
6465
throw new Error("target instance or passthrough must have method");
6566
}
6667

67-
let func: T[keyof T] | Function;
68+
// deno-lint-ignore no-explicit-any
69+
let func: ((...args: any[]) => any);
6870
if ("instance" in options) {
6971
const instance: T = options.instance;
7072
const method: keyof T = options.method as keyof T;
71-
func = instance[method];
73+
// deno-lint-ignore no-explicit-any
74+
func = instance[method] as unknown as ((...args: any[]) => any);
7275
} else {
7376
func = options.func;
7477
}

deps/std/async/delay.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export { delay } from "https://deno.land/std@0.65.0/async/delay.ts";
1+
export { delay } from "https://deno.land/std@0.67.0/async/delay.ts";

deps/std/testing/asserts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ export {
66
assertThrows,
77
assertThrowsAsync,
88
AssertionError,
9-
} from "https://deno.land/std@0.65.0/testing/asserts.ts";
9+
} from "https://deno.land/std@0.67.0/testing/asserts.ts";

deps/udibo/mixins/apply.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export {
22
applyMixins,
33
applyInstanceMixins,
4-
} from "https://raw.githubusercontent.com/udibo/mixins/v0.4.0/apply.ts";
4+
} from "https://deno.land/x/mixins@v0.5.0/apply.ts";

spy.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ function isSpy<T>(func: any): func is Spy<T> {
3434

3535
export class SpyMixin<T> {
3636
calls: SpyCall[];
37-
func?: Function;
37+
// deno-lint-ignore no-explicit-any
38+
func?: (...args: any[]) => any;
3839
obj?: T;
3940
method?: keyof T;
4041
methodDescriptor?: PropertyDescriptor;
@@ -80,10 +81,12 @@ export interface Spy<T> {
8081
type AnySpy<T> = Spy<T> | Spy<void>;
8182
type AnySpyInternal<T> = SpyMixin<T> | SpyMixin<void>;
8283
function spy(): Spy<void>;
83-
function spy(func: Function): Spy<void>;
84+
// deno-lint-ignore no-explicit-any
85+
function spy(func: (...args: any[]) => any): Spy<void>;
8486
function spy<T>(obj: T, method: string | number | symbol): Spy<T>;
8587
function spy<T>(
86-
objOrFunc?: T | Function,
88+
// deno-lint-ignore no-explicit-any
89+
objOrFunc?: T | ((...args: any[]) => any),
8790
method?: string | number | symbol,
8891
): AnySpy<T> {
8992
const calls: SpyCall[] = [];
@@ -100,7 +103,8 @@ function spy<T>(
100103
if (typeof spyInternal.func === "function") {
101104
returned = spyInternal.func.apply(this, Array.from(arguments));
102105
} else {
103-
const func: Function = spyInternal.get?.call(undefined);
106+
// deno-lint-ignore no-explicit-any
107+
const func: (...args: any[]) => any = spyInternal.get?.call(undefined);
104108
if (typeof func === "function") {
105109
func.apply(this, Array.from(arguments));
106110
} else {
@@ -147,7 +151,8 @@ function spy<T>(
147151
if (isSpy(func)) {
148152
console.error("already spying on function");
149153
}
150-
spyInternal.func = func;
154+
// deno-lint-ignore no-explicit-any
155+
spyInternal.func = func as unknown as (...args: any[]) => any;
151156
value = result;
152157
} else {
153158
value = func;
@@ -173,7 +178,8 @@ function spy<T>(
173178
},
174179
});
175180
} else if (typeof objOrFunc === "function") {
176-
spyInternal.func = objOrFunc;
181+
// deno-lint-ignore no-explicit-any
182+
spyInternal.func = objOrFunc as (...args: any[]) => any;
177183
} else {
178184
spyInternal.func = () => undefined;
179185
}

stub.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,34 @@ function stub<T>(
2020
function stub<T>(
2121
instance: T,
2222
method: string | number | symbol,
23-
func: Function,
23+
// deno-lint-ignore no-explicit-any
24+
func: (...args: any[]) => any,
2425
): Stub<T>;
2526
function stub<T>(
2627
instance: T,
2728
method: string | number | symbol,
2829
// deno-lint-ignore no-explicit-any
29-
arrOrFunc?: Function | any[],
30+
arrOrFunc?: ((...args: any[]) => any) | any[],
3031
): Stub<T> {
3132
const stub: Stub<T> = spy(instance, method) as Stub<T>;
3233
const stubInternal: SpyMixin<T> = stub as unknown as SpyMixin<T>;
3334
stub.returns = Array.isArray(arrOrFunc) ? arrOrFunc : [];
34-
const func: Function = typeof arrOrFunc === "function"
35+
// deno-lint-ignore no-explicit-any
36+
const func: (...args: any) => any = typeof arrOrFunc === "function"
3537
? function (this: T) {
36-
return arrOrFunc.apply(this, arguments);
38+
// deno-lint-ignore no-explicit-any
39+
return arrOrFunc.apply(this, arguments as unknown as any[]);
3740
}
3841
: typeof arrOrFunc === "undefined"
3942
? () => undefined
4043
: () => {
4144
throw new SpyError("no return for call");
4245
};
4346
stubInternal.func = function () {
44-
if (stub.returns.length === 0) return func.apply(this, arguments);
47+
if (stub.returns.length === 0) {
48+
// deno-lint-ignore no-explicit-any
49+
return func.apply(this, arguments as unknown as any[]);
50+
}
4551
return stub.returns.shift();
4652
};
4753
return stub;

0 commit comments

Comments
 (0)