Skip to content

Commit

Permalink
feat(vitest): add vitest, aliasing, cleanup uvu deps
Browse files Browse the repository at this point in the history
  • Loading branch information
Danil Tarasov authored and norskeld committed Oct 8, 2022
1 parent 496f790 commit a4883a3
Show file tree
Hide file tree
Showing 65 changed files with 3,035 additions and 3,351 deletions.
14 changes: 0 additions & 14 deletions .nycrc

This file was deleted.

5,870 changes: 2,790 additions & 3,080 deletions package-lock.json

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@
"prerelease": "node --require tsm scripts/release.ts prepare",
"release": "npx semantic-release",
"release:dry": "npx semantic-release --dry-run",
"test": "uvu -r tsm src/__tests__",
"test:coverage": "nyc npm test",
"test:watch": "watchlist src tests --eager -- npm test"
"test": "vitest run",
"test:coverage": "vitest run --coverage",
"test:watch": "vitest"
},
"repository": {
"type": "git",
Expand All @@ -74,30 +74,30 @@
"homepage": "https://github.com/norskeld/sigma#readme",
"devDependencies": {
"@commitlint/cli": "^17.0.0",
"@istanbuljs/nyc-config-typescript": "^1.0.2",
"@nrsk/config-conventional": "^1.0.0",
"@rollup/plugin-typescript": "^8.3.2",
"@semantic-release/changelog": "^6.0.1",
"@semantic-release/git": "^10.0.1",
"@types/node": "^16.11.64",
"@typescript-eslint/eslint-plugin": "^5.22.0",
"@typescript-eslint/parser": "^5.22.0",
"@vitest/coverage-istanbul": "^0.24.0",
"eslint": "^8.16.0",
"eslint-config-prettier": "^8.5.0",
"eslint-import-resolver-typescript": "^2.7.1",
"eslint-plugin-import": "^2.26.0",
"husky": "^8.0.1",
"is-ci": "^3.0.1",
"lint-staged": "^12.4.1",
"nyc": "^15.1.0",
"prettier": "^2.6.2",
"rimraf": "^3.0.2",
"rollup": "^2.74.1",
"rollup-plugin-dts": "^4.2.1",
"rollup-plugin-tsconfig-paths": "^1.3.0",
"semantic-release": "^19.0.2",
"tsm": "^2.2.1",
"typescript": "^4.6.4",
"uvu": "^0.5.3",
"watchlist": "^0.3.1"
"typescript": "^4.8.4",
"vite-tsconfig-paths": "^3.5.1",
"vitest": "^0.24.0"
},
"commitlint": {
"extends": [
Expand Down
3 changes: 2 additions & 1 deletion scripts/compile.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import typescript from '@rollup/plugin-typescript'
import { rollup, InputOptions, OutputOptions } from 'rollup'
import dts from 'rollup-plugin-dts'
import tsConfigPaths from 'rollup-plugin-tsconfig-paths'

interface BundleOptions {
input: InputOptions
Expand Down Expand Up @@ -37,7 +38,7 @@ function createTypesBundleOptions(entry: string, destination: string): BundleOpt
return {
input: {
input: `${entry}.d.ts`,
plugins: [dts()]
plugins: [tsConfigPaths(), dts()]
},
output: [
{
Expand Down
29 changes: 12 additions & 17 deletions src/__tests__/@helpers/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { type Context, suite, uvu } from 'uvu'
import * as assert from 'uvu/assert'
import { expect } from 'vitest'

import { run as internal$run } from '../../parsers/run'
import type { Parser, Result } from '../../state'
import { run as internal$run } from '#parsers'
import type { Parser, Result } from '#state'

interface ReducedResult<T> {
isOk: boolean
Expand All @@ -17,37 +16,31 @@ export function result<T>(isOk: boolean, value: T): ReducedResult<T> {
return { isOk, value } as const
}

export function describe<T = Context>(name: string, f: (t: uvu.Test<T>) => void | Promise<void>) {
const test = suite<T>(name)
f(test)
test.run()
}

export const should = {
expose(exposed: Record<string, unknown>, ...exposees: Array<string>): void {
exposees.forEach((exposee) => assert.ok(exposed[exposee]))
exposees.forEach((exposee) => expect(exposed[exposee]).toBeTruthy())
},

matchState<T, R>(received: Result<T>, expected: ReducedResult<R>): void {
assert.equal(received.isOk, expected.isOk)
expect(received.isOk).toBe(expected.isOk)

switch (received.isOk) {
case true: {
return assert.equal(received.value, expected.value)
return expect(received.value).toStrictEqual(expected.value)
}

case false: {
return assert.equal(received.expected, expected.value)
return expect(received.expected).toStrictEqual(expected.value)
}
}
},

beEqual<T = unknown>(a: T, b: T, message?: string) {
assert.equal(a, b, message)
expect(a, message).toBe(b)
},

throw(f: typeof assert.throws) {
assert.throws(f)
throw(f: () => void) {
expect(f).toThrow()
}
}

Expand Down Expand Up @@ -107,3 +100,5 @@ export const expectedParsers = [
'whitespace',
'whole'
] as const

export { describe, expect, it } from 'vitest'
17 changes: 6 additions & 11 deletions src/__tests__/combinators.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import { suite } from 'uvu'
import * as exposed from '#combinators'
import { should, expectedCombinators, describe, it } from '#testing'

import * as exposed from '../combinators'

import { should, expectedCombinators } from './@helpers'

const it = suite('combinators exports')

it('should expose combinators', () => {
should.expose(exposed, ...expectedCombinators)
describe('combinators exports', () => {
it('should expose combinators', () => {
should.expose(exposed, ...expectedCombinators)
})
})

it.run()
11 changes: 4 additions & 7 deletions src/__tests__/combinators/chain.spec.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import { chainl } from '../../combinators/chain'
import { map } from '../../combinators/map'
import { takeRight } from '../../combinators/take'
import { regexp } from '../../parsers/regexp'
import { string } from '../../parsers/string'
import { run, result, should, describe } from '../@helpers'
import { chainl, map, takeRight } from '#combinators'
import { regexp, string } from '#parsers'
import { run, result, should, describe, it } from '#testing'

const toSum = (left: number, right: number) => left + right
const toNumber = (value: string) => parseInt(value, 10)

const number = map(regexp(/\d+/g, 'integer'), toNumber)
const parser = chainl(number, takeRight(string(' + '), number), toSum)

describe('chain', (it) => {
describe('chain', () => {
it('should succeed with eliminated left recursion and reduced to a value', () => {
const actual = run(parser, '2 + 2 + 4')
const expected = result(true, 8)
Expand Down
8 changes: 4 additions & 4 deletions src/__tests__/combinators/choice.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { choice } from '../../combinators/choice'
import { string } from '../../parsers/string'
import { run, result, should, describe } from '../@helpers'
import { choice } from '#combinators'
import { string } from '#parsers'
import { run, result, should, describe, it } from '#testing'

describe('choice', (it) => {
describe('choice', () => {
it('should succeed with the value of the first successful parser in sequence', () => {
const parser = choice(string('left'), string('mid'), string('right'))
const actual = run(parser, 'mid')
Expand Down
8 changes: 4 additions & 4 deletions src/__tests__/combinators/error.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { error } from '../../combinators/error'
import { string } from '../../parsers/string'
import { run, result, should, describe } from '../@helpers'
import { error } from '#combinators'
import { string } from '#parsers'
import { run, result, should, describe, it } from '#testing'

describe('error', (it) => {
describe('error', () => {
it('should successfully replace error message (expectation)', () => {
const parser = error(string('9000'), 'replaced-error-message')
const actual = run(parser, 'xxxx')
Expand Down
10 changes: 5 additions & 5 deletions src/__tests__/combinators/many.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { many, many1 } from '../../combinators/many'
import { string } from '../../parsers/string'
import { describe, result, run, should, testFailure } from '../@helpers'
import { many, many1 } from '#combinators'
import { string } from '#parsers'
import { describe, result, run, should, testFailure, it } from '#testing'

describe('many', (it) => {
describe('many', () => {
it('should succeed with an array of matched strings', () => {
const parser = many(string('x!'))
const actual = run(parser, 'x!x!x!')
Expand All @@ -19,7 +19,7 @@ describe('many', (it) => {
should.matchState(actual, expected)
})
})
describe('many1', (it) => {
describe('many1', () => {
it('should succeed with an array of matched strings', () => {
const parser = many1(string('x!'))
const actual = run(parser, 'x!x!x!')
Expand Down
10 changes: 5 additions & 5 deletions src/__tests__/combinators/map.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { map, mapTo } from '../../combinators/map'
import { string } from '../../parsers/string'
import { describe, result, run, should } from '../@helpers'
import { map, mapTo } from '#combinators'
import { string } from '#parsers'
import { describe, result, run, should, it } from '#testing'

describe('map', (it) => {
describe('map', () => {
it('should succeed if a single given parser succeeds', () => {
const parser = map(string('9000'), (value) => parseInt(value, 10))
const actual = run(parser, '9000')
Expand All @@ -20,7 +20,7 @@ describe('map', (it) => {
})
})

describe('mapTo', (it) => {
describe('mapTo', () => {
it('should succeed if a single given parser succeeds', () => {
const parser = mapTo(string('9000'), 'constant')
const actual = run(parser, '9000')
Expand Down
9 changes: 4 additions & 5 deletions src/__tests__/combinators/optional.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { optional } from '../../combinators/optional'
import { sequence } from '../../combinators/sequence'
import { string } from '../../parsers/string'
import { run, result, should, describe } from '../@helpers'
import { optional, sequence } from '#combinators'
import { string } from '#parsers'
import { run, result, should, describe, it } from '#testing'

describe('optional', (it) => {
describe('optional', () => {
it('should succeed with the where optional non-matched value replaced with null', () => {
const parser = sequence(string('Hello'), optional(string('...')))
const actual = run(parser, 'Hello')
Expand Down
10 changes: 5 additions & 5 deletions src/__tests__/combinators/sepBy.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { sepBy, sepBy1 } from '../../combinators/sepBy'
import { string } from '../../parsers/string'
import { run, result, should, describe } from '../@helpers'
import { sepBy, sepBy1 } from '#combinators'
import { string } from '#parsers'
import { run, result, should, describe, it } from '#testing'

describe('sepBy', (it) => {
describe('sepBy', () => {
it('should succeed with an array of matched strings without separator', () => {
const parser = sepBy(string('x'), string('!'))
const actual = run(parser, 'x!x!x!')
Expand All @@ -28,7 +28,7 @@ describe('sepBy', (it) => {
})
})

describe('sepBy1', (it) => {
describe('sepBy1', () => {
it('should succeed with an array of matched strings without separator', () => {
const parser = sepBy1(string('x'), string('!'))
const actual = run(parser, 'x!x!x!')
Expand Down
8 changes: 4 additions & 4 deletions src/__tests__/combinators/sequence.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { sequence } from '../../combinators/sequence'
import { string } from '../../parsers/string'
import { run, result, should, describe } from '../@helpers'
import { sequence } from '#combinators'
import { string } from '#parsers'
import { run, result, should, describe, it } from '#testing'

describe('sequence', (it) => {
describe('sequence', () => {
it('should succeed if a sequence of parsers succeeds', () => {
const parser = sequence(string('hello'), string(' '), string('world'))
const actual = run(parser, 'hello world')
Expand Down
14 changes: 7 additions & 7 deletions src/__tests__/combinators/take.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { takeLeft, takeMid, takeRight, takeSides } from '../../combinators/take'
import { string } from '../../parsers/string'
import { describe, result, run, should } from '../@helpers'
import { takeLeft, takeMid, takeRight, takeSides } from '#combinators'
import { string } from '#parsers'
import { describe, result, run, should, it } from '#testing'

describe('takeLeft', (it) => {
describe('takeLeft', () => {
it('should succeed with the value of the parser on the left-hand side', () => {
const parser = takeLeft(string('left'), string('mid'))
const actual = run(parser, 'leftmid')
Expand All @@ -20,7 +20,7 @@ describe('takeLeft', (it) => {
})
})

describe('takeMid', (it) => {
describe('takeMid', () => {
it('should succeed with the value of the parser in the middle', () => {
const parser = takeMid(string('left'), string('mid'), string('right'))
const actual = run(parser, 'leftmidright')
Expand All @@ -38,7 +38,7 @@ describe('takeMid', (it) => {
})
})

describe('takeRight', (it) => {
describe('takeRight', () => {
it('should succeed with the value of the parser on right-hand side', () => {
const parser = takeRight(string('mid'), string('right'))
const actual = run(parser, 'midright')
Expand All @@ -56,7 +56,7 @@ describe('takeRight', (it) => {
})
})

describe('takeSides', (it) => {
describe('takeSides', () => {
it('should succeed with the tuple of the first and the last values', () => {
const parser = takeSides(string('left'), string('mid'), string('right'))
const actual = run(parser, 'leftmidright')
Expand Down
13 changes: 5 additions & 8 deletions src/__tests__/combinators/until.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { map } from '../../combinators/map'
import { takeUntil, skipUntil } from '../../combinators/until'
import { any } from '../../parsers/any'
import { regexp } from '../../parsers/regexp'
import { string } from '../../parsers/string'
import { run, result, should, describe, testFailure } from '../@helpers'
import { map, takeUntil, skipUntil } from '#combinators'
import { any, regexp, string } from '#parsers'
import { run, result, should, describe, testFailure, it } from '#testing'

describe('takeUntil', (it) => {
describe('takeUntil', () => {
it('should succeed with a tuple of values if given a correct string', () => {
const parser = map(takeUntil(any(), string('*/')), (result) => result.flat().join(''))
const actual = run(parser, '/* Comment */')
Expand All @@ -19,7 +16,7 @@ describe('takeUntil', (it) => {
})
})

describe('skipUntil', (it) => {
describe('skipUntil', () => {
it('should succeed with a result of terminating parser if given a correct string', () => {
const parser = skipUntil(any(), string('*/'))
const actual = run(parser, '/* Comment */')
Expand Down
8 changes: 4 additions & 4 deletions src/__tests__/combinators/when.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { when } from '../../combinators/when'
import { string } from '../../parsers'
import { run, result, should, describe } from '../@helpers'
import { when } from '#combinators'
import { string } from '#parsers'
import { run, result, should, describe, it } from '#testing'

const parser = when(string('x'), () => string('y'))

describe('when', (it) => {
describe('when', () => {
it('should succeed with the value of chained parser', () => {
const actual = run(parser, 'xy')
const expected = result(true, 'y')
Expand Down
Loading

0 comments on commit a4883a3

Please sign in to comment.