Skip to content
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

Require TypeScript 4.7 #3041

Merged
merged 9 commits into from Jul 10, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .c8rc.json
@@ -1,7 +1,7 @@
{
"all": true,
"exclude": [
"{coverage,examples,media,test,test-d,test-tap,types}/**",
"{coverage,examples,media,test,test-types,test-tap,types}/**",
"*.config.cjs",
"*.d.*(c|m)ts"
],
Expand Down
7 changes: 3 additions & 4 deletions .github/workflows/ci.yml
Expand Up @@ -42,7 +42,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ts-version: [~4.4, ~4.5, ~4.6, ~4.7]
ts-version: [~4.7]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
Expand All @@ -55,9 +55,8 @@ jobs:
- run: npm i typescript@${TS_VERSION}
env:
TS_VERSION: ${{ matrix.ts-version }}
- run: npm ls typescript
continue-on-error: true
- run: npx tsd
- run: ./node_modules/typescript/bin/tsc --version
- run: ./node_modules/typescript/bin/tsc --noEmit

lockfile_churn:
name: Test package-lock for unexpected modifications
Expand Down
9 changes: 9 additions & 0 deletions .xo-config.cjs
Expand Up @@ -49,6 +49,15 @@ module.exports = {
'unicorn/no-empty-file': 'off',
},
},
{
files: 'test-types/**',
rules: {
'ava/assertion-arguments': 'off',
'ava/no-ignored-test-files': 'off',
'ava/no-skip-assert': 'off',
'ava/use-t': 'off',
},
},
{
// TODO: Update tests.
files: 'test/**',
Expand Down
2 changes: 1 addition & 1 deletion ava.config.js
@@ -1,6 +1,6 @@
export default { // eslint-disable-line import/no-anonymous-default-export
files: ['test/**', '!test/**/{fixtures,helpers}/**'],
ignoredByWatcher: ['{coverage,docs,media,test-d,test-tap}/**'],
ignoredByWatcher: ['{coverage,docs,media,test-types,test-tap}/**'],
environmentVariables: {
AVA_FAKE_SCM_ROOT: '.fake-root', // This is an internal test flag.
},
Expand Down
2 changes: 1 addition & 1 deletion docs/recipes/typescript.md
Expand Up @@ -4,7 +4,7 @@ Translations: [Español](https://github.com/avajs/ava-docs/blob/main/es_ES/docs/

AVA comes bundled with a TypeScript definition file. This allows developers to leverage TypeScript for writing tests.

This guide assumes you've already set up TypeScript for your project. Note that AVA's definition expects at least version 4.4.
This guide assumes you've already set up TypeScript for your project. Note that AVA's definition expects at least version 4.7.

## Enabling AVA's support for TypeScript test files

Expand Down
2 changes: 0 additions & 2 deletions entrypoints/index.d.cts

This file was deleted.

2 changes: 2 additions & 0 deletions entrypoints/main.d.cts
@@ -0,0 +1,2 @@
export {default} from './main.js';
export * from './main.js';
12 changes: 12 additions & 0 deletions entrypoints/main.d.ts
@@ -0,0 +1,12 @@
import type {TestFn} from '../types/test-fn.js';

export * from '../types/assertions.js';
export * from '../types/try-fn.js';
export * from '../types/test-fn.js';
export * from '../types/subscribable.js';

/** Call to declare a test, or chain to declare hooks or test modifiers */
declare const test: TestFn;

/** Call to declare a test, or chain to declare hooks or test modifiers */
export default test;
2 changes: 1 addition & 1 deletion entrypoints/plugin.d.cts
@@ -1 +1 @@
export * from '../plugin.js'
export * from './plugin.js'
File renamed without changes.
12 changes: 0 additions & 12 deletions index.d.ts

This file was deleted.

18 changes: 14 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 7 additions & 8 deletions package.json
Expand Up @@ -11,18 +11,18 @@
"exports": {
".": {
"import": {
"types": "./index.d.ts",
"types": "./entrypoints/main.d.ts",
"default": "./entrypoints/main.mjs"
},
"require": {
"types": "./entrypoints/index.d.cts",
"types": "./entrypoints/main.d.cts",
"default": "./entrypoints/main.cjs"
}
},
"./eslint-plugin-helper": "./entrypoints/eslint-plugin-helper.cjs",
"./plugin": {
"import": {
"types": "./plugin.d.ts",
"types": "./entrypoints/plugin.d.ts",
"default": "./entrypoints/plugin.mjs"
},
"require": {
Expand All @@ -37,14 +37,12 @@
},
"scripts": {
"cover": "c8 --report=none test-ava && c8 --report=none --no-clean tap && c8 report",
"test": "xo && tsd && npm run -s cover"
"test": "xo && tsc --noEmit && npm run -s cover"
},
"files": [
"entrypoints",
"lib",
"types",
"index.d.ts",
"plugin.d.ts"
"types"
],
"keywords": [
"🦄",
Expand Down Expand Up @@ -131,6 +129,7 @@
"devDependencies": {
"@ava/test": "github:avajs/test",
"@ava/typescript": "^3.0.1",
"@sindresorhus/tsconfig": "^3.0.1",
"@sinonjs/fake-timers": "^9.1.2",
"ansi-escapes": "^5.0.0",
"c8": "^7.11.3",
Expand All @@ -145,7 +144,7 @@
"tempy": "^2.0.0",
"touch": "^3.1.0",
"tsd": "^0.20.0",
"typescript": "^4.7.2",
"typescript": "^4.7.3",
"xo": "^0.49.0",
"zen-observable": "^0.8.15"
},
Expand Down
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-unsafe-call */
import test from '../../../../../../../entrypoints/main.cjs';

test('feature test title', t => {
Expand Down
1 change: 0 additions & 1 deletion test-tap/fixture/snapshots/test-sourcemaps/src/test.ts
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-unsafe-call */
import test from '../../../../../entrypoints/main.cjs';

test('top level test title', t => {
Expand Down
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-unsafe-call */
import test from '../../../../../../entrypoints/main.cjs';

test('test title', t => {
Expand Down
File renamed without changes.
40 changes: 40 additions & 0 deletions test-types/import-in-cts/assertions-as-type-guards.cts
@@ -0,0 +1,40 @@
import test from 'ava';
import {expectType} from 'tsd';

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

test('deepEqual', t => {
const actual: unknown = {};
if (t.deepEqual(actual, expected)) {
expectType<Expected>(actual);
}
});

test('like', t => {
const actual: unknown = {};
if (t.like(actual, expected)) {
expectType<Expected>(actual);
}
});

test('is', t => {
const actual: unknown = 2;
if (t.is(actual, 3 as const)) {
expectType<3>(actual);
}
});

test('false', t => {
const actual: unknown = true;
if (t.false(actual)) {
expectType<false>(actual);
}
});

test('true', t => {
const actual: unknown = false;
if (t.true(actual)) {
expectType<true>(actual);
}
});
33 changes: 33 additions & 0 deletions test-types/import-in-cts/context.cts
@@ -0,0 +1,33 @@
/* eslint-disable @typescript-eslint/no-empty-function */
import anyTest, {ExecutionContext, TestFn} from 'ava';
import {expectError, expectType} from 'tsd';

interface Context {
foo: string;
}

const test = anyTest as TestFn<Context>;

const macro = test.macro((t, _expected: number) => {
expectType<string>(t.context.foo);
});

test.beforeEach(t => {
expectType<Context>(t.context);
});

// @ts-expect-error TS2769
expectError(test('foo is bar', macro, 'bar')); // eslint-disable-line @typescript-eslint/no-confusing-void-expression

anyTest('default context is unknown', t => {
expectType<unknown>(t.context);
});

// See https://github.com/avajs/ava/issues/2253
interface Covariant extends Context {
bar: number;
}

const test2 = anyTest as TestFn<Covariant>;
const hook = (_t: ExecutionContext<Context>) => {};
test2.beforeEach(hook);
29 changes: 29 additions & 0 deletions test-types/import-in-cts/deep-equal.cts
@@ -0,0 +1,29 @@
import test from 'ava';
import {expectType} from 'tsd';

test('actual extends expected', t => {
type Expected = {foo: [1, 2, 3]};
const expected: Expected = {foo: [1, 2, 3]};
const actual = {foo: [1, 2, 3]};
if (t.deepEqual(actual, expected)) {
expectType<Expected>(actual);
}
});

test('expected extends actual', t => {
type Expected = {foo: Array<number | string>};
type Actual = {foo: number[]};
const expected: Expected = {foo: [1, 2, 3]};
const actual: Actual = {foo: [1, 2, 3]};
if (t.deepEqual(actual, expected)) {
expectType<Actual>(expected);
}
});

test('neither extends the each other', t => {
type Expected = {readonly foo: readonly [1, 2, 3]};
type Actual = {foo: number[]};
const expected: Expected = {foo: [1, 2, 3]};
const actual: Actual = {foo: [1, 2, 3]};
t.deepEqual(actual, expected);
});
20 changes: 20 additions & 0 deletions test-types/import-in-cts/implementation-result.cts
@@ -0,0 +1,20 @@
/* eslint-disable @typescript-eslint/no-empty-function */
import test from 'ava';

test.after('return anything else', _t => ({
foo: 'bar',
subscribe() {},
then() {}, // eslint-disable-line unicorn/no-thenable
}));

test('return a promise-like', _t => ({
then(resolve) { // eslint-disable-line unicorn/no-thenable
resolve?.(); // eslint-disable-line @typescript-eslint/no-floating-promises
},
}));

test('return a subscribable', _t => ({
subscribe({complete}) {
complete();
},
}));
25 changes: 25 additions & 0 deletions test-types/import-in-cts/like.cts
@@ -0,0 +1,25 @@
import test from 'ava';

test('like', t => {
t.like({
map: new Map([['foo', 'bar']]),
nested: {
baz: 'thud',
qux: 'quux',
},
}, {
map: new Map([['foo', 'bar']]),
nested: {
baz: 'thud',
},
});

type Foo = {
foo?: 'foo';
bar?: 'bar';
};

const foo: Foo = {bar: 'bar'};
const {foo: _, ...expected} = foo;
t.like(expected, {bar: 'bar'});
});