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

Commit 874b56b

Browse files
committed
Upgrade deno to 1.11.0 and add assertion functions
1 parent 617fdc2 commit 874b56b

28 files changed

+1866
-455
lines changed

.github/codecov.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
comment: false
2+
codecov:
3+
require_ci_to_pass: true
4+
coverage:
5+
status:
6+
project:
7+
default:
8+
informational: true
9+
ignore:
10+
- examples

.github/workflows/ci.yml

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,56 +2,54 @@ name: CI
22
on: [push, pull_request]
33
jobs:
44
build:
5-
name: ${{ matrix.config.kind }} ${{ matrix.config.os }}
6-
runs-on: ${{ matrix.config.os }}
5+
name: test deno ${{ matrix.deno }} ${{ matrix.os }}
6+
runs-on: ${{ matrix.os }}
77
timeout-minutes: 5
88
strategy:
99
matrix:
10-
config:
11-
- os: macOS-latest
12-
kind: test
13-
- os: windows-latest
14-
kind: test
15-
- os: ubuntu-latest
16-
kind: test
17-
- os: ubuntu-latest
18-
kind: lint
10+
os: [ubuntu-latest, windows-latest, macOS-latest]
11+
deno: [v1.x, canary]
12+
fail-fast: true
1913
steps:
2014
- name: Clone repository
2115
uses: actions/checkout@v2
22-
- name: Install deno
23-
uses: denolib/setup-deno@master
16+
- name: Setup deno
17+
uses: denoland/setup-deno@main
2418
with:
25-
deno-version: 1.9.0
19+
deno-version: ${{ matrix.deno }}
2620
- name: Check formatting
27-
if: matrix.config.kind == 'lint'
28-
run: |
29-
deno fmt --check
30-
deno lint --unstable
31-
- name: Test
32-
if: matrix.config.kind == 'test'
33-
run: |
34-
deno test
35-
- name: Test unstable
36-
if: matrix.config.kind == 'test'
37-
run: |
38-
deno test --coverage=cov_profile --unstable
39-
- name: Test coverage
40-
if: matrix.config.kind == 'test'
41-
run: |
42-
deno coverage --unstable cov_profile
21+
if: matrix.os == 'ubuntu-latest'
22+
run: deno fmt --check
23+
- name: Check linting
24+
if: matrix.os == 'ubuntu-latest'
25+
run: deno lint
26+
- name: Run tests
27+
run: deno test --coverage=cov
28+
- name: Run tests unstable
29+
run: deno test --unstable
30+
- name: Generate lcov
31+
if: |
32+
matrix.os == 'ubuntu-latest' &&
33+
matrix.deno == 'v1.x'
34+
run: deno coverage --lcov cov > cov.lcov
35+
- name: Upload coverage
36+
if: |
37+
matrix.os == 'ubuntu-latest' &&
38+
matrix.deno == 'v1.x'
39+
uses: codecov/codecov-action@v1
40+
with:
41+
files: cov.lcov
4342
- name: Release info
4443
if: |
45-
matrix.config.kind == 'test' &&
4644
github.repository == 'udibo/mock' &&
45+
matrix.os == 'ubuntu-latest' &&
46+
matrix.deno == 'v1.x' &&
4747
startsWith(github.ref, 'refs/tags/')
4848
shell: bash
4949
run: |
5050
echo "RELEASE_VERSION=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV
5151
- name: Bundle
52-
if: |
53-
env.RELEASE_VERSION != '' &&
54-
startsWith(matrix.config.os, 'ubuntu')
52+
if: env.RELEASE_VERSION != ''
5553
run: |
5654
mkdir -p target/release
5755
deno bundle mod.ts target/release/mock_${RELEASE_VERSION}.js

.vscode/settings.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
{
22
"deno.enable": true,
3-
"deno.unstable": true,
3+
"deno.unstable": false,
44
"deno.lint": true,
55
"[typescript]": {
66
"editor.defaultFormatter": "denoland.vscode-deno"
7-
},
8-
"deno.import_intellisense_origins": {
9-
"https://deno.land": true
107
}
118
}

README.md

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

3-
[![version](https://img.shields.io/badge/release-v0.9.5-success)](https://github.com/udibo/mock/tree/v0.9.5)
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.9.0-success?logo=deno)](https://github.com/denoland/deno/tree/v1.9.0)
3+
[![release](https://img.shields.io/badge/release-v0.10.0-success)](https://github.com/udibo/mock/releases/tag/v0.10.0)
4+
[![deno doc](https://doc.deno.land/badge.svg)](https://doc.deno.land/https/deno.land/x/[email protected]/mod.ts)
65
[![CI](https://github.com/udibo/mock/workflows/CI/badge.svg)](https://github.com/udibo/mock/actions?query=workflow%3ACI)
6+
[![codecov](https://codecov.io/gh/udibo/mock/branch/master/graph/badge.svg?token=TXORMSEHM7)](https://codecov.io/gh/udibo/mock)
77
[![license](https://img.shields.io/github/license/udibo/mock)](https://github.com/udibo/mock/blob/master/LICENSE)
88

9-
This module provides utilities to help mock behavior and spy on function calls
10-
for tests.
9+
Utilities to help mock behavior, spy on function calls, stub methods and fake
10+
time for tests.
1111

1212
## Features
1313

@@ -30,22 +30,22 @@ imported directly from GitHub using raw content URLs.
3030

3131
```ts
3232
// Import from Deno's third party module registry
33-
import { spy, Spy } from "https://deno.land/x/mock@v0.9.5/mod.ts";
33+
import { spy, Spy } from "https://deno.land/x/mock@v0.10.0/mod.ts";
3434
// Import from GitHub
35-
import { spy, Spy } "https://raw.githubusercontent.com/udibo/mock/v0.9.5/mod.ts";
35+
import { spy, Spy } "https://raw.githubusercontent.com/udibo/mock/v0.10.0/mod.ts";
3636
```
3737
3838
If you do not need all of the sub-modules, you can choose to just import the
3939
sub-modules you need.
4040
4141
```ts
4242
// Import from Deno's third party module registry
43-
import { Spy, spy } from "https://deno.land/x/mock@v0.9.5/spy.ts";
43+
import { Spy, spy } from "https://deno.land/x/mock@v0.10.0/spy.ts";
4444
// Import from GitHub
4545
import {
4646
Spy,
4747
spy,
48-
} from "https://raw.githubusercontent.com/udibo/mock/v0.9.5/spy.ts";
48+
} from "https://raw.githubusercontent.com/udibo/mock/v0.10.0/spy.ts";
4949
```
5050

5151
#### Sub-modules
@@ -69,15 +69,15 @@ If a Node.js package has the type "module" specified in its package.json file,
6969
the JavaScript bundle can be imported as a `.js` file.
7070

7171
```js
72-
import { Spy, spy } from "./mock_v0.9.5.js";
72+
import { Spy, spy } from "./mock_v0.10.0.js";
7373
```
7474

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

7979
```js
80-
import { Spy, spy } from "./mock_v0.9.5.mjs";
80+
import { Spy, spy } from "./mock_v0.10.0.mjs";
8181
```
8282

8383
See [Node.js Documentation](https://nodejs.org/api/esm.html) for more
@@ -96,15 +96,15 @@ modules must have the type attribute set to "module".
9696

9797
```js
9898
// main.js
99-
import { Spy, spy } from "./mock_v0.9.5.js";
99+
import { Spy, spy } from "./mock_v0.10.0.js";
100100
```
101101

102102
You can also embed a module script directly into an HTML file by placing the
103103
JavaScript code within the body of the script tag.
104104

105105
```html
106106
<script type="module">
107-
import { spy, Spy } from "./mock_v0.9.5.js";
107+
import { spy, Spy } from "./mock_v0.10.0.js";
108108
</script>
109109
```
110110

@@ -120,7 +120,7 @@ a try block then restore the function in a finally block to ensure the original
120120
instance method is restored before continuing to other tests. The same applies
121121
when using fake time.
122122

123-
See [deno docs](https://doc.deno.land/https/deno.land/x/mock@v0.9.5/mod.ts) for
123+
See [deno docs](https://doc.deno.land/https/deno.land/x/mock@v0.10.0/mod.ts) for
124124
more information.
125125

126126
### Spy
@@ -135,8 +135,9 @@ anything, you can create an empty spy. An empty spy will just return undefined
135135
for any calls made to it.
136136

137137
```ts
138-
import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts";
139-
import { Spy, spy } from "https://deno.land/x/[email protected]/spy.ts";
138+
import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts";
139+
import { assertSpyCall } from "https://deno.land/x/[email protected]/asserts.ts";
140+
import { Spy, spy } from "https://deno.land/x/[email protected]/spy.ts";
140141

141142
function add(
142143
a: number,
@@ -152,20 +153,18 @@ Deno.test("calls fake callback", () => {
152153
const callback: Spy<void> = spy();
153154

154155
assertEquals(add(2, 3, callback), undefined);
156+
assertSpyCall(callback, 1, { args: [undefined, 5] });
155157
assertEquals(add(5, 4, callback), undefined);
156-
assertEquals(callback.calls, [
157-
{ args: [undefined, 5] },
158-
{ args: [undefined, 9] },
159-
]);
158+
assertSpyCall(callback, 1, { args: [undefined, 9] });
160159
});
161160
```
162161

163162
If you have a function that takes a callback that needs to still behave
164163
normally, you can wrap it with a spy.
165164

166165
```ts
167-
import { assertEquals } from "https://deno.land/std@0.93.0/testing/asserts.ts";
168-
import { Spy, spy } from "https://deno.land/x/mock@v0.9.5/spy.ts";
166+
import { assertEquals } from "https://deno.land/std@0.98.0/testing/asserts.ts";
167+
import { Spy, spy } from "https://deno.land/x/mock@v0.10.0/spy.ts";
169168

170169
function filter<T>(values: T[], callback: (value: T) => boolean): any[] {
171170
return values.filter(callback);
@@ -196,8 +195,8 @@ method. If it is not restored and you attempt to wrap it again, it will throw a
196195
spy error saying "already spying on function".
197196

198197
```ts
199-
import { assertEquals } from "https://deno.land/std@0.93.0/testing/asserts.ts";
200-
import { Spy, spy } from "https://deno.land/x/mock@v0.9.5/spy.ts";
198+
import { assertEquals } from "https://deno.land/std@0.98.0/testing/asserts.ts";
199+
import { Spy, spy } from "https://deno.land/x/mock@v0.10.0/spy.ts";
201200

202201
class Database {
203202
private queries: any;
@@ -287,8 +286,8 @@ return values after initialization by replacing or adding to the `stub.returns`
287286
queue. When the returns queue is empty, it will return undefined.
288287

289288
```ts
290-
import { assertEquals } from "https://deno.land/std@0.93.0/testing/asserts.ts";
291-
import { Stub, stub } from "https://deno.land/x/mock@v0.9.5/stub.ts";
289+
import { assertEquals } from "https://deno.land/std@0.98.0/testing/asserts.ts";
290+
import { Stub, stub } from "https://deno.land/x/mock@v0.10.0/stub.ts";
292291

293292
class Cat {
294293
action(name: string): any {
@@ -324,8 +323,8 @@ them returned. You can add more return values after initialization by replacing
324323
or adding to the `stub.returns` queue.
325324

326325
```ts
327-
import { assertEquals } from "https://deno.land/std@0.93.0/testing/asserts.ts";
328-
import { Stub, stub } from "https://deno.land/x/mock@v0.9.5/stub.ts";
326+
import { assertEquals } from "https://deno.land/std@0.98.0/testing/asserts.ts";
327+
import { Stub, stub } from "https://deno.land/x/mock@v0.10.0/stub.ts";
329328

330329
class Database {
331330
query(query: string, params: any[]): any[][] {
@@ -400,8 +399,8 @@ initialization by replacing or adding to the `stub.returns` queue. When the
400399
returns queue is empty, it will call the replacement function.
401400

402401
```ts
403-
import { assertEquals } from "https://deno.land/std@0.93.0/testing/asserts.ts";
404-
import { Stub, stub } from "https://deno.land/x/mock@v0.9.5/stub.ts";
402+
import { assertEquals } from "https://deno.land/std@0.98.0/testing/asserts.ts";
403+
import { Stub, stub } from "https://deno.land/x/mock@v0.10.0/stub.ts";
405404

406405
class Database {
407406
query(query: string, params: any[]): any[][] {
@@ -476,9 +475,9 @@ Overrides the real Date object and timer functions with fake ones that can be
476475
controlled through the fake time instance.
477476

478477
```ts
479-
import { assertEquals } from "https://deno.land/std@0.93.0/testing/asserts.ts";
480-
import { Spy, spy } from "https://deno.land/x/mock@v0.9.5/spy.ts";
481-
import { FakeTime } from "https://deno.land/x/mock@v0.9.5/time.ts";
478+
import { assertEquals } from "https://deno.land/std@0.98.0/testing/asserts.ts";
479+
import { Spy, spy } from "https://deno.land/x/mock@v0.10.0/spy.ts";
480+
import { FakeTime } from "https://deno.land/x/mock@v0.10.0/time.ts";
482481

483482
function secondInterval(cb: () => void): void {
484483
setInterval(cb, 1000);

0 commit comments

Comments
 (0)