Skip to content

Commit

Permalink
Make test-types work with tsc and XO
Browse files Browse the repository at this point in the history
This used to work… but didn't for the new timout tests.
  • Loading branch information
novemberborn committed Jul 3, 2023
1 parent 6ca0f1c commit 5a9a627
Show file tree
Hide file tree
Showing 23 changed files with 35 additions and 28 deletions.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"exports": {
".": {
"import": {
"types": "./entrypoints/main.d.ts",
"types": "./entrypoints/main.d.mts",
"default": "./entrypoints/main.mjs"
},
"require": {
Expand All @@ -22,7 +22,7 @@
"./eslint-plugin-helper": "./entrypoints/eslint-plugin-helper.cjs",
"./plugin": {
"import": {
"types": "./entrypoints/plugin.d.ts",
"types": "./entrypoints/plugin.d.mts",
"default": "./entrypoints/plugin.mjs"
},
"require": {
Expand Down
2 changes: 1 addition & 1 deletion test-types/import-in-cts/assertions-as-type-guards.cts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import test from 'ava';
import test from '../../entrypoints/main.cjs';
import {expectType} from 'tsd';

type Expected = {foo: 'bar'};
Expand Down
2 changes: 1 addition & 1 deletion test-types/import-in-cts/context.cts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-empty-function */
import anyTest, {ExecutionContext, TestFn} from 'ava';
import anyTest, {ExecutionContext, TestFn} from '../../entrypoints/main.cjs';
import {expectError, expectType} from 'tsd';

interface Context {
Expand Down
2 changes: 1 addition & 1 deletion test-types/import-in-cts/deep-equal.cts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import test from 'ava';
import test from '../../entrypoints/main.cjs';
import {expectType} from 'tsd';

test('actual extends expected', t => {
Expand Down
2 changes: 1 addition & 1 deletion test-types/import-in-cts/implementation-result.cts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-empty-function */
import test from 'ava';
import test from '../../entrypoints/main.cjs';

test.after('return anything else', _t => ({
foo: 'bar',
Expand Down
2 changes: 1 addition & 1 deletion test-types/import-in-cts/like.cts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import test from 'ava';
import test from '../../entrypoints/main.cjs';

test('like', t => {
t.like({
Expand Down
2 changes: 1 addition & 1 deletion test-types/import-in-cts/macros.cts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable no-lone-blocks */
import test, {ExecutionContext} from 'ava';
import test, {ExecutionContext} from '../../entrypoints/main.cjs';
import {expectType} from 'tsd';

// Typed arguments through generics.
Expand Down
2 changes: 1 addition & 1 deletion test-types/import-in-cts/snapshot.cts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import test from 'ava';
import test from '../../entrypoints/main.cjs';
import {expectError} from 'tsd';

test('snapshot', t => {
Expand Down
2 changes: 1 addition & 1 deletion test-types/import-in-cts/teardown.cts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import test from 'ava';
import test from '../../entrypoints/main.cjs';

test('test', t => {
t.teardown(() => {}); // eslint-disable-line @typescript-eslint/no-empty-function
Expand Down
2 changes: 1 addition & 1 deletion test-types/import-in-cts/throws.cts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-empty-function */
import test from 'ava';
import test from '../../entrypoints/main.cjs';
import {expectType} from 'tsd';

class CustomError extends Error {
Expand Down
2 changes: 1 addition & 1 deletion test-types/import-in-cts/try-commit.cts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import test, {ExecutionContext} from 'ava';
import test, {ExecutionContext} from '../../entrypoints/main.cjs';
import {expectType} from 'tsd';

test('attempt', async t => {
Expand Down
3 changes: 2 additions & 1 deletion test-types/module/assertions-as-type-guards.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import test from 'ava';
import {expectType} from 'tsd';

import test from '../../entrypoints/main.mjs';

type Expected = {foo: 'bar'};
const expected: Expected = {foo: 'bar'};

Expand Down
5 changes: 3 additions & 2 deletions test-types/module/context.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* eslint-disable @typescript-eslint/no-empty-function */
import type {ExecutionContext, TestFn} from 'ava';
import anyTest from 'ava';
import {expectError, expectType} from 'tsd';

import type {ExecutionContext, TestFn} from '../../entrypoints/main.mjs';
import anyTest from '../../entrypoints/main.mjs';

type Context = {
foo: string;
};
Expand Down
3 changes: 2 additions & 1 deletion test-types/module/deep-equal.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import test from 'ava';
import {expectType} from 'tsd';

import test from '../../entrypoints/main.mjs';

test('actual extends expected', t => {
type Expected = {foo: [1, 2, 3]};
const expected: Expected = {foo: [1, 2, 3]};
Expand Down
2 changes: 1 addition & 1 deletion test-types/module/implementation-result.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-empty-function */
import test from 'ava';
import test from '../../entrypoints/main.mjs';

test.after('return anything else', _t => ({
foo: 'bar',
Expand Down
2 changes: 1 addition & 1 deletion test-types/module/like.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import test from 'ava';
import test from '../../entrypoints/main.mjs';

test('like', t => {
t.like({
Expand Down
7 changes: 4 additions & 3 deletions test-types/module/macros.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type {ExecutionContext} from 'ava';
import test from 'ava';
import {expectType} from 'tsd';

import type {ExecutionContext} from '../../entrypoints/main.mjs';
import test from '../../entrypoints/main.mjs';

// Typed arguments through generics.
{
const hasLength = test.macro<[string, number]>((t, input, expected) => {
Expand Down Expand Up @@ -118,7 +119,7 @@ test('has length 3 (inferred)', (t, input, expected) => {
t.is(input, expected);
}, 'foo', 3);

test.skip('skip', (t, input, expected) => { // eslint-disable-line ava/no-skip-test
test.skip('skip', (t, input, expected) => {
expectType<string>(input);
expectType<number>(expected);
// @ts-expect-error TS2345
Expand Down
3 changes: 2 additions & 1 deletion test-types/module/snapshot.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import test from 'ava';
import {expectError} from 'tsd';

import test from '../../entrypoints/main.mjs';

test('snapshot', t => {
t.snapshot({foo: 'bar'});
t.snapshot(null, 'a snapshot with a message');
Expand Down
2 changes: 1 addition & 1 deletion test-types/module/teardown.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import test from 'ava';
import test from '../../entrypoints/main.mjs';

test('test', t => {
t.teardown(() => {}); // eslint-disable-line @typescript-eslint/no-empty-function
Expand Down
3 changes: 2 additions & 1 deletion test-types/module/throws.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* eslint-disable @typescript-eslint/no-empty-function */
import test from 'ava';
import {expectType} from 'tsd';

import test from '../../entrypoints/main.mjs';

class CustomError extends Error {
foo: string;

Expand Down
9 changes: 5 additions & 4 deletions test-types/module/try-commit.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type {ExecutionContext} from 'ava';
import test from 'ava';
import {expectType} from 'tsd';

import type {ExecutionContext} from '../../entrypoints/main.mjs';
import test from '../../entrypoints/main.mjs';

test('attempt', async t => {
const attempt = await t.try(
(u, a, b) => {
Expand Down Expand Up @@ -55,11 +56,11 @@ test('all possible variants to pass to t.try', async t => {
void t.try('test', (tt, a, b) => tt.is(a.length, b), 'hello', 5);

// Macro with title
const macro1 = test.macro<[string, number]>({ // eslint-disable-line ava/no-nested-tests
const macro1 = test.macro<[string, number]>({
exec: (tt, a, b) => tt.is(a.length, b),
title: (title, a, b) => `${title ? `${String(title)} ` : ''}str: "${String(a)}" with len: "${String(b)}"`,
});
const macro2 = test.macro<[string, number]>((tt, a, b) => { // eslint-disable-line ava/no-nested-tests
const macro2 = test.macro<[string, number]>((tt, a, b) => {
tt.is(a.slice(b), '');
});

Expand Down

0 comments on commit 5a9a627

Please sign in to comment.