diff --git a/eslint.config.mjs b/eslint.config.mjs index 8b98727c..ab3a0717 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -53,7 +53,7 @@ export default [ files: [ '**/*.cjs', '**/cjs/**/*.js', - 'packages/ava/test/testProp.js', + 'packages/ava/test/ava-specs/testProp.js', '**/ava.config.js', '**/jest.config.js', 'packages/expect-type/src/*.js', diff --git a/packages/ava/package.json b/packages/ava/package.json index cb78847d..318d3a8e 100644 --- a/packages/ava/package.json +++ b/packages/ava/package.json @@ -28,8 +28,7 @@ "build:publish-types": "tsc -p tsconfig.publish.types.json && tsc -p tsconfig.publish.types.json --outDir lib/cjs", "build:publish-cjs": "tsc -p tsconfig.publish.json --outDir lib/cjs && cp package.cjs-template.json lib/cjs/package.json", "build:publish-esm": "tsc -p tsconfig.publish.json --module es2015 --moduleResolution node", - "ava-test": "ava --config test/ava.config.js -s -t", - "test": "sh test.sh", + "test": "vitest", "test-bundle:cjs": "ava --config test-bundle/ava.config.cjs", "test-bundle:mjs": "ava --config test-bundle/ava.config.mjs", "test-bundle": "pnpm run test-bundle:cjs && pnpm run test-bundle:mjs", @@ -59,7 +58,9 @@ "esm": "^3.2.25", "fast-check": "workspace:*", "rxjs": "^7.8.2", - "typescript": "~5.7.3" + "typescript": "~5.7.3", + "vite": "^6.1.1", + "vitest": "^2.1.9" }, "keywords": [ "ava", diff --git a/packages/ava/test.sh b/packages/ava/test.sh deleted file mode 100644 index 2336c90c..00000000 --- a/packages/ava/test.sh +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/sh - -npm run ava-test >test/out.log 2>&1 - -for expectedContent in \ - "ok [0-9]* - should never be executed (with seed=48) # SKIP" \ - "ok [0-9]* - should run first" \ - "ok [0-9]* - should run after" \ - "ok [0-9]* - should run serially" \ - "ok [0-9]* - should pass on no-failed asserts synchronous property" \ - "ok [0-9]* - should pass on no-failed asserts asynchronous property" \ - "not ok [0-9]* - should fail on failing asserts synchronous property" \ - "not ok [0-9]* - should fail on failing asserts asynchronous property" \ - "not ok [0-9]* - should fail on synchronous property not running any assertions even if returning undefined" \ - "not ok [0-9]* - should fail on asynchronous property not running any assertions even if returning undefined" \ - "not ok [0-9]* - should fail on synchronous property not running any assertions even if returning true" \ - "not ok [0-9]* - should fail on asynchronous property not running any assertions even if returning true" \ - "not ok [0-9]* - should fail on synchronous property not running any assertions returning false" \ - "not ok [0-9]* - should fail on asynchronous property not running any assertions returning false" \ - "ok [0-9]* - should pass on synchronous properties having only successful assertions even if returning false" \ - "ok [0-9]* - should pass on asynchronous properties having only successful assertions even if returning false" \ - "ok [0-9]* - should pass on property returning passing Observable" \ - "not ok [0-9]* - should fail on property returning failing Observable" \ - "not ok [0-9]* - should fail with seed=4242 and path=\"25\" (with seed=4242)" \ - "ok [0-9]* - should pass on followed plan" \ - "not ok [0-9]* - should fail on not followed plan" \ - "ok [0-9]* - should pass kitchen sink" \ - "not ok [0-9]* - should fail kitchen sink" \ - "ok [0-9]* - should ignore the result when fc.pre interrupted the execution on synchronous properties" \ - "ok [0-9]* - should ignore the result when fc.pre interrupted the execution on asynchronous properties" \ - "ok [0-9]* - should ignore the result when fc.pre interrupted the execution on properties backed by Observables" \ - "ok [0-9]* - should pass as the property fails" \ - "not ok [0-9]* - should fail as the property passes" -do - echo "Checking: ${expectedContent}" - cat test/out.log | grep "^${expectedContent}" >/dev/null 2>&1 - if [ $? -ne 0 ]; then - cat test/out.log - echo "=== TEST FAILED ===" - echo "Unable to find: ${expectedContent}" - exit 1 - fi -done - -echo "TEST PASSED" diff --git a/packages/ava/test/ava-specs/ava.config.js b/packages/ava/test/ava-specs/ava.config.js new file mode 100644 index 00000000..fe11044d --- /dev/null +++ b/packages/ava/test/ava-specs/ava.config.js @@ -0,0 +1 @@ +export default { files: ['test/ava-specs/testProp.js'] }; diff --git a/packages/ava/test/testProp.js b/packages/ava/test/ava-specs/testProp.js similarity index 99% rename from packages/ava/test/testProp.js rename to packages/ava/test/ava-specs/testProp.js index d916a471..d53c94eb 100644 --- a/packages/ava/test/testProp.js +++ b/packages/ava/test/ava-specs/testProp.js @@ -1,4 +1,4 @@ -import { testProp, fc } from '../lib/ava-fast-check.js'; +import { testProp, fc } from '../../lib/ava-fast-check.js'; import { Observable, map } from 'rxjs'; const delay = (duration) => diff --git a/packages/ava/test/ava.config.js b/packages/ava/test/ava.config.js deleted file mode 100644 index 848288b9..00000000 --- a/packages/ava/test/ava.config.js +++ /dev/null @@ -1 +0,0 @@ -export default { files: ['test/testProp.js'] }; diff --git a/packages/ava/test/main.spec.ts b/packages/ava/test/main.spec.ts new file mode 100644 index 00000000..30290db2 --- /dev/null +++ b/packages/ava/test/main.spec.ts @@ -0,0 +1,53 @@ +import * as path from 'path'; +import * as url from 'url'; +import { promisify } from 'util'; +import { execFile as _execFile } from 'child_process'; +import { describe, expect, it } from 'vitest'; + +const execFile = promisify(_execFile); +// @ts-expect-error --module must be higher +const __dirname = url.fileURLToPath(new URL('.', import.meta.url)); +const avaPackageRoot = path.join(__dirname, '..'); + +describe('ava', () => { + it('should pass', async () => { + const { stdout: specOutput } = await execFile( + 'node', + ['./node_modules/ava/entrypoints/cli.mjs', '--config', 'test/ava-specs/ava.config.js', '-s', '-t'], + { cwd: avaPackageRoot }, + ).catch((err) => err); + const expectedContentLines = [ + /ok \d+ - should never be executed \(with seed=48\) # SKIP/, + /ok \d+ - should run first/, + /ok \d+ - should run after/, + /ok \d+ - should run serially/, + /ok \d+ - should pass on no-failed asserts synchronous property/, + /ok \d+ - should pass on no-failed asserts asynchronous property/, + /not ok \d+ - should fail on failing asserts synchronous property/, + /not ok \d+ - should fail on failing asserts asynchronous property/, + /not ok \d+ - should fail on synchronous property not running any assertions even if returning undefined/, + /not ok \d+ - should fail on asynchronous property not running any assertions even if returning undefined/, + /not ok \d+ - should fail on synchronous property not running any assertions even if returning true/, + /not ok \d+ - should fail on asynchronous property not running any assertions even if returning true/, + /not ok \d+ - should fail on synchronous property not running any assertions returning false/, + /not ok \d+ - should fail on asynchronous property not running any assertions returning false/, + /ok \d+ - should pass on synchronous properties having only successful assertions even if returning false/, + /ok \d+ - should pass on asynchronous properties having only successful assertions even if returning false/, + /ok \d+ - should pass on property returning passing Observable/, + /not ok \d+ - should fail on property returning failing Observable/, + /not ok \d+ - should fail with seed=4242 and path="25" \(with seed=4242\)/, + /ok \d+ - should pass on followed plan/, + /not ok \d+ - should fail on not followed plan/, + /ok \d+ - should pass kitchen sink/, + /not ok \d+ - should fail kitchen sink/, + /ok \d+ - should ignore the result when fc.pre interrupted the execution on synchronous properties/, + /ok \d+ - should ignore the result when fc.pre interrupted the execution on asynchronous properties/, + /ok \d+ - should ignore the result when fc.pre interrupted the execution on properties backed by Observables/, + /ok \d+ - should pass as the property fails/, + /not ok \d+ - should fail as the property passes/, + ]; + for (const expectedContentLine of expectedContentLines) { + expect(specOutput).toMatch(expectedContentLine); + } + }); +}); diff --git a/packages/ava/vitest.config.ts b/packages/ava/vitest.config.ts new file mode 100644 index 00000000..50423843 --- /dev/null +++ b/packages/ava/vitest.config.ts @@ -0,0 +1,10 @@ +import type { UserConfig } from 'vite'; +import { defineConfig } from 'vitest/config'; + +// @ts-expect-error - We will fix that one by bumping Vitest to v3 +const config: UserConfig = defineConfig({ + test: { + include: ['**/test/*.{test,spec}.?(c|m)[jt]s?(x)'], + }, +}); +export default config; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index bf45d192..ec9dfeb0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -127,6 +127,12 @@ importers: typescript: specifier: ~5.7.3 version: 5.7.3 + vite: + specifier: ^6.1.1 + version: 6.1.1(@types/node@22.13.5)(jiti@1.21.7)(lightningcss@1.29.1)(terser@5.39.0)(yaml@2.7.0) + vitest: + specifier: ^2.1.9 + version: 2.1.9(@types/node@22.13.5)(happy-dom@17.1.3)(lightningcss@1.29.1)(terser@5.39.0) packages/expect-type: devDependencies: