Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
1694: Switch test runner from Jest to Vitest r=curquiza a=flevi29

# Pull Request

## Why?
  - faster, more efficient (unless abused, misused)
  - TS/ESM support out of the box
  - very little configuration required
  - watch mode included
  - works on the same concepts as Jest when it comes to writing tests, so minimal changes needed in test files
  - better maintained due to its simplicity and modern web orientation
  - trusted by popular and battle-tested packages [svelte](https://github.com/sveltejs/svelte), [Nuxt](https://github.com/nuxt/nuxt), ...
  - ESM oriented, future proof

I am also getting rid of `jsdom` tests, we were already skipping Node.js tests when using `jsdom` and everything else is based on web standards so there isn't really much of a benefit to `jsdom`. This halves the time tests are running for. I am also planning to parallelize some tests by using multiple indexes on Meilisearch to further speed up tests.

## PR checklist
Please check if your PR fulfills the following requirements:
- [x] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
- [x] Have you read the contributing guidelines?
- [x] Have you made sure that the title is accurate and descriptive of the changes?

Thank you so much for contributing to Meilisearch!


Co-authored-by: F. Levi <55688616+flevi29@users.noreply.github.com>
  • Loading branch information
meili-bors[bot] and flevi29 authored Oct 3, 2024
2 parents efbaa33 + 849cdc3 commit f4bbd5a
Show file tree
Hide file tree
Showing 45 changed files with 968 additions and 2,132 deletions.
82 changes: 0 additions & 82 deletions .eslintrc.js

This file was deleted.

23 changes: 7 additions & 16 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const eslint = require("@eslint/js");
const tseslint = require("typescript-eslint");
const tsdoc = require("eslint-plugin-tsdoc");
const jest = require("eslint-plugin-jest");
const vitest = require("@vitest/eslint-plugin");
const globals = require("globals");
const prettier = require("eslint-config-prettier");

Expand Down Expand Up @@ -59,25 +59,16 @@ module.exports = [
"@typescript-eslint/ban-ts-ignore": "off",
},
})),
// Jest linting for test files
// Vitest linting for test files
{
files: ["tests/*.ts"],
...jest.configs["flat/recommended"],
// languageOptions: {
// ...jest.configs['flat/recommended'].languageOptions,
// globals: globals.jest,
// },
plugins: { vitest },
rules: {
...jest.configs["flat/recommended"].rules,
...vitest.configs.recommended.rules,
// @TODO: Remove all of these rules and adapt code!
"jest/no-disabled-tests": "off",
"jest/expect-expect": "off",
"jest/no-conditional-expect": "off",
"jest/valid-title": "off",
"jest/no-jasmine-globals": "off",
"jest/valid-expect-in-promise": "off",
"jest/valid-expect": "off",
"jest/no-alias-methods": "off",
"vitest/expect-expect": "off",
"vitest/valid-title": "off",
"vitest/valid-expect": "off",
},
},
prettier,
Expand Down
21 changes: 8 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,18 @@
},
"scripts": {
"playground:javascript": "yarn --cwd ./playgrounds/javascript && yarn --cwd ./playgrounds/javascript start",
"clear_jest": "jest --clearCache",
"cleanup": "shx rm -rf dist/",
"build": "yarn cleanup && rollup -c && rollup -c --environment NODE_ENV:production",
"build:docs": "typedoc",
"watch": "yarn cleanup && rollup -c --watch",
"postbuild": "yarn size && yarn typingsheader",
"test": "yarn clear_jest && jest --runInBand --verbose",
"test": "vitest run --coverage",
"types:watch": "nodemon --config nodemon.json",
"types": "yarn tsc",
"test:env:browser": "yarn build && yarn --cwd tests/env/express && yarn --cwd tests/env/express test",
"test:watch": "yarn clear_jest && yarn test --watch",
"test:coverage": "yarn test --coverage",
"test:ci": "yarn test --ci",
"test:watch": "vitest watch",
"test:coverage": "yarn test",
"test:ci": "yarn test",
"test:env": "yarn build && yarn test:env:nodejs && yarn test:env:esm && yarn test:env:node-ts",
"test:env:node-ts": "yarn --cwd tests/env/typescript-node start",
"test:env:nodejs": "yarn build && node tests/env/node/index.js && node tests/env/node/getting_started.js",
Expand Down Expand Up @@ -81,18 +80,14 @@
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "15.3.0",
"@types/eslint__js": "^8.42.3",
"@types/jest": "^29.5.11",
"@vitest/coverage-v8": "2.0.5",
"@vitest/eslint-plugin": "^1.1.4",
"brotli-size": "^4.0.0",
"eslint": "^9.11.1",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-jest": "^28.8.0",
"eslint-plugin-tsdoc": "^0.3.0",
"globals": "^15.9.0",
"gzip-size": "^6.0.0",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"jest-fetch-mock": "^3.0.3",
"jest-watch-typeahead": "^2.2.2",
"kleur": "^4.1.5",
"lint-staged": "15.2.10",
"nodemon": "^3.1.7",
Expand All @@ -103,10 +98,10 @@
"rollup-plugin-terser": "^7.0.0",
"rollup-plugin-typescript2": "^0.36.0",
"shx": "^0.3.2",
"ts-jest": "^29.2.5",
"typedoc": "^0.26.7",
"typescript": "^5.4.5",
"typescript-eslint": "^8.8.0"
"typescript-eslint": "^8.8.0",
"vitest": "2.0.5"
},
"packageManager": "yarn@1.22.22"
}
26 changes: 13 additions & 13 deletions tests/__snapshots__/facet_search.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`Test on POST search Admin key: basic facet value search 1`] = `
exports[`Test on POST search > Admin key: basic facet value search 1`] = `
{
"facetHits": [
{
Expand All @@ -17,7 +17,7 @@ exports[`Test on POST search Admin key: basic facet value search 1`] = `
}
`;

exports[`Test on POST search Admin key: facet value search with filter 1`] = `
exports[`Test on POST search > Admin key: facet value search with filter 1`] = `
{
"facetHits": [
{
Expand All @@ -30,7 +30,7 @@ exports[`Test on POST search Admin key: facet value search with filter 1`] = `
}
`;

exports[`Test on POST search Admin key: facet value search with no facet query 1`] = `
exports[`Test on POST search > Admin key: facet value search with no facet query 1`] = `
{
"facetHits": [
{
Expand All @@ -55,7 +55,7 @@ exports[`Test on POST search Admin key: facet value search with no facet query 1
}
`;

exports[`Test on POST search Admin key: facet value search with search query 1`] = `
exports[`Test on POST search > Admin key: facet value search with search query 1`] = `
{
"facetHits": [
{
Expand All @@ -68,7 +68,7 @@ exports[`Test on POST search Admin key: facet value search with search query 1`]
}
`;

exports[`Test on POST search Master key: basic facet value search 1`] = `
exports[`Test on POST search > Master key: basic facet value search 1`] = `
{
"facetHits": [
{
Expand All @@ -85,7 +85,7 @@ exports[`Test on POST search Master key: basic facet value search 1`] = `
}
`;

exports[`Test on POST search Master key: facet value search with filter 1`] = `
exports[`Test on POST search > Master key: facet value search with filter 1`] = `
{
"facetHits": [
{
Expand All @@ -98,7 +98,7 @@ exports[`Test on POST search Master key: facet value search with filter 1`] = `
}
`;

exports[`Test on POST search Master key: facet value search with no facet query 1`] = `
exports[`Test on POST search > Master key: facet value search with no facet query 1`] = `
{
"facetHits": [
{
Expand All @@ -123,7 +123,7 @@ exports[`Test on POST search Master key: facet value search with no facet query
}
`;

exports[`Test on POST search Master key: facet value search with search query 1`] = `
exports[`Test on POST search > Master key: facet value search with search query 1`] = `
{
"facetHits": [
{
Expand All @@ -136,7 +136,7 @@ exports[`Test on POST search Master key: facet value search with search query 1`
}
`;

exports[`Test on POST search Search key: basic facet value search 1`] = `
exports[`Test on POST search > Search key: basic facet value search 1`] = `
{
"facetHits": [
{
Expand All @@ -153,7 +153,7 @@ exports[`Test on POST search Search key: basic facet value search 1`] = `
}
`;

exports[`Test on POST search Search key: facet value search with filter 1`] = `
exports[`Test on POST search > Search key: facet value search with filter 1`] = `
{
"facetHits": [
{
Expand All @@ -166,7 +166,7 @@ exports[`Test on POST search Search key: facet value search with filter 1`] = `
}
`;

exports[`Test on POST search Search key: facet value search with no facet query 1`] = `
exports[`Test on POST search > Search key: facet value search with no facet query 1`] = `
{
"facetHits": [
{
Expand All @@ -191,7 +191,7 @@ exports[`Test on POST search Search key: facet value search with no facet query
}
`;

exports[`Test on POST search Search key: facet value search with search query 1`] = `
exports[`Test on POST search > Search key: facet value search with search query 1`] = `
{
"facetHits": [
{
Expand Down
18 changes: 9 additions & 9 deletions tests/__snapshots__/faceting.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`Test on faceting Admin key: Get default faceting object 1`] = `
exports[`Test on faceting > Admin key: Get default faceting object 1`] = `
{
"maxValuesPerFacet": 100,
"sortFacetValuesBy": {
Expand All @@ -9,7 +9,7 @@ exports[`Test on faceting Admin key: Get default faceting object 1`] = `
}
`;

exports[`Test on faceting Admin key: Reset faceting 1`] = `
exports[`Test on faceting > Admin key: Reset faceting 1`] = `
{
"maxValuesPerFacet": 100,
"sortFacetValuesBy": {
Expand All @@ -18,7 +18,7 @@ exports[`Test on faceting Admin key: Reset faceting 1`] = `
}
`;

exports[`Test on faceting Admin key: Update faceting at null 1`] = `
exports[`Test on faceting > Admin key: Update faceting at null 1`] = `
{
"maxValuesPerFacet": 100,
"sortFacetValuesBy": {
Expand All @@ -27,7 +27,7 @@ exports[`Test on faceting Admin key: Update faceting at null 1`] = `
}
`;

exports[`Test on faceting Admin key: Update faceting settings 1`] = `
exports[`Test on faceting > Admin key: Update faceting settings 1`] = `
{
"maxValuesPerFacet": 12,
"sortFacetValuesBy": {
Expand All @@ -37,7 +37,7 @@ exports[`Test on faceting Admin key: Update faceting settings 1`] = `
}
`;

exports[`Test on faceting Master key: Get default faceting object 1`] = `
exports[`Test on faceting > Master key: Get default faceting object 1`] = `
{
"maxValuesPerFacet": 100,
"sortFacetValuesBy": {
Expand All @@ -46,7 +46,7 @@ exports[`Test on faceting Master key: Get default faceting object 1`] = `
}
`;

exports[`Test on faceting Master key: Reset faceting 1`] = `
exports[`Test on faceting > Master key: Reset faceting 1`] = `
{
"maxValuesPerFacet": 100,
"sortFacetValuesBy": {
Expand All @@ -55,7 +55,7 @@ exports[`Test on faceting Master key: Reset faceting 1`] = `
}
`;

exports[`Test on faceting Master key: Update faceting at null 1`] = `
exports[`Test on faceting > Master key: Update faceting at null 1`] = `
{
"maxValuesPerFacet": 100,
"sortFacetValuesBy": {
Expand All @@ -64,7 +64,7 @@ exports[`Test on faceting Master key: Update faceting at null 1`] = `
}
`;

exports[`Test on faceting Master key: Update faceting settings 1`] = `
exports[`Test on faceting > Master key: Update faceting settings 1`] = `
{
"maxValuesPerFacet": 12,
"sortFacetValuesBy": {
Expand Down
8 changes: 4 additions & 4 deletions tests/__snapshots__/get_search.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`Test on GET search Admin key: search on attributesToSearchOn set to null 1`] = `
exports[`Test on GET search > Admin key: search on attributesToSearchOn set to null 1`] = `
{
"estimatedTotalHits": 2,
"hits": [
Expand All @@ -24,7 +24,7 @@ exports[`Test on GET search Admin key: search on attributesToSearchOn set to nul
}
`;

exports[`Test on GET search Master key: search on attributesToSearchOn set to null 1`] = `
exports[`Test on GET search > Master key: search on attributesToSearchOn set to null 1`] = `
{
"estimatedTotalHits": 2,
"hits": [
Expand All @@ -48,7 +48,7 @@ exports[`Test on GET search Master key: search on attributesToSearchOn set to nu
}
`;

exports[`Test on GET search Search key: search on attributesToSearchOn set to null 1`] = `
exports[`Test on GET search > Search key: search on attributesToSearchOn set to null 1`] = `
{
"estimatedTotalHits": 2,
"hits": [
Expand Down
Loading

0 comments on commit f4bbd5a

Please sign in to comment.