test: migrate to vitest

This commit is contained in:
Jeroen Claassens 2023-01-23 23:12:03 +01:00
parent 04295e51ef
commit 982198d24f
No known key found for this signature in database
GPG Key ID: 99BA590FEB09D9A8
10 changed files with 301 additions and 286 deletions

View File

@ -1,4 +0,0 @@
module.exports = {
testEnvironment: 'node',
testMatch: ['<rootDir>/test/*.test.(ts|js)']
}

View File

@ -32,7 +32,7 @@
"dev:cjs": "rollup -w -c scripts/configs.js --environment TARGET:commonjs-full",
"dev:esm": "rollup -w -c scripts/configs.js --environment TARGET:esm-dev-full",
"build": "rm -r dist && mkdir dist && node ./scripts/build.main.js",
"test": "jest",
"test": "vitest run",
"lint": "eslint src scripts test",
"release": "./scripts/release.sh",
"docs:bump": "node ./scripts/bump-docs.js",
@ -58,45 +58,41 @@
]
},
"devDependencies": {
"@babel/cli": "^7.2.3",
"@babel/core": "^7.3.4",
"@babel/eslint-parser": "^7.16.3",
"@babel/plugin-proposal-object-rest-spread": "7.16.0",
"@babel/preset-env": "7.16.0",
"@babel/preset-typescript": "7.16.0",
"@commitlint/cli": "^14.1.0",
"@commitlint/config-conventional": "^14.1.0",
"@rollup/plugin-babel": "^5.3.0",
"@rollup/plugin-node-resolve": "^13.0.6",
"@rollup/plugin-replace": "^3.0.0",
"@types/jest": "27.0.2",
"@vuepress/plugin-google-analytics": "^1.4.0",
"@vuepress/plugin-register-components": "^1.5.2",
"babel-loader": "^8.0.5",
"@babel/cli": "^7.20.7",
"@babel/core": "^7.20.12",
"@babel/eslint-parser": "^7.19.1",
"@babel/plugin-proposal-object-rest-spread": "7.20.7",
"@babel/preset-env": "7.20.2",
"@babel/preset-typescript": "7.18.6",
"@commitlint/cli": "^17.4.2",
"@commitlint/config-conventional": "^17.4.2",
"@rollup/plugin-babel": "^6.0.3",
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-replace": "^5.0.2",
"@vuepress/plugin-google-analytics": "^1.9.8",
"@vuepress/plugin-register-components": "^1.9.8",
"babel-loader": "^9.1.2",
"codemirror": "5.63.3",
"eslint": "8.2.0",
"eslint-config-prettier": "8.3.0",
"eslint": "8.32.0",
"eslint-config-prettier": "8.6.0",
"eslint-plugin-vue": "8.0.3",
"faker": "5.5.3",
"husky": "^7.0.0",
"jest": "^27.3.1",
"prettier": "2.4.1",
"replace-in-file": "^6.1.0",
"rimraf": "3.0.2",
"husky": "^8.0.3",
"prettier": "2.8.3",
"replace-in-file": "^6.3.5",
"rollup": "^2.61.1",
"rollup-plugin-copy": "3.4.0",
"standard-version": "^9.3.2",
"terser-webpack-plugin": "5.2.5",
"standard-version": "^9.5.0",
"terser": "^5.16.1",
"typescript": "^4.4.4",
"vitest": "^0.28.1",
"vue-codemirror": "^4.0.6",
"vue-eslint-parser": "^8.0.1",
"vuepress": "^1.4.0",
"vuepress-plugin-element-tabs": "^0.2.8",
"vuepress-plugin-google-adsense": "^0.2.1",
"vuepress-plugin-smooth-scroll": "^0.0.10",
"vuepress-plugin-social-share": "^1.1.0",
"webpack": "4.46.0",
"webpack-cli": "^4.9.1"
"vuepress-plugin-social-share": "^1.1.0"
},
"engines": {
"node": ">=10"

7
src/tsconfig.json Normal file
View File

@ -0,0 +1,7 @@
{
"extends": "../tsconfig.base.json",
"compilerOptions": {
"declarationDir": "../dist"
},
"include": ["."]
}

View File

@ -1,19 +1,19 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1
exports[`Searching using extended search Search: all 1`] = `
Array [
Object {
"item": Object {
exports[`Searching using extended search > Search: all 1`] = `
[
{
"item": {
"text": "smithee",
},
"matches": Array [
Object {
"indices": Array [
Array [
"matches": [
{
"indices": [
[
0,
6,
],
Array [
[
0,
6,
],
@ -25,18 +25,18 @@ Array [
"refIndex": 4,
"score": 2.220446049250313e-16,
},
Object {
"item": Object {
{
"item": {
"text": "smith",
},
"matches": Array [
Object {
"indices": Array [
Array [
"matches": [
{
"indices": [
[
0,
4,
],
Array [
[
0,
4,
],
@ -48,18 +48,18 @@ Array [
"refIndex": 5,
"score": 2.220446049250313e-16,
},
Object {
"item": Object {
{
"item": {
"text": "hello word",
},
"matches": Array [
Object {
"indices": Array [
Array [
"matches": [
{
"indices": [
[
0,
9,
],
Array [
[
0,
9,
],
@ -71,18 +71,18 @@ Array [
"refIndex": 0,
"score": 8.569061098350962e-12,
},
Object {
"item": Object {
{
"item": {
"text": "I am fine",
},
"matches": Array [
Object {
"indices": Array [
Array [
"matches": [
{
"indices": [
[
0,
8,
],
Array [
[
0,
8,
],
@ -97,16 +97,16 @@ Array [
]
`;
exports[`Searching using extended search Search: exact-match 1`] = `
Array [
Object {
"item": Object {
exports[`Searching using extended search > Search: exact-match 1`] = `
[
{
"item": {
"text": "smith",
},
"matches": Array [
Object {
"indices": Array [
Array [
"matches": [
{
"indices": [
[
0,
4,
],
@ -121,16 +121,16 @@ Array [
]
`;
exports[`Searching using extended search Search: include-match 1`] = `
Array [
Object {
"item": Object {
exports[`Searching using extended search > Search: include-match 1`] = `
[
{
"item": {
"text": "hello word",
},
"matches": Array [
Object {
"indices": Array [
Array [
"matches": [
{
"indices": [
[
0,
4,
],
@ -142,14 +142,14 @@ Array [
"refIndex": 0,
"score": 8.569061098350962e-12,
},
Object {
"item": Object {
{
"item": {
"text": "indeed fine hello foo",
},
"matches": Array [
Object {
"indices": Array [
Array [
"matches": [
{
"indices": [
[
12,
16,
],
@ -164,16 +164,16 @@ Array [
]
`;
exports[`Searching using extended search Search: inverse-exact-match 1`] = `
Array [
Object {
"item": Object {
exports[`Searching using extended search > Search: inverse-exact-match 1`] = `
[
{
"item": {
"text": "smithee",
},
"matches": Array [
Object {
"indices": Array [
Array [
"matches": [
{
"indices": [
[
0,
6,
],
@ -185,14 +185,14 @@ Array [
"refIndex": 4,
"score": 2.220446049250313e-16,
},
Object {
"item": Object {
{
"item": {
"text": "smith",
},
"matches": Array [
Object {
"indices": Array [
Array [
"matches": [
{
"indices": [
[
0,
4,
],
@ -204,14 +204,14 @@ Array [
"refIndex": 5,
"score": 2.220446049250313e-16,
},
Object {
"item": Object {
{
"item": {
"text": "hello word",
},
"matches": Array [
Object {
"indices": Array [
Array [
"matches": [
{
"indices": [
[
0,
9,
],
@ -223,14 +223,14 @@ Array [
"refIndex": 0,
"score": 8.569061098350962e-12,
},
Object {
"item": Object {
{
"item": {
"text": "how are you",
},
"matches": Array [
Object {
"indices": Array [
Array [
"matches": [
{
"indices": [
[
0,
10,
],
@ -242,14 +242,14 @@ Array [
"refIndex": 1,
"score": 9.287439764962262e-10,
},
Object {
"item": Object {
{
"item": {
"text": "I am fine",
},
"matches": Array [
Object {
"indices": Array [
Array [
"matches": [
{
"indices": [
[
0,
8,
],
@ -264,16 +264,16 @@ Array [
]
`;
exports[`Searching using extended search Search: inverse-prefix-exact-match 1`] = `
Array [
Object {
"item": Object {
exports[`Searching using extended search > Search: inverse-prefix-exact-match 1`] = `
[
{
"item": {
"text": "smithee",
},
"matches": Array [
Object {
"indices": Array [
Array [
"matches": [
{
"indices": [
[
0,
6,
],
@ -285,14 +285,14 @@ Array [
"refIndex": 4,
"score": 2.220446049250313e-16,
},
Object {
"item": Object {
{
"item": {
"text": "smith",
},
"matches": Array [
Object {
"indices": Array [
Array [
"matches": [
{
"indices": [
[
0,
4,
],
@ -304,14 +304,14 @@ Array [
"refIndex": 5,
"score": 2.220446049250313e-16,
},
Object {
"item": Object {
{
"item": {
"text": "how are you",
},
"matches": Array [
Object {
"indices": Array [
Array [
"matches": [
{
"indices": [
[
0,
10,
],
@ -323,14 +323,14 @@ Array [
"refIndex": 1,
"score": 9.287439764962262e-10,
},
Object {
"item": Object {
{
"item": {
"text": "I am fine",
},
"matches": Array [
Object {
"indices": Array [
Array [
"matches": [
{
"indices": [
[
0,
8,
],
@ -342,14 +342,14 @@ Array [
"refIndex": 3,
"score": 9.287439764962262e-10,
},
Object {
"item": Object {
{
"item": {
"text": "indeed fine hello foo",
},
"matches": Array [
Object {
"indices": Array [
Array [
"matches": [
{
"indices": [
[
0,
20,
],
@ -364,16 +364,16 @@ Array [
]
`;
exports[`Searching using extended search Search: inverse-suffix-exact-match 1`] = `
Array [
Object {
"item": Object {
exports[`Searching using extended search > Search: inverse-suffix-exact-match 1`] = `
[
{
"item": {
"text": "smithee",
},
"matches": Array [
Object {
"indices": Array [
Array [
"matches": [
{
"indices": [
[
0,
6,
],
@ -385,14 +385,14 @@ Array [
"refIndex": 4,
"score": 2.220446049250313e-16,
},
Object {
"item": Object {
{
"item": {
"text": "smith",
},
"matches": Array [
Object {
"indices": Array [
Array [
"matches": [
{
"indices": [
[
0,
4,
],
@ -404,14 +404,14 @@ Array [
"refIndex": 5,
"score": 2.220446049250313e-16,
},
Object {
"item": Object {
{
"item": {
"text": "hello word",
},
"matches": Array [
Object {
"indices": Array [
Array [
"matches": [
{
"indices": [
[
0,
9,
],
@ -423,14 +423,14 @@ Array [
"refIndex": 0,
"score": 8.569061098350962e-12,
},
Object {
"item": Object {
{
"item": {
"text": "how are you",
},
"matches": Array [
Object {
"indices": Array [
Array [
"matches": [
{
"indices": [
[
0,
10,
],
@ -442,14 +442,14 @@ Array [
"refIndex": 1,
"score": 9.287439764962262e-10,
},
Object {
"item": Object {
{
"item": {
"text": "I am fine",
},
"matches": Array [
Object {
"indices": Array [
Array [
"matches": [
{
"indices": [
[
0,
8,
],
@ -464,20 +464,20 @@ Array [
]
`;
exports[`Searching using extended search Search: literal match with fuzzy match 1`] = `
Array [
Object {
"item": Object {
exports[`Searching using extended search > Search: literal match with fuzzy match 1`] = `
[
{
"item": {
"text": "indeed fine hello foo",
},
"matches": Array [
Object {
"indices": Array [
Array [
"matches": [
{
"indices": [
[
0,
10,
],
Array [
[
18,
20,
],
@ -489,14 +489,14 @@ Array [
"refIndex": 2,
"score": 1.4901161193847656e-8,
},
Object {
"item": Object {
{
"item": {
"text": "hello word",
},
"matches": Array [
Object {
"indices": Array [
Array [
"matches": [
{
"indices": [
[
0,
4,
],
@ -511,16 +511,16 @@ Array [
]
`;
exports[`Searching using extended search Search: literal match with regular match 1`] = `
Array [
Object {
"item": Object {
exports[`Searching using extended search > Search: literal match with regular match 1`] = `
[
{
"item": {
"text": "how are you",
},
"matches": Array [
Object {
"indices": Array [
Array [
"matches": [
{
"indices": [
[
4,
6,
],
@ -532,18 +532,18 @@ Array [
"refIndex": 1,
"score": 9.287439764962262e-10,
},
Object {
"item": Object {
{
"item": {
"text": "indeed fine hello foo",
},
"matches": Array [
Object {
"indices": Array [
Array [
"matches": [
{
"indices": [
[
0,
10,
],
Array [
[
18,
20,
],
@ -558,16 +558,16 @@ Array [
]
`;
exports[`Searching using extended search Search: prefix-exact-match 1`] = `
Array [
Object {
"item": Object {
exports[`Searching using extended search > Search: prefix-exact-match 1`] = `
[
{
"item": {
"text": "hello word",
},
"matches": Array [
Object {
"indices": Array [
Array [
"matches": [
{
"indices": [
[
0,
4,
],
@ -582,16 +582,16 @@ Array [
]
`;
exports[`Searching using extended search Search: single literal match 1`] = `
Array [
Object {
"item": Object {
exports[`Searching using extended search > Search: single literal match 1`] = `
[
{
"item": {
"text": "indeed fine hello foo",
},
"matches": Array [
Object {
"indices": Array [
Array [
"matches": [
{
"indices": [
[
0,
10,
],
@ -606,16 +606,16 @@ Array [
]
`;
exports[`Searching using extended search Search: suffix-exact-match 1`] = `
Array [
Object {
"item": Object {
exports[`Searching using extended search > Search: suffix-exact-match 1`] = `
[
{
"item": {
"text": "I am fine",
},
"matches": Array [
Object {
"indices": Array [
Array [
"matches": [
{
"indices": [
[
5,
8,
],

View File

@ -1,33 +1,33 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1
exports[`Ignore location and field length norm Check order of entries when location and field-length norm are ignored 1`] = `
Array [
Object {
exports[`Ignore location and field length norm > Check order of entries when location and field-length norm are ignored 1`] = `
[
{
"item": "Module with Promise-aware beforeEach",
"refIndex": 3,
"score": 0.09090909090909091,
},
Object {
{
"item": "Module with Promise-aware afterEach",
"refIndex": 5,
"score": 0.2727272727272727,
},
Object {
{
"item": "Promise-aware return values without beforeEach/afterEach",
"refIndex": 4,
"score": 0.4090909090909091,
},
Object {
{
"item": "async beforeEach test",
"refIndex": 1,
"score": 0.5,
},
Object {
{
"item": "assert.async in beforeEach",
"refIndex": 2,
"score": 0.5,
},
Object {
{
"item": "beforeEach",
"refIndex": 0,
"score": 0.5454545454545454,
@ -35,39 +35,39 @@ Array [
]
`;
exports[`Ignore location and field length norm Check order of entries when location and field-length norm are not ignored 1`] = `
Array [
Object {
exports[`Ignore location and field length norm > Check order of entries when location and field-length norm are not ignored 1`] = `
[
{
"item": "beforeEach",
"refIndex": 0,
"score": 0,
},
Object {
{
"item": "async beforeEach test",
"refIndex": 1,
"score": 0.1972392177586917,
},
Object {
{
"item": "before",
"refIndex": 6,
"score": 0.4,
},
Object {
{
"item": "assert.async in beforeEach",
"refIndex": 2,
"score": 0.4493775633055149,
},
Object {
{
"item": "before (skip)",
"refIndex": 7,
"score": 0.5231863610884103,
},
Object {
{
"item": "Module with Promise-aware beforeEach",
"refIndex": 3,
"score": 0.5916079783099616,
},
Object {
{
"item": "Promise-aware return values without beforeEach/afterEach",
"refIndex": 4,
"score": 0.699819425905295,

View File

@ -1,28 +1,28 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1
exports[`Logical parser Implicit operations 1`] = `
Object {
"children": Array [
Object {
exports[`Logical parser > Implicit operations 1`] = `
{
"children": [
{
"keyId": "title",
"pattern": "old war",
},
Object {
"children": Array [
Object {
"children": Array [
Object {
{
"children": [
{
"children": [
{
"keyId": "title",
"pattern": "!arts",
},
Object {
{
"keyId": "tags",
"pattern": "kiro",
},
],
"operator": "$and",
},
Object {
{
"keyId": "title",
"pattern": "^lock",
},
@ -34,20 +34,20 @@ Object {
}
`;
exports[`Logical parser Tree structure 1`] = `
Object {
"children": Array [
Object {
exports[`Logical parser > Tree structure 1`] = `
{
"children": [
{
"keyId": "title",
"pattern": "old war",
},
Object {
"children": Array [
Object {
{
"children": [
{
"keyId": "title",
"pattern": "!arts",
},
Object {
{
"keyId": "title",
"pattern": "^lock",
},

7
test/tsconfig.json Normal file
View File

@ -0,0 +1,7 @@
{
"extends": "../tsconfig.base.json",
"compilerOptions": {
"types": ["vitest/globals"]
},
"include": ["."]
}

View File

@ -2,7 +2,8 @@ import Fuse from '../dist/fuse'
import { BattlePokedex } from './fixtures/pokedex'
import { PokedexType } from './fixtures/types'
const idx = (result) => result.map((obj) => obj.refIndex)
const idx = (result: Fuse.FuseResult<Author>[]) =>
result.map((obj) => obj.refIndex)
const defaultOptions: Fuse.IFuseOptions<PokedexType> = {
keys: ['alias', 'species', 'name', 'num'],
@ -67,18 +68,13 @@ describe('Search results with indices', () => {
const matches = results[0].matches
expect(matches.length).toBe(1)
expect(matches[0].indices.length).toBe(9)
expect(matches[0].indices[0]).toMatchObject([0, 4])
expect(matches?.length).toBe(1)
expect(matches?.[0].indices.length).toBe(9)
expect(matches?.[0].indices[0]).toMatchObject([0, 4])
})
})
describe('Logical search results', () => {
interface Author {
readonly name: string
readonly title: string
}
const list: Array<Author> = [
{
title: 'The Code of the Wooster',
@ -103,3 +99,8 @@ describe('Logical search results', () => {
expect(idx(result)).toMatchObject([0])
})
})
interface Author {
readonly name: string
readonly title: string
}

View File

@ -8,8 +8,6 @@
"esModuleInterop": true,
"strict": true,
"declaration": true,
"noImplicitAny": true,
"declarationDir": "./dist"
},
"include": ["src/*", "src/**/*"]
"noImplicitAny": true
}
}

10
vitest.config.ts Normal file
View File

@ -0,0 +1,10 @@
import { defineConfig } from 'vitest/config'
export default defineConfig({
test: {
globals: true
},
esbuild: {
target: 'es2015'
}
})