From 9775e7fb01b435c928623eb733b31c3ef77e6d31 Mon Sep 17 00:00:00 2001 From: tommy-mitchell Date: Sun, 21 Jul 2024 19:37:35 -0500 Subject: [PATCH 01/11] update endpoint example --- .gitignore | 1 + .xo-config.cjs | 1 - docs/recipes/endpoint-testing.md | 25 ++++++++++++++++++------- examples/endpoint-testing/app.js | 6 ++---- examples/endpoint-testing/package.json | 9 +++++---- examples/endpoint-testing/test.js | 22 ++++++++++++++-------- 6 files changed, 40 insertions(+), 24 deletions(-) diff --git a/.gitignore b/.gitignore index 1f8ca5804..1d0a1618c 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ /test-tap/**/node_modules/ /test/**/fixtures/**/node_modules/*/ /examples/**/node_modules/ +/examples/**/package-lock.json diff --git a/.xo-config.cjs b/.xo-config.cjs index 4a84a1a58..acc03e8c1 100644 --- a/.xo-config.cjs +++ b/.xo-config.cjs @@ -43,7 +43,6 @@ module.exports = { rules: { 'ava/no-ignored-test-files': 'off', 'ava/no-only-test': 'off', - 'unicorn/prefer-module': 'off', }, }, { diff --git a/docs/recipes/endpoint-testing.md b/docs/recipes/endpoint-testing.md index 5eaa08394..d0e85660f 100644 --- a/docs/recipes/endpoint-testing.md +++ b/docs/recipes/endpoint-testing.md @@ -4,21 +4,23 @@ Translations: [EspaΓ±ol](https://github.com/avajs/ava-docs/blob/main/es_ES/docs/ [![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/avajs/ava/tree/main/examples/endpoint-testing?file=test.js&terminal=test&view=editor) -AVA doesn't have a built-in method for testing endpoints, but you can use any HTTP client of your choosing, for example [`got`](https://github.com/sindresorhus/got). You'll also need to start an HTTP server, preferably on a unique port so that you can run tests in parallel. For that we recommend [`test-listen`](https://github.com/zeit/test-listen). +AVA doesn't have a built-in method for testing endpoints, but you can use any HTTP client of your choosing, for example [`ky`](https://github.com/sindresorhus/ky). You'll also need to start an HTTP server, preferably on a unique port so that you can run tests in parallel. For that we recommend [`async-listen`](https://github.com/vercel/async-listen). Since tests run concurrently, it's best to create a fresh server instance at least for each test file, but perhaps even for each test. This can be accomplished with `test.before()` and `test.beforeEach()` hooks and `t.context`. If you start your server using a `test.before()` hook you should make sure to execute your tests serially. Check out the example below: ```js -import http from 'node:http'; +import {createServer} from 'node:http'; + +import {listen} from 'async-listen'; import test from 'ava'; -import got from 'got'; -import listen from 'test-listen'; -import app from '../app'; +import ky, {HTTPError} from 'ky'; + +import app from './app.js'; test.before(async t => { - t.context.server = http.createServer(app); + t.context.server = createServer(app); t.context.prefixUrl = await listen(t.context.server); }); @@ -27,9 +29,18 @@ test.after.always(t => { }); test.serial('get /user', async t => { - const {email} = await got('user', {prefixUrl: t.context.prefixUrl}).json(); + const {email} = await ky('user', {prefixUrl: t.context.prefixUrl}).json(); + t.is(email, 'ava@rocks.com'); }); + +test.serial('404', async t => { + await t.throwsAsync( + ky('password', {prefixUrl: t.context.prefixUrl}), + {message: /Request failed with status code 404 Not Found/, instanceOf: HTTPError}, + ); +}); + ``` Other libraries you may find useful: diff --git a/examples/endpoint-testing/app.js b/examples/endpoint-testing/app.js index f9f715df6..4c7eb75c6 100644 --- a/examples/endpoint-testing/app.js +++ b/examples/endpoint-testing/app.js @@ -1,6 +1,4 @@ -'use strict'; - -module.exports = (request, response) => { +export default function app(request, response) { if (request.url === '/user') { response.setHeader('Content-Type', 'application/json'); response.end(JSON.stringify({email: 'ava@rocks.com'})); @@ -8,4 +6,4 @@ module.exports = (request, response) => { response.writeHead('404'); response.end(); } -}; +} diff --git a/examples/endpoint-testing/package.json b/examples/endpoint-testing/package.json index c1003774c..794d41ddc 100644 --- a/examples/endpoint-testing/package.json +++ b/examples/endpoint-testing/package.json @@ -1,12 +1,13 @@ { "name": "ava-endpoint-testing", "description": "Example for endpoint testing", + "type": "module", "scripts": { - "test": "ava" + "test": "ava test.js" }, "devDependencies": { - "ava": "^3.15.0", - "got": "^11.8.2", - "test-listen": "^1.1.0" + "ava": "^6.1.3", + "ky": "^1.4.0", + "async-listen": "^3.0.1" } } diff --git a/examples/endpoint-testing/test.js b/examples/endpoint-testing/test.js index 413e68ccc..76d7bddc8 100644 --- a/examples/endpoint-testing/test.js +++ b/examples/endpoint-testing/test.js @@ -1,14 +1,13 @@ -'use strict'; -const http = require('node:http'); +import {createServer} from 'node:http'; -const test = require('ava'); -const got = require('got'); -const listen = require('test-listen'); +import {listen} from 'async-listen'; +import test from 'ava'; +import ky, {HTTPError} from 'ky'; -const app = require('./app.js'); +import app from './app.js'; test.before(async t => { - t.context.server = http.createServer(app); + t.context.server = createServer(app); t.context.prefixUrl = await listen(t.context.server); }); @@ -17,7 +16,14 @@ test.after.always(t => { }); test.serial('get /user', async t => { - const {email} = await got('user', {prefixUrl: t.context.prefixUrl}).json(); + const {email} = await ky('user', {prefixUrl: t.context.prefixUrl}).json(); t.is(email, 'ava@rocks.com'); }); + +test.serial('404', async t => { + await t.throwsAsync( + ky('password', {prefixUrl: t.context.prefixUrl}), + {message: /Request failed with status code 404 Not Found/, instanceOf: HTTPError}, + ); +}); From 447377a483bc98fd89dd8177a39ce1d05779c408 Mon Sep 17 00:00:00 2001 From: tommy-mitchell Date: Sun, 21 Jul 2024 19:57:40 -0500 Subject: [PATCH 02/11] update macros examples --- examples/macros/index.js | 4 +++- examples/macros/package.json | 5 +++-- examples/macros/test.js | 15 ++++++++------- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/examples/macros/index.js b/examples/macros/index.js index a5a11214b..c17afd446 100644 --- a/examples/macros/index.js +++ b/examples/macros/index.js @@ -1 +1,3 @@ -exports.sum = (a, b) => a + b; +export function sum(a, b) { + return a + b; +} diff --git a/examples/macros/package.json b/examples/macros/package.json index 44e851513..8dc675379 100644 --- a/examples/macros/package.json +++ b/examples/macros/package.json @@ -1,10 +1,11 @@ { "name": "ava-macros", "description": "Example for reusing test logic through macros", + "type": "module", "scripts": { - "test": "ava" + "test": "ava test.js" }, "devDependencies": { - "ava": "^3.15.0" + "ava": "^6.1.3" } } diff --git a/examples/macros/test.js b/examples/macros/test.js index 4b3648dde..b53d814eb 100644 --- a/examples/macros/test.js +++ b/examples/macros/test.js @@ -1,12 +1,13 @@ -const test = require('ava'); +import test from 'ava'; -const {sum} = require('./index.js'); +import {sum} from './index.js'; -function macro(t, a, b, expected) { - t.is(sum(a, b), expected); -} - -macro.title = (providedTitle, a, b, expected) => `${providedTitle ?? ''} ${a}+${b} = ${expected}`.trim(); +const macro = test.macro({ + exec(t, a, b, expected) { + t.is(sum(a, b), expected); + }, + title: (providedTitle, a, b, expected) => `${providedTitle ?? ''} ${a}+${b} = ${expected}`.trim(), +}); test(macro, 2, 2, 4); test(macro, 3, 3, 6); From 28a25856809b7c0fd5dcba5f36208330104ab44b Mon Sep 17 00:00:00 2001 From: tommy-mitchell Date: Sun, 21 Jul 2024 19:58:09 -0500 Subject: [PATCH 03/11] update matching titles example --- docs/05-command-line.md | 10 ---------- examples/matching-titles/package.json | 5 +++-- examples/matching-titles/test.js | 3 +-- 3 files changed, 4 insertions(+), 14 deletions(-) diff --git a/docs/05-command-line.md b/docs/05-command-line.md index 3154b52a1..a92ed2654 100644 --- a/docs/05-command-line.md +++ b/docs/05-command-line.md @@ -144,16 +144,6 @@ test('moo will also run', t => { test.only('boo will run but not exclusively', t => { t.pass(); }); - -// Won't run, no title -test(function (t) { - t.fail(); -}); - -// Won't run, no explicit title -test(function foo(t) { - t.fail(); -}); ``` ## Running tests at specific line numbers diff --git a/examples/matching-titles/package.json b/examples/matching-titles/package.json index 41ccb750a..bc0fd3e85 100644 --- a/examples/matching-titles/package.json +++ b/examples/matching-titles/package.json @@ -1,10 +1,11 @@ { "name": "ava-matching-titles", "description": "Example for running tests with matching titles", + "type": "module", "scripts": { - "test": "ava --match='*oo*'" + "test": "ava test.js --match='*oo*'" }, "devDependencies": { - "ava": "^3.15.0" + "ava": "^6.1.3" } } diff --git a/examples/matching-titles/test.js b/examples/matching-titles/test.js index 4c6cbd96b..c5672fd0c 100644 --- a/examples/matching-titles/test.js +++ b/examples/matching-titles/test.js @@ -1,5 +1,4 @@ -'use strict'; -const test = require('ava'); +import test from 'ava'; test('foo will run', t => { t.pass(); From 5f534dc86ca9f601fb707ff4881061fae66dafbb Mon Sep 17 00:00:00 2001 From: tommy-mitchell Date: Sun, 21 Jul 2024 19:58:32 -0500 Subject: [PATCH 04/11] update line numbers example --- examples/specific-line-numbers/package.json | 3 ++- examples/specific-line-numbers/test.js | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/specific-line-numbers/package.json b/examples/specific-line-numbers/package.json index 9aef3692c..347a3079d 100644 --- a/examples/specific-line-numbers/package.json +++ b/examples/specific-line-numbers/package.json @@ -1,10 +1,11 @@ { "name": "ava-specific-line-numbers", "description": "Example for running tests at specific line numbers", + "type": "module", "scripts": { "test": "ava test.js:5" }, "devDependencies": { - "ava": "^3.15.0" + "ava": "^6.1.3" } } diff --git a/examples/specific-line-numbers/test.js b/examples/specific-line-numbers/test.js index 56f6991d2..4c4977204 100644 --- a/examples/specific-line-numbers/test.js +++ b/examples/specific-line-numbers/test.js @@ -1,5 +1,4 @@ -'use strict'; -const test = require('ava'); +import test from 'ava'; test('unicorn', t => { t.pass(); From 8c92061b213e582c736aeafa4ed93762ad8e7d66 Mon Sep 17 00:00:00 2001 From: tommy-mitchell Date: Sun, 21 Jul 2024 19:58:48 -0500 Subject: [PATCH 05/11] update tap reporter example --- examples/tap-reporter/package.json | 5 +++-- examples/tap-reporter/readme.md | 2 +- examples/tap-reporter/test.js | 3 +-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/tap-reporter/package.json b/examples/tap-reporter/package.json index 38c62a14e..c107e57eb 100644 --- a/examples/tap-reporter/package.json +++ b/examples/tap-reporter/package.json @@ -1,11 +1,12 @@ { "name": "ava-tap-reporter", "description": "Example for a custom TAP reporter", + "type": "module", "scripts": { - "test": "ava --tap | tap-nyan" + "test": "ava test.js --tap | tap-nyan" }, "devDependencies": { - "ava": "^3.15.0", + "ava": "^6.1.3", "tap-nyan": "^1.1.0" } } diff --git a/examples/tap-reporter/readme.md b/examples/tap-reporter/readme.md index 816f0c5e3..c276727d3 100644 --- a/examples/tap-reporter/readme.md +++ b/examples/tap-reporter/readme.md @@ -1,5 +1,5 @@ # Running tests at specific line numbers -> Example for a [custom TAP reporter](https://github.com/avajs/ava/blob/main/docs/05-command-line.md#running-tests-at-specific-line-numbers) +> Example for a [custom TAP reporter](https://github.com/avajs/ava/blob/main/docs/05-command-line.md#tap-reporter) [![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/avajs/ava/tree/main/examples/tap-reporter?file=test.js&terminal=test&view=editor) diff --git a/examples/tap-reporter/test.js b/examples/tap-reporter/test.js index 224061b89..a6b1bb9b3 100644 --- a/examples/tap-reporter/test.js +++ b/examples/tap-reporter/test.js @@ -1,5 +1,4 @@ -'use strict'; -const test = require('ava'); +import test from 'ava'; test('unicorn', t => { t.pass(); From 173f3013ec391d70fd1ae06a46b79e919d7878d3 Mon Sep 17 00:00:00 2001 From: tommy-mitchell Date: Sun, 21 Jul 2024 20:46:25 -0500 Subject: [PATCH 06/11] update timeouts examples --- examples/timeouts/index.js | 40 +++++++++++++++------------------- examples/timeouts/package.json | 5 +++-- examples/timeouts/test.js | 31 +++++++++++--------------- 3 files changed, 33 insertions(+), 43 deletions(-) diff --git a/examples/timeouts/index.js b/examples/timeouts/index.js index 92709dd7b..2ba9a3648 100644 --- a/examples/timeouts/index.js +++ b/examples/timeouts/index.js @@ -1,35 +1,29 @@ -'use strict'; - const delay = ms => new Promise(resolve => { setTimeout(resolve, ms); }); -exports.fetchUsers = async () => { +export async function fetchUsers() { await delay(50); - return [ - { - id: 1, - firstName: 'Ava', - name: 'Rocks', - email: 'ava@rocks.com', - }, - ]; -}; + return [{ + id: 1, + firstName: 'Ava', + name: 'Rocks', + email: 'ava@rocks.com', + }]; +} -exports.fetchPosts = async userId => { +export async function fetchPosts(userId) { await delay(200); - return [ - { - id: 1, - userId, - message: 'AVA Rocks πŸš€', - }, - ]; -}; + return [{ + id: 1, + userId, + message: 'AVA Rocks πŸš€', + }]; +} -exports.createPost = async message => { +export async function createPost(message) { await delay(3000); return { @@ -37,4 +31,4 @@ exports.createPost = async message => { userId: 1, message, }; -}; +} diff --git a/examples/timeouts/package.json b/examples/timeouts/package.json index ec288c771..50bb66fa7 100644 --- a/examples/timeouts/package.json +++ b/examples/timeouts/package.json @@ -1,10 +1,11 @@ { "name": "ava-timeouts", "description": "Example for test timeouts", + "type": "module", "scripts": { - "test": "ava --timeout=2s --verbose" + "test": "ava test.js --timeout=2s --verbose" }, "devDependencies": { - "ava": "^3.15.0" + "ava": "^6.1.3" } } diff --git a/examples/timeouts/test.js b/examples/timeouts/test.js index f16945c10..5f67fbd8e 100644 --- a/examples/timeouts/test.js +++ b/examples/timeouts/test.js @@ -1,21 +1,18 @@ -'use strict'; -const test = require('ava'); +import test from 'ava'; -const {fetchUsers, fetchPosts, createPost} = require('./index.js'); +import {fetchUsers, fetchPosts, createPost} from './index.js'; test('retrieve users', async t => { t.timeout(100); const users = await fetchUsers(); - t.deepEqual(users, [ - { - id: 1, - firstName: 'Ava', - name: 'Rocks', - email: 'ava@rocks.com', - }, - ]); + t.deepEqual(users, [{ + id: 1, + firstName: 'Ava', + name: 'Rocks', + email: 'ava@rocks.com', + }]); }); test('retrieve posts', async t => { @@ -23,13 +20,11 @@ test('retrieve posts', async t => { const posts = await fetchPosts(1); - t.deepEqual(posts, [ - { - id: 1, - userId: 1, - message: 'AVA Rocks πŸš€', - }, - ]); + t.deepEqual(posts, [{ + id: 1, + userId: 1, + message: 'AVA Rocks πŸš€', + }]); }); test('create post', async t => { From 893f291cbd05f0fcf77f2bc9315f055b9f0d7f26 Mon Sep 17 00:00:00 2001 From: tommy-mitchell Date: Sun, 21 Jul 2024 21:15:16 -0500 Subject: [PATCH 07/11] update ts basic example --- .gitignore | 1 + examples/typescript-basic/package.json | 9 +++++---- examples/typescript-basic/source/test.ts | 2 +- examples/typescript-basic/tsconfig.json | 1 - 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 1d0a1618c..b7f378288 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ /test/**/fixtures/**/node_modules/*/ /examples/**/node_modules/ /examples/**/package-lock.json +/examples/**/build/ diff --git a/examples/typescript-basic/package.json b/examples/typescript-basic/package.json index ad85254fc..af1ab949d 100644 --- a/examples/typescript-basic/package.json +++ b/examples/typescript-basic/package.json @@ -1,14 +1,15 @@ { "name": "ava-typescript-basic", "description": "Basic example for AVA with TypeScript", + "type": "module", "scripts": { "test": "ava" }, "devDependencies": { - "@ava/typescript": "^2.0.0", - "@sindresorhus/tsconfig": "^1.0.2", - "ava": "^3.15.0", - "typescript": "^4.3.4" + "@ava/typescript": "^5.0.0", + "@sindresorhus/tsconfig": "^6.0.0", + "ava": "^6.1.3", + "typescript": "~5.5.3" }, "ava": { "typescript": { diff --git a/examples/typescript-basic/source/test.ts b/examples/typescript-basic/source/test.ts index 339a2321a..aa9bead68 100644 --- a/examples/typescript-basic/source/test.ts +++ b/examples/typescript-basic/source/test.ts @@ -1,6 +1,6 @@ import test from 'ava'; -import {sum, subtract} from '.'; +import {sum, subtract} from './index.js'; test('sum', t => { t.is(sum(0, 0), 0); diff --git a/examples/typescript-basic/tsconfig.json b/examples/typescript-basic/tsconfig.json index 60833d016..7b7de8c66 100644 --- a/examples/typescript-basic/tsconfig.json +++ b/examples/typescript-basic/tsconfig.json @@ -1,7 +1,6 @@ { "extends": "@sindresorhus/tsconfig", "compilerOptions": { - "module": "commonjs", "outDir": "build", } } From 23729ab6096c0371e94d561a48af1af24ae5f5b7 Mon Sep 17 00:00:00 2001 From: tommy-mitchell Date: Sun, 21 Jul 2024 21:17:57 -0500 Subject: [PATCH 08/11] update ts context example --- examples/typescript-context/package.json | 9 +++++---- examples/typescript-context/source/test.ts | 8 ++++---- examples/typescript-context/tsconfig.json | 1 - 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/examples/typescript-context/package.json b/examples/typescript-context/package.json index f577a30ec..9e0f89cf9 100644 --- a/examples/typescript-context/package.json +++ b/examples/typescript-context/package.json @@ -1,14 +1,15 @@ { "name": "ava-typescript-context", "description": "TypeScript example for typing t.context", + "type": "module", "scripts": { "test": "ava" }, "devDependencies": { - "@ava/typescript": "^2.0.0", - "@sindresorhus/tsconfig": "^1.0.2", - "ava": "^3.15.0", - "typescript": "^4.3.4" + "@ava/typescript": "^5.0.0", + "@sindresorhus/tsconfig": "^6.0.0", + "ava": "^6.1.3", + "typescript": "~5.5.3" }, "ava": { "typescript": { diff --git a/examples/typescript-context/source/test.ts b/examples/typescript-context/source/test.ts index feccdaac4..b73a4ee3b 100644 --- a/examples/typescript-context/source/test.ts +++ b/examples/typescript-context/source/test.ts @@ -1,10 +1,10 @@ -import anyTest, {TestInterface} from 'ava'; +import anyTest, {type TestFn} from 'ava'; -import {concat} from '.'; +import {concat} from './index.js'; -const test = anyTest as TestInterface<{sort: (a: string, b: string) => number}>; +const test = anyTest as TestFn<{sort: (a: string, b: string) => number}>; -test.beforeEach(t => { +test.before(t => { t.context = { sort: (a: string, b: string) => a.localeCompare(b) }; diff --git a/examples/typescript-context/tsconfig.json b/examples/typescript-context/tsconfig.json index 60833d016..7b7de8c66 100644 --- a/examples/typescript-context/tsconfig.json +++ b/examples/typescript-context/tsconfig.json @@ -1,7 +1,6 @@ { "extends": "@sindresorhus/tsconfig", "compilerOptions": { - "module": "commonjs", "outDir": "build", } } From a611a02d43da111c021750434d296dd5ee3c0756 Mon Sep 17 00:00:00 2001 From: tommy-mitchell Date: Sun, 21 Jul 2024 21:24:50 -0500 Subject: [PATCH 09/11] add loader example --- .gitignore | 1 - examples/typescript-basic/.gitignore | 1 + examples/typescript-context/.gitignore | 1 + examples/typescript-loader/.gitignore | 1 + examples/typescript-loader/index.ts | 1 + examples/typescript-loader/package.json | 22 ++++++++++++++++++++++ examples/typescript-loader/readme.md | 5 +++++ examples/typescript-loader/test.ts | 8 ++++++++ examples/typescript-loader/tsconfig.json | 3 +++ 9 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 examples/typescript-basic/.gitignore create mode 100644 examples/typescript-context/.gitignore create mode 100644 examples/typescript-loader/.gitignore create mode 100644 examples/typescript-loader/index.ts create mode 100644 examples/typescript-loader/package.json create mode 100644 examples/typescript-loader/readme.md create mode 100644 examples/typescript-loader/test.ts create mode 100644 examples/typescript-loader/tsconfig.json diff --git a/.gitignore b/.gitignore index b7f378288..1d0a1618c 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,3 @@ /test/**/fixtures/**/node_modules/*/ /examples/**/node_modules/ /examples/**/package-lock.json -/examples/**/build/ diff --git a/examples/typescript-basic/.gitignore b/examples/typescript-basic/.gitignore new file mode 100644 index 000000000..378eac25d --- /dev/null +++ b/examples/typescript-basic/.gitignore @@ -0,0 +1 @@ +build diff --git a/examples/typescript-context/.gitignore b/examples/typescript-context/.gitignore new file mode 100644 index 000000000..378eac25d --- /dev/null +++ b/examples/typescript-context/.gitignore @@ -0,0 +1 @@ +build diff --git a/examples/typescript-loader/.gitignore b/examples/typescript-loader/.gitignore new file mode 100644 index 000000000..6626d2979 --- /dev/null +++ b/examples/typescript-loader/.gitignore @@ -0,0 +1 @@ +.tsimp diff --git a/examples/typescript-loader/index.ts b/examples/typescript-loader/index.ts new file mode 100644 index 000000000..45b80413c --- /dev/null +++ b/examples/typescript-loader/index.ts @@ -0,0 +1 @@ +export const multiply = (a: number, b: number) => a * b; diff --git a/examples/typescript-loader/package.json b/examples/typescript-loader/package.json new file mode 100644 index 000000000..686626c6c --- /dev/null +++ b/examples/typescript-loader/package.json @@ -0,0 +1,22 @@ +{ + "name": "ava-typescript-context", + "description": "TypeScript example for typing t.context", + "type": "module", + "scripts": { + "test": "ava" + }, + "devDependencies": { + "@sindresorhus/tsconfig": "^6.0.0", + "ava": "^6.1.3", + "tsimp": "^2.0.11", + "typescript": "~5.5.3" + }, + "ava": { + "extensions": { + "ts": "module" + }, + "nodeArguments": [ + "--import=tsimp" + ] + } +} diff --git a/examples/typescript-loader/readme.md b/examples/typescript-loader/readme.md new file mode 100644 index 000000000..9f395bdd6 --- /dev/null +++ b/examples/typescript-loader/readme.md @@ -0,0 +1,5 @@ +# TypeScript loader example + +> TypeScript example for configuring AVA with [ESM loaders](https://github.com/avajs/ava/blob/main/docs/recipes/typescript.md#enabling-avas-support-for-typescript-test-files) + +[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/avajs/ava/tree/main/examples/typescript-loader?file=test.ts&terminal=test&view=editor) diff --git a/examples/typescript-loader/test.ts b/examples/typescript-loader/test.ts new file mode 100644 index 000000000..a03f12264 --- /dev/null +++ b/examples/typescript-loader/test.ts @@ -0,0 +1,8 @@ +import test from 'ava'; + +import { multiply } from './index.js'; + +test('multiply', (t) => { + t.is(multiply(1, 0), 0); + t.is(multiply(2, 3), 6); +}); diff --git a/examples/typescript-loader/tsconfig.json b/examples/typescript-loader/tsconfig.json new file mode 100644 index 000000000..e49282769 --- /dev/null +++ b/examples/typescript-loader/tsconfig.json @@ -0,0 +1,3 @@ +{ + "extends": "@sindresorhus/tsconfig" +} From 569fc4a3c1c512b1780791206dce83c5f7dad8a9 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Mon, 22 Jul 2024 13:55:04 +0200 Subject: [PATCH 10/11] Update endpoint-testing.md --- docs/recipes/endpoint-testing.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/recipes/endpoint-testing.md b/docs/recipes/endpoint-testing.md index d0e85660f..bd5d18432 100644 --- a/docs/recipes/endpoint-testing.md +++ b/docs/recipes/endpoint-testing.md @@ -40,7 +40,6 @@ test.serial('404', async t => { {message: /Request failed with status code 404 Not Found/, instanceOf: HTTPError}, ); }); - ``` Other libraries you may find useful: From bac765a1778c6db9f509aa0617825a69287c7486 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Mon, 22 Jul 2024 14:18:46 +0200 Subject: [PATCH 11/11] Update test.ts --- examples/typescript-loader/test.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/examples/typescript-loader/test.ts b/examples/typescript-loader/test.ts index a03f12264..a7dedf718 100644 --- a/examples/typescript-loader/test.ts +++ b/examples/typescript-loader/test.ts @@ -1,8 +1,7 @@ import test from 'ava'; +import {multiply} from './index.js'; -import { multiply } from './index.js'; - -test('multiply', (t) => { +test('multiply', t => { t.is(multiply(1, 0), 0); t.is(multiply(2, 3), 6); });