mirror of
https://github.com/pezkuwichain/pezkuwi-dev.git
synced 2026-04-22 03:17:57 +00:00
Fix TypeScript type definitions for test suite
- Add explicit Describe and It interfaces with todo support - Fix mock type compatibility in jest.ts - Update import assertions to import attributes (assert -> with) - Add dynamic.d.mts declaration file - Fix spec files to use explicit type declarations
This commit is contained in:
Vendored
+2
-2
@@ -58,11 +58,11 @@ function extendMock <F extends AnyFn> (mocked: WithMock<F>) {
|
|||||||
export function jest () {
|
export function jest () {
|
||||||
return {
|
return {
|
||||||
jest: enhanceObj(enhanceObj({
|
jest: enhanceObj(enhanceObj({
|
||||||
fn: <F extends AnyFn> (fn?: F) => extendMock<F>(mock.fn(fn)),
|
fn: <F extends AnyFn> (fn?: F) => extendMock<F>(mock.fn(fn) as unknown as WithMock<F>),
|
||||||
restoreAllMocks: () => {
|
restoreAllMocks: () => {
|
||||||
mock.reset();
|
mock.reset();
|
||||||
},
|
},
|
||||||
spyOn: <F extends AnyFn> (obj: object, key: string) => extendMock<F>(mock.method(obj, key as keyof typeof obj))
|
spyOn: <F extends AnyFn> (obj: object, key: string) => extendMock<F>(mock.method(obj, key as keyof typeof obj) as unknown as WithMock<F>)
|
||||||
}, jestWarn), jestStub)
|
}, jestWarn), jestStub)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
+6
@@ -1,6 +1,12 @@
|
|||||||
// Copyright 2017-2026 @pezkuwi/dev-test authors & contributors
|
// Copyright 2017-2026 @pezkuwi/dev-test authors & contributors
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
import '../globals.d.ts';
|
||||||
|
|
||||||
|
declare const describe: import('./suite.js').Describe;
|
||||||
|
declare const it: import('./suite.js').It;
|
||||||
|
declare const expect: (value: unknown) => { toBe: (expected: unknown) => void; toBeDefined: () => void };
|
||||||
|
|
||||||
describe('describe()', () => {
|
describe('describe()', () => {
|
||||||
// eslint-disable-next-line jest/no-focused-tests
|
// eslint-disable-next-line jest/no-focused-tests
|
||||||
describe.only('.only', () => {
|
describe.only('.only', () => {
|
||||||
|
|||||||
Vendored
+19
-5
@@ -13,6 +13,20 @@ interface WrapOpts {
|
|||||||
|
|
||||||
type WrapFn = (name: string, options: { only?: boolean; skip?: boolean; timeout?: number; todo?: boolean; }, fn: () => void | Promise<void>) => void | Promise<void>;
|
type WrapFn = (name: string, options: { only?: boolean; skip?: boolean; timeout?: number; todo?: boolean; }, fn: () => void | Promise<void>) => void | Promise<void>;
|
||||||
|
|
||||||
|
type TestFn = (name: string, exec: () => void | Promise<void>, timeout?: number) => void;
|
||||||
|
|
||||||
|
export interface Describe extends TestFn {
|
||||||
|
only: TestFn;
|
||||||
|
skip: TestFn;
|
||||||
|
todo: TestFn;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface It extends TestFn {
|
||||||
|
only: TestFn;
|
||||||
|
skip: TestFn;
|
||||||
|
todo: TestFn;
|
||||||
|
}
|
||||||
|
|
||||||
const MINUTE = 60 * 1000;
|
const MINUTE = 60 * 1000;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -23,7 +37,7 @@ const MINUTE = 60 * 1000;
|
|||||||
*
|
*
|
||||||
* @param {} fn
|
* @param {} fn
|
||||||
*/
|
*/
|
||||||
function createWrapper <T extends WrapFn> (fn: T, defaultTimeout: number) {
|
function createWrapper <T extends WrapFn> (fn: T, defaultTimeout: number): Describe | It {
|
||||||
const wrap = (opts: WrapOpts) => (name: string, exec: () => void | Promise<void>, timeout?: number) => fn(name, { ...opts, timeout: (timeout || defaultTimeout) }, exec) as unknown as void;
|
const wrap = (opts: WrapOpts) => (name: string, exec: () => void | Promise<void>, timeout?: number) => fn(name, { ...opts, timeout: (timeout || defaultTimeout) }, exec) as unknown as void;
|
||||||
|
|
||||||
// Ensure that we have consistent helpers on the function. These are not consistently
|
// Ensure that we have consistent helpers on the function. These are not consistently
|
||||||
@@ -33,16 +47,16 @@ function createWrapper <T extends WrapFn> (fn: T, defaultTimeout: number) {
|
|||||||
only: wrap({ only: true }),
|
only: wrap({ only: true }),
|
||||||
skip: wrap({ skip: true }),
|
skip: wrap({ skip: true }),
|
||||||
todo: wrap({ todo: true })
|
todo: wrap({ todo: true })
|
||||||
});
|
}) as Describe | It;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This ensures that the describe and it functions match our actual usages.
|
* This ensures that the describe and it functions match our actual usages.
|
||||||
* This includes .only, .skip and .todo helpers (.each is not applied)
|
* This includes .only, .skip and .todo helpers (.each is not applied)
|
||||||
**/
|
**/
|
||||||
export function suite () {
|
export function suite (): { describe: Describe; it: It } {
|
||||||
return {
|
return {
|
||||||
describe: createWrapper(describe, 60 * MINUTE),
|
describe: createWrapper(describe, 60 * MINUTE) as Describe,
|
||||||
it: createWrapper(it, 2 * MINUTE)
|
it: createWrapper(it, 2 * MINUTE) as It
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+3
-5
@@ -6,7 +6,7 @@
|
|||||||
import type { expect } from './env/expect.js';
|
import type { expect } from './env/expect.js';
|
||||||
import type { jest } from './env/jest.js';
|
import type { jest } from './env/jest.js';
|
||||||
import type { lifecycle } from './env/lifecycle.js';
|
import type { lifecycle } from './env/lifecycle.js';
|
||||||
import type { suite } from './env/suite.js';
|
import type { Describe, It } from './env/suite.js';
|
||||||
|
|
||||||
type Expect = ReturnType<typeof expect>;
|
type Expect = ReturnType<typeof expect>;
|
||||||
|
|
||||||
@@ -14,8 +14,6 @@ type Jest = ReturnType<typeof jest>;
|
|||||||
|
|
||||||
type Lifecycle = ReturnType<typeof lifecycle>;
|
type Lifecycle = ReturnType<typeof lifecycle>;
|
||||||
|
|
||||||
type Suite = ReturnType<typeof suite>;
|
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
var after: Lifecycle['after'];
|
var after: Lifecycle['after'];
|
||||||
var afterAll: Lifecycle['afterAll'];
|
var afterAll: Lifecycle['afterAll'];
|
||||||
@@ -23,9 +21,9 @@ declare global {
|
|||||||
var before: Lifecycle['before'];
|
var before: Lifecycle['before'];
|
||||||
var beforeAll: Lifecycle['beforeAll'];
|
var beforeAll: Lifecycle['beforeAll'];
|
||||||
var beforeEach: Lifecycle['beforeEach'];
|
var beforeEach: Lifecycle['beforeEach'];
|
||||||
var describe: Suite['describe'];
|
var describe: Describe;
|
||||||
var expect: Expect['expect'];
|
var expect: Expect['expect'];
|
||||||
var it: Suite['it'];
|
var it: It;
|
||||||
var jest: Jest['jest'];
|
var jest: Jest['jest'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,8 @@
|
|||||||
"noEmit": true
|
"noEmit": true
|
||||||
},
|
},
|
||||||
"include": [
|
"include": [
|
||||||
"src/**/*.spec.ts"
|
"src/**/*.spec.ts",
|
||||||
|
"src/globals.d.ts"
|
||||||
],
|
],
|
||||||
"references": [
|
"references": [
|
||||||
{ "path": "../dev-test/tsconfig.build.json" }
|
{ "path": "../dev-test/tsconfig.build.json" }
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
// Copyright 2017-2026 @pezkuwi/dev authors & contributors
|
// Copyright 2017-2026 @pezkuwi/dev authors & contributors
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
/// <reference types="@pezkuwi/dev-test/globals.d.ts" />
|
import type { Describe, It } from '@pezkuwi/dev-test/env/suite.js';
|
||||||
|
|
||||||
|
declare const describe: Describe;
|
||||||
|
declare const it: It;
|
||||||
|
declare const expect: (value: unknown) => { toBe: (expected: boolean) => void; toEqual: (expected: unknown) => void };
|
||||||
|
|
||||||
import fs from 'node:fs';
|
import fs from 'node:fs';
|
||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
// Copyright 2017-2026 @pezkuwi/dev authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
export function sum(a: number, b: number): number;
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
import './augmented.js';
|
import './augmented.js';
|
||||||
|
|
||||||
/** This import should appear as-in in the ouput (cjs without asserts) */
|
/** This import should appear as-in in the ouput (cjs without asserts) */
|
||||||
import testJson from '@pezkuwi/dev/rootJs/testJson.json' assert { type: 'json' };
|
import testJson from '@pezkuwi/dev/rootJs/testJson.json' with { type: 'json' };
|
||||||
|
|
||||||
/** Double double work, i.e. re-exports */
|
/** Double double work, i.e. re-exports */
|
||||||
export { Clazz } from './Clazz.js';
|
export { Clazz } from './Clazz.js';
|
||||||
|
|||||||
Reference in New Issue
Block a user