diff options
| author | Arnaud Bailly <arnaud@pankzsoft.com> | 2026-08-30 18:08:55 +0200 |
|---|---|---|
| committer | Arnaud Bailly <arnaud@pankzsoft.com> | 2026-09-01 07:58:04 +0200 |
| commit | b3285b3f5878d705fcbeb7165097b6623a02f553 (patch) | |
| tree | 6b08a1eb2e88eb0406979642c7f2b61547815fa8 /pbt/ts/src | |
| parent | 966f532a61b34d187bfdeefed7617fbfb6f768ed (diff) | |
| download | lambda-nantes-b3285b3f5878d705fcbeb7165097b6623a02f553.tar.gz | |
Replace jest with vitest
This implies fixing some quirky modules import logic. Thanks to Claude
for fixing this whole s**t
Diffstat (limited to 'pbt/ts/src')
| -rw-r--r-- | pbt/ts/src/bank.test.ts | 124 | ||||
| -rw-r--r-- | pbt/ts/src/bank.ts | 2 | ||||
| -rw-r--r-- | pbt/ts/src/fs.ts | 4 | ||||
| -rw-r--r-- | pbt/ts/src/index.test.ts | 4 | ||||
| -rw-r--r-- | pbt/ts/src/index.ts | 2 | ||||
| -rw-r--r-- | pbt/ts/src/levelbank.ts | 4 | ||||
| -rw-r--r-- | pbt/ts/src/property.test.ts | 4 | ||||
| -rw-r--r-- | pbt/ts/src/property.ts | 4 |
8 files changed, 72 insertions, 76 deletions
diff --git a/pbt/ts/src/bank.test.ts b/pbt/ts/src/bank.test.ts index 021e4c6..a6b3e76 100644 --- a/pbt/ts/src/bank.test.ts +++ b/pbt/ts/src/bank.test.ts @@ -1,10 +1,10 @@ -import {toNullable} from 'fp-ts/lib/Option'; +import {toNullable} from 'fp-ts/lib/Option.js'; import { Account, Operation, SimpleBank, bankImplementationMatchesModel, -} from './bank'; +} from './bank.js'; import { Gen, Property, @@ -16,10 +16,11 @@ import { listOf, mapOf1 as nonEmptyMap, property, -} from './property'; +} from './property.js'; import Prando from 'prando'; -import {LevelBank} from './levelbank'; -import {withTempFile} from './fs'; +import {LevelBank} from './levelbank.js'; +import {withTempFile} from './fs.js'; +import {test, expect} from 'vitest'; const sampleAccounts: Account[] = [ 'FR12345678901234', @@ -116,83 +117,78 @@ const levelBankMatchFakeBank = return true; }; -describe('Bank Simulator', () => { - test('level-db bank conforms to model', async () => { - const prop = forall(genAccounts, async accounts => { - return property(genOperations(accounts), async ops => { - const levelBank = await withTempFile( - filename => new LevelBank(filename), - ).then(bank => bank.populateWith(accounts)); +test('level-db bank conforms to model', async () => { + const prop = forall(genAccounts, async accounts => { + return property(genOperations(accounts), async ops => { + const levelBank = await withTempFile( + filename => new LevelBank(filename), + ).then(bank => bank.populateWith(accounts)); - return bankImplementationMatchesModel(accounts)(levelBank)(ops); - }); + return bankImplementationMatchesModel(accounts)(levelBank)(ops); }); + }); - const result = await Property.run(prop); + const result = await Property.run(prop); - console.log(result); - console.log(JSON.stringify(result.counterexample)); + console.log(result); + console.log(JSON.stringify(result.counterexample)); - expect(result.result).toBe('OK'); - }); + expect(result.result).toBe('OK'); +}); - // - // - // - // - // - // +// +// +// +// +// +// - test('in-mem bank conforms to model', async () => { - const prop = forall(genAccounts, async accounts => { - return property(genOperations(accounts), async ops => { - const simpleBank = new SimpleBank(accounts); +test('in-mem bank conforms to model', async () => { + const prop = forall(genAccounts, async accounts => { + return property(genOperations(accounts), async ops => { + const simpleBank = new SimpleBank(accounts); - return bankImplementationMatchesModel(accounts)(simpleBank)(ops); - }); + return bankImplementationMatchesModel(accounts)(simpleBank)(ops); }); + }); - const result = await Property.run(prop); + const result = await Property.run(prop); - console.log(result); - console.log(JSON.stringify(result.counterexample)); + console.log(result); + console.log(JSON.stringify(result.counterexample)); - expect(result.result).toBe('OK'); - }); + expect(result.result).toBe('OK'); +}); - // - // - // - // - // - // +// +// +// +// +// +// - test('can retrieve balance given account exists', async () => { - const prop = forall(genAccounts, async accounts => { - const api = new SimpleBank(accounts); - return property(keyValueOf(accounts), async ([accountNr, bal]) => { - const retrieved = toNullable(await api.balance(accountNr)); - return Promise.resolve(retrieved === bal); - }); +test('can retrieve balance given account exists', async () => { + const prop = forall(genAccounts, async accounts => { + const api = new SimpleBank(accounts); + return property(keyValueOf(accounts), async ([accountNr, bal]) => { + const retrieved = toNullable(await api.balance(accountNr)); + return Promise.resolve(retrieved === bal); }); - - const result = await Property.run(prop); - - expect(result.result).toBe('OK'); }); - test('correctly update balance given a sequence of deposits and withdrawals', async () => { - const prop = forall(genAccounts, accounts => { - return property( - genOperations(accounts), - levelBankMatchFakeBank(accounts), - ); - }); + const result = await Property.run(prop); - const result = await Property.run(prop); + expect(result.result).toBe('OK'); +}); - console.log(result); - console.log(JSON.stringify(result.counterexample)); - expect(result.result).toBe('OK'); +test('correctly update balance given a sequence of deposits and withdrawals', async () => { + const prop = forall(genAccounts, accounts => { + return property(genOperations(accounts), levelBankMatchFakeBank(accounts)); }); + + const result = await Property.run(prop); + + console.log(result); + console.log(JSON.stringify(result.counterexample)); + expect(result.result).toBe('OK'); }); diff --git a/pbt/ts/src/bank.ts b/pbt/ts/src/bank.ts index 6a220dc..f46465f 100644 --- a/pbt/ts/src/bank.ts +++ b/pbt/ts/src/bank.ts @@ -19,7 +19,7 @@ /// 3. Developing a mini-quickcheck from a "concrete" use case /// -import {Option, fromNullable, matchW, toNullable} from 'fp-ts/lib/Option'; +import {Option, fromNullable, matchW, toNullable} from 'fp-ts/lib/Option.js'; // keep it simple export type Account = string; diff --git a/pbt/ts/src/fs.ts b/pbt/ts/src/fs.ts index 133c8fd..716b8ac 100644 --- a/pbt/ts/src/fs.ts +++ b/pbt/ts/src/fs.ts @@ -1,7 +1,7 @@ import {mkdtemp, realpath} from 'fs/promises'; import {tmpdir} from 'os'; -import path = require('path'); -import fs = require('fs'); +import * as path from 'path'; +import * as fs from 'fs'; export const withTempFile = <A>(fn: (filepath: string) => A) => withTempDir(dir => fn(path.join(dir, 'file'))); diff --git a/pbt/ts/src/index.test.ts b/pbt/ts/src/index.test.ts index 675f683..7c4fd61 100644 --- a/pbt/ts/src/index.test.ts +++ b/pbt/ts/src/index.test.ts @@ -1,8 +1,8 @@ import { prop_reverse_is_self_inverse, prop_reverse_with_two_lists, -} from './index'; -import {Property, classify} from './property'; +} from './index.js'; +import {Property, classify} from './property.js'; describe('testing lists reversal', () => { test('reverse of two appended lists is append of each list reversed', async () => { diff --git a/pbt/ts/src/index.ts b/pbt/ts/src/index.ts index 7a58ffe..ed9bf6a 100644 --- a/pbt/ts/src/index.ts +++ b/pbt/ts/src/index.ts @@ -1,6 +1,6 @@ import 'dotenv/config'; import Prando from 'prando'; -import {Gen, listOf, property, shrinklist, someInt} from './property'; +import {Gen, listOf, property, shrinklist, someInt} from './property.js'; function arrayEquals<A>(a: A[], b: A[]): boolean { return ( diff --git a/pbt/ts/src/levelbank.ts b/pbt/ts/src/levelbank.ts index 0ea9525..298e8ad 100644 --- a/pbt/ts/src/levelbank.ts +++ b/pbt/ts/src/levelbank.ts @@ -1,8 +1,8 @@ // Specify types of keys and values (any, in the case of json). import {Level} from 'level'; -import {Account, Bank} from './bank'; -import {Option, fromNullable} from 'fp-ts/lib/Option'; +import {Account, Bank} from './bank.js'; +import {Option, fromNullable} from 'fp-ts/lib/Option.js'; export class LevelBank implements Bank { db: Level<string, number>; diff --git a/pbt/ts/src/property.test.ts b/pbt/ts/src/property.test.ts index 67ea81d..c47c964 100644 --- a/pbt/ts/src/property.test.ts +++ b/pbt/ts/src/property.test.ts @@ -4,7 +4,7 @@ import { property, shrinkPair, shrinkPositive, -} from './property'; +} from './property.js'; // from https://github.com/jlink/shrinking-challenge/blob/main/challenges/difference.md const predicate1: (pair: [number, number]) => Promise<boolean> = ([x, y]) => @@ -29,7 +29,7 @@ describe('Find minimal counterexample', () => { if (result.counterexample !== null) { expect(result.counterexample.counterexample).toStrictEqual([10, 10]); } else { - fail('no counterexample'); + expect.fail('no counterexample'); } }); }); diff --git a/pbt/ts/src/property.ts b/pbt/ts/src/property.ts index ea7a62b..f67abb4 100644 --- a/pbt/ts/src/property.ts +++ b/pbt/ts/src/property.ts @@ -1,5 +1,5 @@ -import {Option, getOrElse, isSome, none, some} from 'fp-ts/lib/Option'; -import {LazyArg, pipe} from 'fp-ts/lib/function'; +import {Option, getOrElse, isSome, none, some} from 'fp-ts/lib/Option.js'; +import {LazyArg, pipe} from 'fp-ts/lib/function.js'; import Prando from 'prando'; type Result = 'OK' | 'Falsified' | 'Exception'; |
