Skip to content

Commit 08a1f16

Browse files
authored
build: refactor to use deno (#30)
* chore: move test/index.js to mod_test.ts * chore: move test/typings.ts to typings_test.ts * test: format typings_test.ts with deno * test: refactor mod_test.ts to use Deno test * fix(AssertionError): make stack argument optional * build: use deno in build scripts * test: drop test index.html * build: add .tool-versions * build: add coverage folder to gitignore * build: add index.js to gitignore * style: deno fmt * build: drop dist files from package.json * style: deno fmt md files * style: deno fmt package* * build: move dist/mod.d.ts to index.d.ts * refactor: manually write index.d.ts for now Refs: denoland/deno#3385 * build: fix npm files * test: temporarily pass the typings tests * build: add deno ci * build: use denoland/setup-deno * style: deno fmt * build: remove tsconfig Not needed for Deno * build: remove broken coverage assertions * build: remove node build * style: fix all lint errors * fix(AssertionError): captureStackTrace inside consturctor * build: use deno lint * style: deno fmt * style: NAUGHTY DENO
1 parent 6a0cf50 commit 08a1f16

16 files changed

+345
-436
lines changed

.github/workflows/nodejs.yml

Lines changed: 0 additions & 44 deletions
This file was deleted.

.github/workflows/test.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Test Deno Module
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
deno-version: [1.15.2, canary]
15+
16+
steps:
17+
- name: Git sources
18+
uses: actions/checkout@v2
19+
20+
- name: Use Deno Version ${{ matrix.deno-version }}
21+
uses: denoland/[email protected]
22+
with:
23+
deno-version: ${{ matrix.deno-version }}
24+
25+
- name: Deno Check Fmt
26+
run: deno fmt --check
27+
28+
- name: Deno Lint
29+
run: deno lint
30+
31+
- name: Build Deno Module
32+
run: deno bundle --reload mod.ts > index.js
33+
34+
- name: Test Deno Module
35+
run: deno test --coverage=coverage
36+
37+
# TODO: coverage broken see https://github.com/denoland/deno/issues/11875
38+
# - name: Generate lcov
39+
# run: deno coverage coverage --lcov > coverage/lcov.info
40+
41+
# - name: Assert coverage is good
42+
# uses: VeryGoodOpenSource/[email protected]

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@ npm-debug.log
1717

1818
coverage.html
1919
dist
20+
coverage
21+
index.js

.tool-versions

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
deno 1.15.2

History.md

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
1-
1.1.0 / 2018-01-02
2-
==================
1+
# 1.1.0 / 2018-01-02
32

4-
* Add type definitions ([#11](https://github.com/chaijs/assertion-error/pull/11))
3+
- Add type definitions
4+
([#11](https://github.com/chaijs/assertion-error/pull/11))
55

6-
1.0.1 / 2015-03-04
7-
==================
6+
# 1.0.1 / 2015-03-04
87

9-
* Merge pull request #2 from simonzack/master
10-
* fixes `.stack` on firefox
8+
- Merge pull request #2 from simonzack/master
9+
- fixes `.stack` on firefox
1110

12-
1.0.0 / 2013-06-08
13-
==================
11+
# 1.0.0 / 2013-06-08
1412

15-
* readme: change travis and component urls
16-
* refactor: [*] prepare for move to chaijs gh org
13+
- readme: change travis and component urls
14+
- refactor: [*] prepare for move to chaijs gh org
1715

18-
0.1.0 / 2013-04-07
19-
==================
16+
# 0.1.0 / 2013-04-07
2017

21-
* test: use vanilla test runner/assert
22-
* pgk: remove unused deps
23-
* lib: implement
24-
* "Initial commit"
18+
- test: use vanilla test runner/assert
19+
- pgk: remove unused deps
20+
- lib: implement
21+
- "Initial commit"

README.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,15 @@ Both `AssertionError` and `AssertionResult` implement the `Result` interface:
3535

3636
```typescript
3737
interface Result {
38-
name: 'AssertionError' | 'AssertionResult'
39-
ok: boolean
40-
toJSON(...args: unknown[]): Record<string, unknown>
38+
name: "AssertionError" | "AssertionResult";
39+
ok: boolean;
40+
toJSON(...args: unknown[]): Record<string, unknown>;
4141
}
4242
```
4343

4444
So if a function returns `AssertionResult | AssertionError` it is easy to check
45-
_which_ one is returned by checking either `.name` or `.ok`, or check `instanceof Error`.
45+
_which_ one is returned by checking either `.name` or `.ok`, or check
46+
`instanceof Error`.
4647

4748
## Installation
4849

@@ -56,8 +57,12 @@ $ npm install --save assertion-error
5657

5758
### Deno
5859

59-
`assertion_error` is available on [Deno.land](https://deno.land/x/assertion_error)
60+
`assertion_error` is available on
61+
[Deno.land](https://deno.land/x/assertion_error)
6062

6163
```typescript
62-
import {AssertionError, AssertionResult} from 'https://deno.land/x/[email protected]/mod.ts'
64+
import {
65+
AssertionError,
66+
AssertionResult,
67+
} from "https://deno.land/x/[email protected]/mod.ts";
6368
```

index.d.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
interface Result {
2+
name: "AssertionError" | "AssertionResult";
3+
ok: boolean;
4+
toJSON(...args: unknown[]): Record<string, unknown>;
5+
}
6+
7+
declare class AssertionError<T> extends Error implements Result {
8+
[key: string]: unknown
9+
name: "AssertionError";
10+
ok: false;
11+
message: string;
12+
// deno-lint-ignore ban-types
13+
constructor(message: string, props?: T, ssf?: Function);
14+
stack: string;
15+
toJSON(stack?: boolean): Record<string, unknown>;
16+
}
17+
18+
declare class AssertionResult<T> implements Result {
19+
[key: string]: unknown
20+
name: "AssertionResult";
21+
ok: true;
22+
message: string;
23+
constructor(props?: T);
24+
toJSON(): Record<string, unknown>;
25+
}
26+
27+
export { AssertionError, AssertionResult, Result };

mod.ts

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,71 @@
1-
const canElideFrames = 'captureStackTrace' in Error
2-
const startStackFrames = new WeakMap()
1+
import { Result } from "./index.d.ts";
32

4-
interface Result {
5-
name: 'AssertionError' | 'AssertionResult'
6-
ok: boolean
7-
toJSON(...args: unknown[]): Record<string, unknown>
8-
}
3+
type V8Error = ErrorConstructor & {
4+
// deno-lint-ignore ban-types
5+
captureStackTrace(err: Error, ssf: Function): void;
6+
};
7+
8+
const canElideFrames = "captureStackTrace" in Error;
99

1010
export class AssertionError<T> extends Error implements Result {
1111
[key: string]: unknown
1212

13-
get name(): 'AssertionError' {
14-
return 'AssertionError'
13+
get name(): "AssertionError" {
14+
return "AssertionError";
1515
}
1616

1717
get ok() {
18-
return false
18+
return false;
1919
}
2020

21-
constructor(public message = 'Unspecified AssertionError', props?: T, ssf?: Function) {
22-
super(message)
23-
if (canElideFrames && ssf) startStackFrames.set(this, ssf)
21+
constructor(
22+
public message = "Unspecified AssertionError",
23+
props?: T,
24+
// deno-lint-ignore ban-types
25+
ssf?: Function,
26+
) {
27+
super(message);
28+
if (canElideFrames) {
29+
(Error as V8Error).captureStackTrace(
30+
this,
31+
ssf || AssertionError,
32+
);
33+
}
2434
for (const key in props) {
2535
if (!(key in this)) {
26-
// @ts-ignore
36+
// @ts-ignore: allow arbitrary assignment of values onto class
2737
this[key] = props[key];
2838
}
2939
}
3040
}
3141

32-
get stack() {
33-
if (canElideFrames) {
34-
return (Error as any).captureStackTrace(this, startStackFrames.get(this) || AssertionError);
35-
} else {
36-
return super.stack
37-
}
38-
}
39-
40-
toJSON(stack: boolean): Record<string, unknown> {
42+
toJSON(stack?: boolean): Record<string, unknown> {
4143
return {
4244
...this,
4345
name: this.name,
4446
message: this.message,
4547
ok: false,
4648
// include stack if exists and not turned off
4749
stack: stack !== false ? this.stack : undefined,
48-
}
50+
};
4951
}
50-
5152
}
5253

5354
export class AssertionResult<T> implements Result {
5455
[key: string]: unknown
5556

56-
get name(): 'AssertionResult' {
57-
return 'AssertionResult'
57+
get name(): "AssertionResult" {
58+
return "AssertionResult";
5859
}
5960

6061
get ok() {
61-
return true
62+
return true;
6263
}
6364

6465
constructor(props?: T) {
6566
for (const key in props) {
6667
if (!(key in this)) {
67-
// @ts-ignore
68+
// @ts-ignore: allow arbitrary assignment of values onto class
6869
this[key] = props[key];
6970
}
7071
}
@@ -75,6 +76,6 @@ export class AssertionResult<T> implements Result {
7576
...this,
7677
name: this.name,
7778
ok: this.ok,
78-
}
79+
};
7980
}
8081
}

0 commit comments

Comments
 (0)