-
Notifications
You must be signed in to change notification settings - Fork 3
Types #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
daogrady
wants to merge
23
commits into
main
Choose a base branch
from
feat/types
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+622
−56
Draft
Types #17
Changes from 9 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
0c00c93
First few types
daogrady 2c19746
Reuse Axios types
daogrady 6b129cf
Formatting
daogrady 9112ec4
More types
daogrady 64651b9
Merge branch 'main' into feat/types
daogrady 9aea8a8
Restore types
daogrady cec36d4
More types
daogrady 3099e43
Add globals
daogrady a6992c4
More types
daogrady d4727ef
Types
daogrady e064709
Types
daogrady 61f782e
Types
daogrady d780811
Types
daogrady 99a219d
Types
daogrady 1af46bf
Types
daogrady 31d21e6
Types
daogrady 48d97dc
Types
daogrady 96250b0
Types
daogrady 64f7214
Types
daogrady c977026
Types
daogrady 365fd8e
Types
daogrady f4855ec
Types
daogrady 3553c93
Types
daogrady File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import type { mock } from 'node:test' | ||
|
|
||
| declare global { | ||
| // when extending global, only var can be used | ||
| var describe: { | ||
| each: () => void; | ||
| skip: { | ||
| each: () => void; | ||
| } | ||
| } | (() => void); | ||
| var xdescribe: typeof describe['skip']; | ||
| var it: { | ||
| each: () => void, | ||
| skip: () => void | ||
| } | ||
| var test: typeof it; | ||
| var xtest: typeof it['skip']; | ||
| function before(message: string & Function?, method: Function): void; | ||
| function beforeEach(): void | ||
| function beforeAll(message: string & Function?, method: Function): void; | ||
| function after(message: string & Function?, method: Function): void; | ||
| function afterEach(): void; | ||
| function afterAll(message: string & Function?, method: Function): void; | ||
| function expect(): void; | ||
|
|
||
| var chai: { | ||
| expect: typeof expect, | ||
| should?: () => void, | ||
| fake?: boolean | ||
| } | ||
|
|
||
| var jest: { | ||
| fn: () => void; | ||
| spyOn: typeof mock.method; | ||
| restoreAllMocks: () => void; | ||
| resetAllMocks: () => void; | ||
| clearAllMocks: () => void; | ||
| clearAllTimers: () => void; | ||
| mock: ( | ||
| module: string | unknown, | ||
| fn?: Function, | ||
| o?: { virtual?: boolean } | ||
| ) => void; | ||
| setTimeout: () => void; | ||
| } | ||
|
|
||
| // cds-dk types | ||
| var cds: { | ||
| repl: unknown | ||
| } | ||
| } | ||
| export {}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,8 @@ | ||
| const { inspect } = require('node:util') | ||
|
|
||
| /** | ||
| * @param {{status: any, body: any}} x | ||
| */ | ||
| const format = x => inspect( | ||
| is.error(x) ? x.message | ||
| : typeof x === 'object' && 'status' in x && 'body' in x ? { status: x.status, body: x.body } | ||
|
|
@@ -8,22 +12,39 @@ const format = x => inspect( | |
| ) | ||
|
|
||
| const expect = module.exports = actual => { | ||
| const chainable = function (x) { return this.call(x) }; delete chainable.length | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| const chainable = function (x) { | ||
| return this.call(x) | ||
| } | ||
| return Object.setPrototypeOf(chainable, new Assertion(actual)) | ||
| } | ||
|
|
||
| /** | ||
| * @template T | ||
| * @typedef {(x: any) => x is T} Is */ | ||
|
|
||
| const is = new class { | ||
| Array = Array.isArray | ||
| /** @type {Is<Error>} */ | ||
| Error = x => x instanceof Error || x?.stack && x.message | ||
| /** @type {Is<Symbol>} */ | ||
| Symbol = x => typeof x === 'symbol' | ||
| /** @type {Is<Object>} */ | ||
| Object = x => typeof x === 'object' // && x && !is.array(x) | ||
| /** @type {Is<String>} */ | ||
| String = x => typeof x === 'string' || x instanceof String | ||
| /** @type {Is<Number>} */ | ||
| Number = x => typeof x === 'number' || x instanceof Number | ||
| /** @type {Is<Boolean>} */ | ||
| Boolean = x => typeof x === 'boolean' || x instanceof Boolean | ||
| /** @type {Is<Promise<unknown>>} */ | ||
| Promise = x => x instanceof Promise | ||
| /** @type {Is<RegExp>} */ | ||
| RegExp = x => x instanceof RegExp | ||
| /** @type {Is<Date>} */ | ||
| Date = x => x instanceof Date | ||
| /** @type {Is<Set<unknown>>} */ | ||
| Set = x => x instanceof Set | ||
| /** @type {Is<Map<unknown, unknown>>} */ | ||
| Map = x => x instanceof Map | ||
| array = this.Array | ||
| error = this.Error | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,10 @@ | ||
| global.before = (m,fn=m) => global.beforeAll(fn) | ||
| global.after = (m,fn=m) => global.afterAll(fn) | ||
| /** | ||
| * @param {string} message | ||
| * @param {string} [fn] | ||
| */ | ||
| global.before = (message, fn = message) => global.beforeAll(fn) | ||
| /** | ||
| * @param {string} message | ||
| * @param {string} [fn] | ||
| */ | ||
| global.after = (message, fn = message) => global.afterAll(fn) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| const { describe, test, before, after, beforeEach, afterEach, mock } = require('node:test') | ||
| /** @param {{length: number} & Function} fn */ | ||
| const _fn = fn => !fn.length ? fn : (_,done) => fn (done) | ||
|
|
||
| describe.each = test.each = describe.skip.each = test.skip.each = require('./test-each') | ||
|
|
@@ -24,6 +25,7 @@ global.chai = { | |
|
|
||
| global.jest = { | ||
| fn: (..._) => mock.fn (..._), | ||
| // @ts-expect-error - tsc doesn't understand proxy overloads + spreading | ||
| spyOn: (..._) => mock.method (..._), | ||
| restoreAllMocks: ()=> mock.restoreAll(), | ||
| resetAllMocks: ()=> mock.reset(), | ||
|
|
@@ -32,10 +34,12 @@ global.jest = { | |
| mock (module, fn = ()=>{}, o) { | ||
| if (typeof module === 'string') { | ||
| const path = require.resolve (module) | ||
| // @ts-expect-error - missing props on Module, but we only need exports | ||
| return require.cache[path] = { get exports () { | ||
| return require.cache[path] = o?.virtual ? fn() : Object.assign (require(path), fn()) | ||
| }} | ||
| } | ||
| return undefined | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this happened implicitly before and TS didn't like it that way. |
||
| }, | ||
| setTimeout(){} | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed, as underscore is generally used for "variables I don't use", "don't care", or "throwaway" (both, in Python, as well as in the ESLint rules
no-unused-vars).If there's a good reason for keeping the underscore, do let me know.