Skip to content

Commit 13d24c7

Browse files
committed
Use vitest to run tests
1 parent 62aa526 commit 13d24c7

File tree

8 files changed

+306
-1840
lines changed

8 files changed

+306
-1840
lines changed

lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export * as schemas from './schemas'
1+
export { default as schemas } from '../schemas'
22
export { default as validator } from './validator'

lib/schemas.js

Lines changed: 0 additions & 19 deletions
This file was deleted.

lib/validator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Ajv from 'ajv'
22
import addFormats from 'ajv-formats'
3-
import * as schemas from './schemas'
3+
import schemas from '../schemas'
44

55
export default function (options = { allErrors: true, verbose: true }) {
66
const ajv = new Ajv({ schemas: Object.values(schemas) })

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,13 @@
2222
"ajv-formats": "^2.1.1"
2323
},
2424
"devDependencies": {
25-
"glob": "^9.3.2",
26-
"jest": "^29.5.0",
2725
"standard": "^17.0.0",
28-
"vite": "^4.2.1"
26+
"vite": "^4.2.1",
27+
"vitest": "^0.29.8"
2928
},
3029
"scripts": {
3130
"build": "vite build",
3231
"lint": "standard",
33-
"test": "yarn node --experimental-vm-modules $(yarn bin jest)"
32+
"test": "vitest"
3433
}
3534
}

schemas/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const modules = import.meta.glob('./*.json', { eager: true, import: 'default' })
2+
const schemas = Object.fromEntries(Object.entries(modules).map(([path, module]) => {
3+
const name = path.split('/').pop().split('.').shift();
4+
return [name == 'schema' ? 'default' : name, module];
5+
}));
6+
7+
export default schemas;

test/examples/index.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
import { globSync } from 'glob'
2-
import { readFileSync } from 'fs'
31
import { basename } from 'path'
42

5-
const pattern = new URL('./*.json', import.meta.url).pathname
3+
const modules = import.meta.glob("./*.json", { eager: true, import: 'default' })
64

7-
export default Object.fromEntries(globSync(pattern).map(file => {
8-
const contents = JSON.parse(readFileSync(file, 'utf8'))
9-
return [basename(file, '.json'), contents]
5+
export default Object.fromEntries(Object.entries(modules).map(([path, module]) => {
6+
return [basename(path, '.json'), module]
107
}))

test/schemas.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, test, expect } from '@jest/globals'
1+
import { describe, test, expect } from 'vitest'
22
import { validator } from '../lib'
33
import examples from './examples'
44

yarn.lock

Lines changed: 290 additions & 1808 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)