Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ jobs:
with:
persist-credentials: false

- name: Set up node@24
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: 24

- name: Set up bun@latest
uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0

Expand Down
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ echo

# Check lint
printSubHeader "Check lint on staged files..."
bun biome lint --fix --staged --no-errors-on-unmatched
bunx biome lint --fix --staged --no-errors-on-unmatched
printPassed "Lint"

# Reindex staged files
Expand Down
10 changes: 3 additions & 7 deletions __tests__/__example/example.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { join } from 'node:path';
import { TypesTesting } from 'src';
import exampleModule from './example-module';
import * as ExampleTypes from './example-types';
import type * as ExampleTypes from './example-types';

if (process.versions.bun) {
let bunTest = (await import('bun:test')).default;
Expand Down Expand Up @@ -38,16 +38,12 @@ describe('example-module', () => {
test(`exampleModule.getName type is function without parameter and return 'example-module'`, () => {
// using runtime argument
expectType(exampleModule.getName).toBe<() => 'example-module'>();
expectType(exampleModule.getName).toBe<{
(): 'example-module';
}>();
expectType(exampleModule.getName).toBe<() => 'example-module'>();
expectType(exampleModule.getName()).toBe<'example-module'>();

// using type argument
expectType<typeof exampleModule.getName>().toBe<() => 'example-module'>();
expectType<typeof exampleModule.getName>().toBe<{
(): 'example-module';
}>();
expectType<typeof exampleModule.getName>().toBe<() => 'example-module'>();
expectType<
ReturnType<typeof exampleModule.getName>
>().toBe<'example-module'>();
Expand Down
2 changes: 1 addition & 1 deletion __tests__/__example/jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type JestConfigWithTsJest, createJsWithTsEsmPreset } from 'ts-jest';
import { createJsWithTsEsmPreset, type JestConfigWithTsJest } from 'ts-jest';

const presetConfig = createJsWithTsEsmPreset({
tsconfig: '__tests__/__example/tsconfig.jest.json'
Expand Down
4 changes: 3 additions & 1 deletion __tests__/__example/tsconfig.jest.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"ignoreDeprecations": "6.0",
"module": "ESNext",
"target": "ESNext",
"isolatedModules": true,
"esModuleInterop": true,
"outDir": "."
"outDir": ".",
"rootDir": "../../"
},
"files": ["example.test.ts"],
"include": ["../../src"]
Expand Down
7 changes: 7 additions & 0 deletions __tests__/__example/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from 'vitest/config';

export default defineConfig({
resolve: {
tsconfigPaths: true
}
});
2 changes: 1 addition & 1 deletion __tests__/__integrations/jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type JestConfigWithTsJest, createJsWithTsEsmPreset } from 'ts-jest';
import { createJsWithTsEsmPreset, type JestConfigWithTsJest } from 'ts-jest';

const presetConfig = createJsWithTsEsmPreset({
tsconfig: '__tests__/__integrations/tsconfig.jest.json'
Expand Down
5 changes: 1 addition & 4 deletions __tests__/__integrations/jest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ if (process.versions.bun) {
meta: Record<string, unknown>;
}[];
}[];
} =
await Bun.$`node --experimental-vm-modules node_modules/jest/bin/jest.js jest.test.ts -c=__tests__/__integrations/jest.config.ts --json`
.nothrow()
.json();
} = await Bun.$`bun test:integrations:jest --json`.nothrow().json();

describe('jest', () => {
test('successfully run in jest', () => {
Expand Down
9 changes: 3 additions & 6 deletions __tests__/__integrations/test-case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,13 @@ const prepareThrowMessage = (fnName: string) => {
};
};

export const testCase = (
export const testCase = <T extends import('@jest/expect').JestExpect>(
describe: (label: string, fn: () => void) => void,
test:
| import('vitest').TestAPI
| import('bun:test').Test
| import('bun:test').Test<unknown[]>
| import('@jest/types').Global.ItConcurrent,
expect:
| import('vitest').ExpectStatic
| import('bun:test').Expect
| import('@jest/expect').JestExpect
expect: T
) => {
describe('toBeAny', () => {
const throwMessage = prepareThrowMessage('toBeAny');
Expand Down
4 changes: 3 additions & 1 deletion __tests__/__integrations/tsconfig.jest.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"ignoreDeprecations": "6.0",
"module": "ESNext",
"target": "ESNext",
"isolatedModules": true,
"esModuleInterop": true,
"outDir": "."
"outDir": ".",
"rootDir": "../../"
},
"files": ["jest.test.ts", "test-case.ts"],
"include": ["../../src"]
Expand Down
7 changes: 7 additions & 0 deletions __tests__/__integrations/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from 'vitest/config';

export default defineConfig({
resolve: {
tsconfigPaths: true
}
});
34 changes: 19 additions & 15 deletions __tests__/__integrations/vitest.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
import { afterEach, describe, expect, test, vi } from 'vitest';
import { testCase } from './test-case';

vi.mock('ansis', async (importOriginal) => {
if (process.versions.bun) {
return {};
}

const originalAnsis = await importOriginal<typeof import('ansis')>();
return {
...originalAnsis,
default: {
...originalAnsis.default,
green: vi.fn((str: string) => str),
red: vi.fn((str: string) => str),
reset: vi.fn((str: string) => str)
}
};
});

if (process.versions.bun) {
let bunTest = (await import('bun:test')).default;

Expand All @@ -24,7 +41,7 @@ if (process.versions.bun) {
meta: Record<string, unknown>;
}[];
}[];
} = await Bun.$`bunx vitest run vitest.test.ts --reporter=json`
} = await Bun.$`bun test:integrations:vitest --reporter json`
.nothrow()
.json();

Expand All @@ -46,24 +63,11 @@ if (process.versions.bun) {
}
});
} else {
vi.mock('ansis', async (importOriginal) => {
const originalAnsis = await importOriginal<typeof import('ansis')>();
return {
...originalAnsis,
default: {
...originalAnsis.default,
green: vi.fn((str: string) => str),
red: vi.fn((str: string) => str),
reset: vi.fn((str: string) => str)
}
};
});

describe('typesTesting', () => {
afterEach(() => {
vi.clearAllMocks();
});

testCase(describe, test, expect);
testCase(describe, test, expect as any);
});
}
2 changes: 1 addition & 1 deletion __tests__/lib/compiler/create-error-value.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { createErrorValue } from 'lib/compiler/create-error-value';
import ts from 'typescript';

describe('lib > compiler > create-error-value', () => {
let resolvePath: JestMock.Spied<typeof ts.sys.resolvePath>;
let resolvePath: jest.Spied<typeof ts.sys.resolvePath>;
let sourceFile: ts.SourceFile;
let caller: ts.Node;

Expand Down
4 changes: 2 additions & 2 deletions __tests__/lib/factories/assertion.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, it, jest } from 'bun:test';
import {
assertionWithTypeArgument,
assertionWithoutTypeArgument
assertionWithoutTypeArgument,
assertionWithTypeArgument
} from 'lib/factories/assertion';

describe('lib > factories > assertion', () => {
Expand Down
49 changes: 24 additions & 25 deletions __tests__/src/blueprints/TypesTesting.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,26 @@ import {
} from 'bun:test';
import type { Compiler } from 'lib';
import * as Lib from 'lib';
import { TypesTesting } from 'src/blueprints/TypesTesting';
import * as __Internal from 'src/blueprints/__internal/TypesTestingError';
import { TypesTesting } from 'src/blueprints/TypesTesting';

const { TypesTestingError: OriginalTypesTestingError } = __Internal;
const { Compiler: OriginalCompiler, Assertion: OriginalAssertion } = Lib;

describe('src > blueprints > TypesTesting', () => {
let error: __Internal.TypesTestingError;
let compileMock: jest.Mock<Compiler.Compile>;
let assertionMock: typeof OriginalAssertion;
let TypesTestingErrorMock: jest.SpiedClass<typeof OriginalTypesTestingError>;

beforeEach(() => {
error = {
name: '',
message: '',
stack: '',
errors: new Map<string, Compiler.CompileResultError>()
} as unknown as __Internal.TypesTestingError;

compileMock = jest.fn(() => ({
files: ['test.ts'],
options: {},
Expand All @@ -31,12 +39,17 @@ describe('src > blueprints > TypesTesting', () => {
toBe: jest.fn()
} as unknown as typeof assertionMock;

TypesTestingErrorMock = jest.fn().mockImplementation(() => ({
name: '',
message: '',
stack: '',
errors: new Map<string, Compiler.CompileResultError>()
}));
TypesTestingErrorMock = jest
.fn()
.mockImplementation(
(
_: Map<string, Compiler.CompileResultError>,
onErrorFound: __Internal.OnErrorFound
) => {
onErrorFound('');
return error;
}
);

mock.module('lib', () => ({
Compiler: {
Expand Down Expand Up @@ -131,29 +144,15 @@ describe('src > blueprints > TypesTesting', () => {
);
});

it('should throw TypesTestingError if afterErrorFound is called', () => {
it('should throw if error.name exists', () => {
const test = new TypesTesting({});
test.prepare();

TypesTestingErrorMock.mockImplementationOnce((_, afterErrorFound) => {
const _this = {} as __Internal.TypesTestingError;
afterErrorFound('', _this);
return _this;
});
const { toBe } = test.expectType();

error.name = 'TypesTestingError';
expect(() => test.expectType<'error on expect call'>()).toThrow();

TypesTestingErrorMock.mockImplementationOnce(
jest.fn()
).mockImplementationOnce((_, afterErrorFound) => {
const _this = {} as __Internal.TypesTestingError;
afterErrorFound('', _this);
return _this;
});

expect(() =>
test.expectType<''>().toBe<'error on assertionCall'>()
).toThrow();
expect(() => toBe<'error on assertionCall'>()).toThrow();
});

it('should return assertion methods when no error', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,36 @@ import {
import * as Ansis from 'ansis';
import type { Compiler } from 'lib';
import {
type AfterErrorFound,
type OnErrorFound,
TypesTestingError
} from 'src/blueprints/__internal/TypesTestingError';

describe('TypesTestingError', () => {
let afterErrorFound: AfterErrorFound;
let onErrorFound: OnErrorFound;
let errorMessage: string;
let errors: Compiler.CompileResult['errors'];

beforeEach(() => {
afterErrorFound = jest.fn();
onErrorFound = jest.fn();
errorMessage = 'message';
errors = new Map<string, Compiler.CompileResultError>();
});

describe('instantiation', () => {
it('should be instance of Error', () => {
const error = new TypesTestingError(errors, afterErrorFound);
const error = new TypesTestingError(errors, onErrorFound);
expect(error).toBeInstanceOf(Error);
});

describe('no error found', () => {
let error: TypesTestingError;

beforeEach(() => {
error = new TypesTestingError(errors, afterErrorFound);
error = new TypesTestingError(errors, onErrorFound);
});

it('should not call afterErrorFound fn', () => {
expect(afterErrorFound).toHaveBeenCalledTimes(0);
it('should not call onErrorFound fn', () => {
expect(onErrorFound).toHaveBeenCalledTimes(0);
});

it('should return empty name', () => {
Expand Down Expand Up @@ -89,7 +89,7 @@ describe('TypesTestingError', () => {
} as Compiler.CompileResultError;
});

error = new TypesTestingError(errors, afterErrorFound);
error = new TypesTestingError(errors, onErrorFound);
});

afterEach(() => {
Expand All @@ -100,8 +100,8 @@ describe('TypesTestingError', () => {
});
});

it('should call afterErrorFound fn', () => {
expect(afterErrorFound).toHaveBeenCalledTimes(1);
it('should call onErrorFound fn', () => {
expect(onErrorFound).toHaveBeenCalledTimes(1);
});

it('should return TypesTestingError name', () => {
Expand Down
9 changes: 5 additions & 4 deletions biome.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
"files": {
"ignoreUnknown": true
},
"organizeImports": {
"enabled": true
},
"formatter": {
"enabled": true,
"attributePosition": "multiline",
Expand All @@ -18,7 +15,11 @@
},
"linter": {
"enabled": true,
"ignore": ["__example", "__integrations"],
"includes": [
"**",
"!!__tests__/__example/**",
"!!__tests__/__integrations/**"
],
"rules": {
"recommended": true
}
Expand Down
Binary file modified bun.lockb
Binary file not shown.
Loading
Loading