Skip to content

Commit 02f4e27

Browse files
authored
Rely on TypeScript 4.7 and update integration + tests
* Only test against TypeScript 4.7 * Move type definitions to entrypoints/ Only TS 4.7 will resolve them now, but it's cleaner. * Use @sindresorhus/tsconfig * Fix test TypeScript files, make compilable and lintable * Use tsc directly, instead of tsd * Add *.cts versions of type tests * Reorganize type tests * Use tsc directly, avoid npx, print actual version Somehow `npx tsc` was pointing at an older version. Possibly the binstubs are corrupted in CI… somehow.
1 parent d0af729 commit 02f4e27

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+532
-93
lines changed

.c8rc.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"all": true,
33
"exclude": [
4-
"{coverage,examples,media,test,test-d,test-tap,types}/**",
4+
"{coverage,examples,media,test,test-types,test-tap,types}/**",
55
"*.config.cjs",
66
"*.d.*(c|m)ts"
77
],

.github/workflows/ci.yml

+3-4
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
runs-on: ubuntu-latest
4343
strategy:
4444
matrix:
45-
ts-version: [~4.4, ~4.5, ~4.6, ~4.7]
45+
ts-version: [~4.7]
4646
steps:
4747
- uses: actions/checkout@v3
4848
- uses: actions/setup-node@v3
@@ -55,9 +55,8 @@ jobs:
5555
- run: npm i typescript@${TS_VERSION}
5656
env:
5757
TS_VERSION: ${{ matrix.ts-version }}
58-
- run: npm ls typescript
59-
continue-on-error: true
60-
- run: npx tsd
58+
- run: ./node_modules/typescript/bin/tsc --version
59+
- run: ./node_modules/typescript/bin/tsc --noEmit
6160

6261
lockfile_churn:
6362
name: Test package-lock for unexpected modifications

.xo-config.cjs

+9
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ module.exports = {
4949
'unicorn/no-empty-file': 'off',
5050
},
5151
},
52+
{
53+
files: 'test-types/**',
54+
rules: {
55+
'ava/assertion-arguments': 'off',
56+
'ava/no-ignored-test-files': 'off',
57+
'ava/no-skip-assert': 'off',
58+
'ava/use-t': 'off',
59+
},
60+
},
5261
{
5362
// TODO: Update tests.
5463
files: 'test/**',

ava.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export default { // eslint-disable-line import/no-anonymous-default-export
22
files: ['test/**', '!test/**/{fixtures,helpers}/**'],
3-
ignoredByWatcher: ['{coverage,docs,media,test-d,test-tap}/**'],
3+
ignoredByWatcher: ['{coverage,docs,media,test-types,test-tap}/**'],
44
environmentVariables: {
55
AVA_FAKE_SCM_ROOT: '.fake-root', // This is an internal test flag.
66
},

docs/recipes/typescript.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Translations: [Español](https://github.com/avajs/ava-docs/blob/main/es_ES/docs/
44

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

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

99
## Enabling AVA's support for TypeScript test files
1010

entrypoints/index.d.cts

-2
This file was deleted.

entrypoints/main.d.cts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export {default} from './main.js';
2+
export * from './main.js';

entrypoints/main.d.ts

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import type {TestFn} from '../types/test-fn.js';
2+
3+
export * from '../types/assertions.js';
4+
export * from '../types/try-fn.js';
5+
export * from '../types/test-fn.js';
6+
export * from '../types/subscribable.js';
7+
8+
/** Call to declare a test, or chain to declare hooks or test modifiers */
9+
declare const test: TestFn;
10+
11+
/** Call to declare a test, or chain to declare hooks or test modifiers */
12+
export default test;

entrypoints/plugin.d.cts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export * from '../plugin.js'
1+
export * from './plugin.js'
File renamed without changes.

index.d.ts

-12
This file was deleted.

package-lock.json

+14-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+7-8
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@
1111
"exports": {
1212
".": {
1313
"import": {
14-
"types": "./index.d.ts",
14+
"types": "./entrypoints/main.d.ts",
1515
"default": "./entrypoints/main.mjs"
1616
},
1717
"require": {
18-
"types": "./entrypoints/index.d.cts",
18+
"types": "./entrypoints/main.d.cts",
1919
"default": "./entrypoints/main.cjs"
2020
}
2121
},
2222
"./eslint-plugin-helper": "./entrypoints/eslint-plugin-helper.cjs",
2323
"./plugin": {
2424
"import": {
25-
"types": "./plugin.d.ts",
25+
"types": "./entrypoints/plugin.d.ts",
2626
"default": "./entrypoints/plugin.mjs"
2727
},
2828
"require": {
@@ -37,14 +37,12 @@
3737
},
3838
"scripts": {
3939
"cover": "c8 --report=none test-ava && c8 --report=none --no-clean tap && c8 report",
40-
"test": "xo && tsd && npm run -s cover"
40+
"test": "xo && tsc --noEmit && npm run -s cover"
4141
},
4242
"files": [
4343
"entrypoints",
4444
"lib",
45-
"types",
46-
"index.d.ts",
47-
"plugin.d.ts"
45+
"types"
4846
],
4947
"keywords": [
5048
"🦄",
@@ -131,6 +129,7 @@
131129
"devDependencies": {
132130
"@ava/test": "github:avajs/test",
133131
"@ava/typescript": "^3.0.1",
132+
"@sindresorhus/tsconfig": "^3.0.1",
134133
"@sinonjs/fake-timers": "^9.1.2",
135134
"ansi-escapes": "^5.0.0",
136135
"c8": "^7.11.3",
@@ -145,7 +144,7 @@
145144
"tempy": "^2.0.0",
146145
"touch": "^3.1.0",
147146
"tsd": "^0.20.0",
148-
"typescript": "^4.7.2",
147+
"typescript": "^4.7.3",
149148
"xo": "^0.49.0",
150149
"zen-observable": "^0.8.15"
151150
},

test-tap/fixture/snapshots/test-sourcemaps/src/feature/__tests__/test.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable @typescript-eslint/no-unsafe-call */
21
import test from '../../../../../../../entrypoints/main.cjs';
32

43
test('feature test title', t => {

test-tap/fixture/snapshots/test-sourcemaps/src/test.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable @typescript-eslint/no-unsafe-call */
21
import test from '../../../../../entrypoints/main.cjs';
32

43
test('top level test title', t => {

test-tap/fixture/snapshots/test-sourcemaps/src/test/test.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable @typescript-eslint/no-unsafe-call */
21
import test from '../../../../../../entrypoints/main.cjs';
32

43
test('test title', t => {
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import test from 'ava';
2+
import {expectType} from 'tsd';
3+
4+
type Expected = {foo: 'bar'};
5+
const expected: Expected = {foo: 'bar'};
6+
7+
test('deepEqual', t => {
8+
const actual: unknown = {};
9+
if (t.deepEqual(actual, expected)) {
10+
expectType<Expected>(actual);
11+
}
12+
});
13+
14+
test('like', t => {
15+
const actual: unknown = {};
16+
if (t.like(actual, expected)) {
17+
expectType<Expected>(actual);
18+
}
19+
});
20+
21+
test('is', t => {
22+
const actual: unknown = 2;
23+
if (t.is(actual, 3 as const)) {
24+
expectType<3>(actual);
25+
}
26+
});
27+
28+
test('false', t => {
29+
const actual: unknown = true;
30+
if (t.false(actual)) {
31+
expectType<false>(actual);
32+
}
33+
});
34+
35+
test('true', t => {
36+
const actual: unknown = false;
37+
if (t.true(actual)) {
38+
expectType<true>(actual);
39+
}
40+
});

test-types/import-in-cts/context.cts

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/* eslint-disable @typescript-eslint/no-empty-function */
2+
import anyTest, {ExecutionContext, TestFn} from 'ava';
3+
import {expectError, expectType} from 'tsd';
4+
5+
interface Context {
6+
foo: string;
7+
}
8+
9+
const test = anyTest as TestFn<Context>;
10+
11+
const macro = test.macro((t, _expected: number) => {
12+
expectType<string>(t.context.foo);
13+
});
14+
15+
test.beforeEach(t => {
16+
expectType<Context>(t.context);
17+
});
18+
19+
// @ts-expect-error TS2769
20+
expectError(test('foo is bar', macro, 'bar')); // eslint-disable-line @typescript-eslint/no-confusing-void-expression
21+
22+
anyTest('default context is unknown', t => {
23+
expectType<unknown>(t.context);
24+
});
25+
26+
// See https://github.com/avajs/ava/issues/2253
27+
interface Covariant extends Context {
28+
bar: number;
29+
}
30+
31+
const test2 = anyTest as TestFn<Covariant>;
32+
const hook = (_t: ExecutionContext<Context>) => {};
33+
test2.beforeEach(hook);
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import test from 'ava';
2+
import {expectType} from 'tsd';
3+
4+
test('actual extends expected', t => {
5+
type Expected = {foo: [1, 2, 3]};
6+
const expected: Expected = {foo: [1, 2, 3]};
7+
const actual = {foo: [1, 2, 3]};
8+
if (t.deepEqual(actual, expected)) {
9+
expectType<Expected>(actual);
10+
}
11+
});
12+
13+
test('expected extends actual', t => {
14+
type Expected = {foo: Array<number | string>};
15+
type Actual = {foo: number[]};
16+
const expected: Expected = {foo: [1, 2, 3]};
17+
const actual: Actual = {foo: [1, 2, 3]};
18+
if (t.deepEqual(actual, expected)) {
19+
expectType<Actual>(expected);
20+
}
21+
});
22+
23+
test('neither extends the each other', t => {
24+
type Expected = {readonly foo: readonly [1, 2, 3]};
25+
type Actual = {foo: number[]};
26+
const expected: Expected = {foo: [1, 2, 3]};
27+
const actual: Actual = {foo: [1, 2, 3]};
28+
t.deepEqual(actual, expected);
29+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* eslint-disable @typescript-eslint/no-empty-function */
2+
import test from 'ava';
3+
4+
test.after('return anything else', _t => ({
5+
foo: 'bar',
6+
subscribe() {},
7+
then() {}, // eslint-disable-line unicorn/no-thenable
8+
}));
9+
10+
test('return a promise-like', _t => ({
11+
then(resolve) { // eslint-disable-line unicorn/no-thenable
12+
resolve?.(); // eslint-disable-line @typescript-eslint/no-floating-promises
13+
},
14+
}));
15+
16+
test('return a subscribable', _t => ({
17+
subscribe({complete}) {
18+
complete();
19+
},
20+
}));

test-types/import-in-cts/like.cts

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import test from 'ava';
2+
3+
test('like', t => {
4+
t.like({
5+
map: new Map([['foo', 'bar']]),
6+
nested: {
7+
baz: 'thud',
8+
qux: 'quux',
9+
},
10+
}, {
11+
map: new Map([['foo', 'bar']]),
12+
nested: {
13+
baz: 'thud',
14+
},
15+
});
16+
17+
type Foo = {
18+
foo?: 'foo';
19+
bar?: 'bar';
20+
};
21+
22+
const foo: Foo = {bar: 'bar'};
23+
const {foo: _, ...expected} = foo;
24+
t.like(expected, {bar: 'bar'});
25+
});

0 commit comments

Comments
 (0)