Skip to content

Commit

Permalink
chore: migrate to yakumo v1 & node:test
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Dec 12, 2023
1 parent 85e9977 commit 76cda56
Show file tree
Hide file tree
Showing 19 changed files with 76 additions and 59 deletions.
20 changes: 7 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,26 @@
"bump": "yakumo version",
"dep": "yakumo upgrade",
"pub": "yakumo publish",
"test": "yakumo mocha -r esbuild-register core",
"test": "yakumo test -r esbuild-register core",
"test:json": "shx rm -rf coverage && c8 -r json yarn test",
"test:html": "shx rm -rf coverage && c8 -r html yarn test",
"test:text": "shx rm -rf coverage && c8 -r text yarn test"
},
"devDependencies": {
"@types/chai": "^4.3.9",
"@types/mocha": "^9.1.1",
"@types/node": "^20.8.9",
"@types/chai": "^4.3.11",
"@types/node": "^20.10.2",
"c8": "^7.14.0",
"chai": "^4.3.10",
"element-plus": "2.4.0",
"esbuild": "^0.18.20",
"esbuild-register": "^3.5.0",
"marked-vue": "^1.2.3",
"mocha": "^9.2.2",
"serve": "^13.0.4",
"shx": "^0.3.4",
"typescript": "^5.2.2",
"typescript": "^5.3.2",
"vitepress": "1.0.0-rc.24",
"yakumo": "^0.3.13",
"yakumo-esbuild": "^0.3.26",
"yakumo-mocha": "^0.3.1",
"yakumo-publish": "^0.3.5",
"yakumo-tsc": "^0.3.12",
"yakumo-upgrade": "^0.3.4",
"yakumo-version": "^0.3.4"
"yakumo": "^1.0.0-alpha.3",
"yakumo-esbuild": "^1.0.0-alpha.0",
"yakumo-tsc": "^1.0.0-alpha.1"
}
}
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "schemastery",
"description": "Type driven schema validator",
"version": "3.14.1",
"version": "3.14.2",
"main": "lib/index.cjs",
"module": "lib/index.mjs",
"typings": "lib/index.d.ts",
Expand Down
5 changes: 3 additions & 2 deletions packages/core/tests/array.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { describe, test } from 'node:test'
import { expect } from 'chai'
import Schema from 'schemastery'

describe('Array', () => {
it('array', () => {
test('array', () => {
const Config = Schema.array(String)
expect(Config.toString()).to.equal('string[]')

Expand All @@ -17,7 +18,7 @@ describe('Array', () => {
expect(() => new Config([0])).to.throw()
})

it('array (length)', () => {
test('array (length)', () => {
const Config = Schema.array(String).min(2).max(3)

expect(new Config(['dress', 'skirt'])).to.deep.equal(['dress', 'skirt'])
Expand Down
7 changes: 4 additions & 3 deletions packages/core/tests/bitset.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { describe, test } from 'node:test'
import { expect } from 'chai'
import Schema from 'schemastery'

describe('Bitset', () => {
it('basic usage', () => {
test('basic usage', () => {
const validate = Schema.bitset({ a: 1, b: 2, c: 4 })

expect(validate()).to.equal(0)
Expand All @@ -17,7 +18,7 @@ describe('Bitset', () => {
expect(() => validate('a')).to.throw()
})

it('enumeration support', () => {
test('enumeration support', () => {
enum Foo {
a = 1,
b = 2,
Expand All @@ -34,7 +35,7 @@ describe('Bitset', () => {
expect(() => validate('a')).to.throw()
})

it('transform', () => {
test('transform', () => {
const validate = Schema.object({
foo: Schema.bitset({ a: 1, b: 2, c: 4 }),
})
Expand Down
3 changes: 2 additions & 1 deletion packages/core/tests/date.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { describe, test } from 'node:test'
import { expect } from 'chai'
import Schema from 'schemastery'

describe('Date', () => {
it('date', () => {
test('date', () => {
const Config = Schema.object({
date: Schema.date(),
})
Expand Down
5 changes: 3 additions & 2 deletions packages/core/tests/dict.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { describe, test } from 'node:test'
import { expect } from 'chai'
import Schema from 'schemastery'

describe('Dictionary', () => {
it('dict (basic)', () => {
test('dict (basic)', () => {
const Config = Schema.dict(RegExp)
expect(Config.toString()).to.equal('{ [key: string]: RegExp }')

Expand All @@ -19,7 +20,7 @@ describe('Dictionary', () => {
expect(() => new Config({ a: '' })).to.throw()
})

it('dict (key schema)', () => {
test('dict (key schema)', () => {
const validate = Schema.dict(Number, Schema.union([
'foo' as const,
Schema.transform('bar' as const, () => 'foo' as const),
Expand Down
3 changes: 2 additions & 1 deletion packages/core/tests/i18n.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { describe, test } from 'node:test'
import { expect } from 'chai'
import Schema from 'schemastery'

describe('I18n', () => {
it('basic support', () => {
test('basic support', () => {
const schema = Schema.intersect([
Schema.object({
enabled: Schema.boolean().default(false),
Expand Down
17 changes: 9 additions & 8 deletions packages/core/tests/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
import { describe, test } from 'node:test'
import { expect } from 'chai'
import Schema from 'schemastery'

describe('Schema API', () => {
it('unknown', () => {
test('unknown', () => {
const validate1 = new Schema({ type: 'unknown' })
expect(() => validate1(0)).to.throw()

expect(() => Schema.array(Symbol('unknown'))).to.throw()
})

it('any', () => {
test('any', () => {
const config = Schema.any()
expect(config.toString()).to.equal('any')

expect(config(123)).to.equal(123)
expect(config(null)).to.equal(null)
})

it('never', () => {
test('never', () => {
const config = Schema.never()
expect(config.toString()).to.equal('never')

Expand All @@ -26,7 +27,7 @@ describe('Schema API', () => {
expect(() => config(123)).to.throw()
})

it('number', () => {
test('number', () => {
const config = Schema.number().min(1).step(2).default(123)
expect(config.toString()).to.equal('number')

Expand All @@ -39,7 +40,7 @@ describe('Schema API', () => {
expect(() => config(456)).to.throw()
})

it('boolean', () => {
test('boolean', () => {
const config = Schema.boolean().default(true)
expect(config.toString()).to.equal('boolean')

Expand All @@ -51,7 +52,7 @@ describe('Schema API', () => {
expect(() => config(1)).to.throw()
})

it('function', () => {
test('function', () => {
const config = Schema.function()
expect(config.toString()).to.equal('function')

Expand All @@ -62,7 +63,7 @@ describe('Schema API', () => {
expect(() => config(1)).to.throw()
})

it('is', () => {
test('is', () => {
const config = Schema.is(RegExp)
expect(config.toString()).to.equal('RegExp')

Expand All @@ -74,7 +75,7 @@ describe('Schema API', () => {
expect(() => config('1')).to.throw()
})

it('loose', () => {
test('loose', () => {
const config = Schema.object({
foo: Schema.union([1, 2, 3]).loose().default(1),
bar: Schema.union([1, 2, 3]),
Expand Down
13 changes: 7 additions & 6 deletions packages/core/tests/intersect.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { describe, test } from 'node:test'
import { expect } from 'chai'
import Schema from 'schemastery'

describe('Intersect', () => {
it('intersect (primitive 1)', () => {
test('intersect (primitive 1)', () => {
const validate = Schema.intersect([String, Number])
expect(validate.toString()).to.equal('string & number')

Expand All @@ -13,7 +14,7 @@ describe('Intersect', () => {
expect(() => validate(123)).to.throw()
})

it('intersect (primitive 2)', () => {
test('intersect (primitive 2)', () => {
const validate = Schema.intersect([String, 'foo'])
expect(validate.toString()).to.equal('string & "foo"')

Expand All @@ -23,7 +24,7 @@ describe('Intersect', () => {
expect(() => validate('bar')).to.throw()
})

it('intersect (object)', () => {
test('intersect (object)', () => {
const validate = Schema.intersect([
Schema.object({ a: Schema.string().default('foo') }),
Schema.object({ b: Schema.number().required() }),
Expand All @@ -38,7 +39,7 @@ describe('Intersect', () => {
expect(() => validate({ b: '' })).to.throw()
})

it('intersect (nested)', () => {
test('intersect (nested)', () => {
const validate = Schema.intersect([
Schema.intersect([
Schema.object({ a: Schema.string() }),
Expand All @@ -57,7 +58,7 @@ describe('Intersect', () => {
expect(() => validate({ c: '' })).to.throw()
})

it('intersect (tagged union)', () => {
test('intersect (tagged union)', () => {
// https://github.com/shigma/schemastery/issues/31
const validate = Schema.intersect([
Schema.object({ e: Schema.boolean().default(true) }),
Expand All @@ -76,7 +77,7 @@ describe('Intersect', () => {
expect(validate(null)).to.deep.equal({ e: true, x: 114 })
})

it('intersect (shared default)', () => {
test('intersect (shared default)', () => {
// https://github.com/shigma/schemastery/issues/45
const validate = Schema.intersect([
Schema.object({
Expand Down
5 changes: 3 additions & 2 deletions packages/core/tests/misc.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { describe, test } from 'node:test'
import { expect } from 'chai'
import Schema from 'schemastery'

describe('Miscellaneous', () => {
it('serialization (basic)', () => {
test('serialization (basic)', () => {
const Number = Schema.number()
const validate = new Schema(JSON.parse(JSON.stringify(Number)))

Expand All @@ -11,7 +12,7 @@ describe('Miscellaneous', () => {
expect(() => validate('0')).to.throw()
})

it('serialization (recursive)', () => {
test('serialization (recursive)', () => {
const Node = Schema.object({ id: Number })
Node.set('children', Schema.array(Node))
const validate = new Schema(JSON.parse(JSON.stringify(Node)))
Expand Down
7 changes: 4 additions & 3 deletions packages/core/tests/number.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { describe, test } from 'node:test'
import { expect } from 'chai'
import Schema from 'schemastery'

describe('Number', () => {
it('number', () => {
test('number', () => {
const config = Schema.number().default(42)
expect(config.toString()).to.equal('number')

Expand All @@ -14,7 +15,7 @@ describe('Number', () => {
expect(() => config('42')).to.throw()
})

it('number (range)', () => {
test('number (range)', () => {
// https://github.com/shigma/schemastery/issues/44
const config = Schema.number().min(1).max(3).step(0.1)
expect(config(1)).to.equal(1)
Expand All @@ -25,7 +26,7 @@ describe('Number', () => {
expect(() => config(2.718)).to.throw()
})

it('number (decimal)', () => {
test('number (decimal)', () => {
// https://github.com/shigma/schemastery/issues/44
const config = Schema.number().min(-1).max(0).step(0.01)
expect(config(-0.55)).to.equal(-0.55)
Expand Down
3 changes: 2 additions & 1 deletion packages/core/tests/object.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { describe, test } from 'node:test'
import { expect } from 'chai'
import Schema from 'schemastery'

describe('Object', () => {
it('basic support', () => {
test('basic support', () => {
const Config = Schema.object({
a: Schema.string().required(),
b: Schema.number().default(123),
Expand Down
3 changes: 2 additions & 1 deletion packages/core/tests/simplify.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { describe, test } from 'node:test'
import { expect } from 'chai'
import Schema from 'schemastery'

describe('Simplify', () => {
it('basic support', () => {
test('basic support', () => {
const schema = Schema.intersect([
Schema.object({
a: Schema.string().default('a'),
Expand Down
7 changes: 4 additions & 3 deletions packages/core/tests/string.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { describe, test } from 'node:test'
import { expect } from 'chai'
import Schema from 'schemastery'

describe('String', () => {
it('string', () => {
test('string', () => {
const config = Schema.string().default('bar')
expect(config.toString()).to.equal('string')

Expand All @@ -14,15 +15,15 @@ describe('String', () => {
expect(() => config(123)).to.throw()
})

it('string (length)', () => {
test('string (length)', () => {
const config = Schema.string().min(5).max(6)
expect(config('dress')).to.equal('dress')

expect(() => config('sock')).to.throw()
expect(() => config('uniform')).to.throw()
})

it('string (pattern)', () => {
test('string (pattern)', () => {
const config = Schema.string().pattern(/^[a-z]+$/i)
expect(config('dress')).to.equal('dress')
expect(config('SKIRT')).to.equal('SKIRT')
Expand Down

0 comments on commit 76cda56

Please sign in to comment.