Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
1622: Update Jest r=curquiza a=flevi29

# Pull Request

## Related issue
Fixes meilisearch#1621 

## What does this PR do?
- because newer versions of jest doesn't include anymore "jest-environment-jsdom", add it as development dependency
- because newer versions of jest simplified snapshots, update them accordingly
  - this means replacing `Object {` with `{` and `Array [` with `[`
- because newer versions of jest support builtin `fetch` from newer versions of Node.js, add a global setup script that disables builtin `fetch`
  - this is because builtin `fetch` breaks a lot of tests, regarding errors, abort, and even objects created by `fetch` are different, for instance some arrays no longer return `true` for `expect.any(Array)` (something to do with `instanceof Array`) (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray#description)
- `jasmine` `fail()` doesn't work anymore, but it still fails the tests, except with a less convenient error message `ReferenceError: fail is not defined` https://jestjs.io/blog/2021/05/25/jest-27#flipping-defaults EDIT: just realized it says here that we can set `"testRunner": "jest-jasmine2"`, but I tried it and `fail()` is still undefined
  - should fix this in a separate PR, where we fix/improve the tests, this PR is about updating Jest and making minimal code changes for it to work

## 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 <[email protected]>
  • Loading branch information
meili-bors[bot] and flevi29 authored Jan 8, 2024
2 parents c869e53 + 8950f26 commit be57d84
Show file tree
Hide file tree
Showing 10 changed files with 1,783 additions and 2,252 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ examples
scripts
tests/env
coverage
/jest-disable-built-in-fetch.js
5 changes: 5 additions & 0 deletions jest-disable-built-in-fetch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = function () {
// This is required for tests to work with "cross-fetch" on newer node versions,
// otherwise "cross-fetch" won't replace the builtin `fetch`
globalThis.fetch = undefined
}
4 changes: 4 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// @TODO Remove this once merged with eslint updates
// eslint-disable-next-line tsdoc/syntax
/** @type {import('jest').Config} */
const config = {
rootDir: '.',
testMatch: ['<rootDir>/tests/**/*.ts?(x)'],
Expand All @@ -15,6 +18,7 @@ const config = {
'jest-watch-typeahead/filename',
'jest-watch-typeahead/testname',
],
globalSetup: './jest-disable-built-in-fetch.js',
projects: [
{
preset: 'ts-jest',
Expand Down
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"@rollup/plugin-commonjs": "25.0.2",
"@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-node-resolve": "15.1.0",
"@types/jest": "^27.5.0",
"@types/jest": "^29.5.11",
"@types/prettier": "^2.2.3",
"@typescript-eslint/eslint-plugin": "2.34.0",
"@typescript-eslint/parser": "2.34.0",
Expand All @@ -88,16 +88,17 @@
"eslint-config-prettier": "^8.1.0",
"eslint-config-standard-with-typescript": "^17.0.0",
"eslint-plugin-import": "2",
"eslint-plugin-jest": "^24.1.8",
"eslint-plugin-jest": "^27.6.1",
"eslint-plugin-node": "11",
"eslint-plugin-prettier": "^3.1.4",
"eslint-plugin-promise": "4",
"eslint-plugin-standard": "5",
"eslint-plugin-tsdoc": "^0.2.17",
"gzip-size": "^6.0.0",
"jest": "^26.6.3",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"jest-fetch-mock": "^3.0.3",
"jest-watch-typeahead": "^0.6.3",
"jest-watch-typeahead": "^2.2.2",
"kleur": "^4.1.5",
"lint-staged": "11.1.2",
"nodemon": "^2.0.16",
Expand All @@ -108,7 +109,7 @@
"rollup-plugin-terser": "^7.0.0",
"rollup-plugin-typescript2": "^0.35.0",
"shx": "^0.3.2",
"ts-jest": "^26.5.6",
"ts-jest": "^29.1.1",
"typescript": "^4.9.5"
}
}
96 changes: 48 additions & 48 deletions tests/__snapshots__/facet_search.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Test on POST search Admin key: basic facet value search 1`] = `
Object {
"facetHits": Array [
Object {
{
"facetHits": [
{
"count": 1,
"value": "action",
},
Object {
{
"count": 2,
"value": "adventure",
},
Expand All @@ -18,9 +18,9 @@ Object {
`;

exports[`Test on POST search Admin key: facet value search with filter 1`] = `
Object {
"facetHits": Array [
Object {
{
"facetHits": [
{
"count": 1,
"value": "action",
},
Expand All @@ -31,21 +31,21 @@ Object {
`;

exports[`Test on POST search Admin key: facet value search with no facet query 1`] = `
Object {
"facetHits": Array [
Object {
{
"facetHits": [
{
"count": 1,
"value": "action",
},
Object {
{
"count": 2,
"value": "adventure",
},
Object {
{
"count": 1,
"value": "comedy",
},
Object {
{
"count": 2,
"value": "romance",
},
Expand All @@ -56,9 +56,9 @@ Object {
`;

exports[`Test on POST search Admin key: facet value search with search query 1`] = `
Object {
"facetHits": Array [
Object {
{
"facetHits": [
{
"count": 1,
"value": "adventure",
},
Expand All @@ -69,13 +69,13 @@ Object {
`;

exports[`Test on POST search Master key: basic facet value search 1`] = `
Object {
"facetHits": Array [
Object {
{
"facetHits": [
{
"count": 1,
"value": "action",
},
Object {
{
"count": 2,
"value": "adventure",
},
Expand All @@ -86,9 +86,9 @@ Object {
`;

exports[`Test on POST search Master key: facet value search with filter 1`] = `
Object {
"facetHits": Array [
Object {
{
"facetHits": [
{
"count": 1,
"value": "action",
},
Expand All @@ -99,21 +99,21 @@ Object {
`;

exports[`Test on POST search Master key: facet value search with no facet query 1`] = `
Object {
"facetHits": Array [
Object {
{
"facetHits": [
{
"count": 1,
"value": "action",
},
Object {
{
"count": 2,
"value": "adventure",
},
Object {
{
"count": 1,
"value": "comedy",
},
Object {
{
"count": 2,
"value": "romance",
},
Expand All @@ -124,9 +124,9 @@ Object {
`;

exports[`Test on POST search Master key: facet value search with search query 1`] = `
Object {
"facetHits": Array [
Object {
{
"facetHits": [
{
"count": 1,
"value": "adventure",
},
Expand All @@ -137,13 +137,13 @@ Object {
`;

exports[`Test on POST search Search key: basic facet value search 1`] = `
Object {
"facetHits": Array [
Object {
{
"facetHits": [
{
"count": 1,
"value": "action",
},
Object {
{
"count": 2,
"value": "adventure",
},
Expand All @@ -154,9 +154,9 @@ Object {
`;

exports[`Test on POST search Search key: facet value search with filter 1`] = `
Object {
"facetHits": Array [
Object {
{
"facetHits": [
{
"count": 1,
"value": "action",
},
Expand All @@ -167,21 +167,21 @@ Object {
`;

exports[`Test on POST search Search key: facet value search with no facet query 1`] = `
Object {
"facetHits": Array [
Object {
{
"facetHits": [
{
"count": 1,
"value": "action",
},
Object {
{
"count": 2,
"value": "adventure",
},
Object {
{
"count": 1,
"value": "comedy",
},
Object {
{
"count": 2,
"value": "romance",
},
Expand All @@ -192,9 +192,9 @@ Object {
`;

exports[`Test on POST search Search key: facet value search with search query 1`] = `
Object {
"facetHits": Array [
Object {
{
"facetHits": [
{
"count": 1,
"value": "adventure",
},
Expand Down
32 changes: 16 additions & 16 deletions tests/__snapshots__/faceting.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,73 +1,73 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Test on faceting Admin key: Get default faceting object 1`] = `
Object {
{
"maxValuesPerFacet": 100,
"sortFacetValuesBy": Object {
"sortFacetValuesBy": {
"*": "alpha",
},
}
`;

exports[`Test on faceting Admin key: Reset faceting 1`] = `
Object {
{
"maxValuesPerFacet": 100,
"sortFacetValuesBy": Object {
"sortFacetValuesBy": {
"*": "alpha",
},
}
`;

exports[`Test on faceting Admin key: Update faceting at null 1`] = `
Object {
{
"maxValuesPerFacet": 100,
"sortFacetValuesBy": Object {
"sortFacetValuesBy": {
"*": "alpha",
},
}
`;

exports[`Test on faceting Admin key: Update faceting settings 1`] = `
Object {
{
"maxValuesPerFacet": 12,
"sortFacetValuesBy": Object {
"sortFacetValuesBy": {
"*": "alpha",
"test": "count",
},
}
`;

exports[`Test on faceting Master key: Get default faceting object 1`] = `
Object {
{
"maxValuesPerFacet": 100,
"sortFacetValuesBy": Object {
"sortFacetValuesBy": {
"*": "alpha",
},
}
`;

exports[`Test on faceting Master key: Reset faceting 1`] = `
Object {
{
"maxValuesPerFacet": 100,
"sortFacetValuesBy": Object {
"sortFacetValuesBy": {
"*": "alpha",
},
}
`;

exports[`Test on faceting Master key: Update faceting at null 1`] = `
Object {
{
"maxValuesPerFacet": 100,
"sortFacetValuesBy": Object {
"sortFacetValuesBy": {
"*": "alpha",
},
}
`;

exports[`Test on faceting Master key: Update faceting settings 1`] = `
Object {
{
"maxValuesPerFacet": 12,
"sortFacetValuesBy": Object {
"sortFacetValuesBy": {
"*": "alpha",
"test": "count",
},
Expand Down
Loading

0 comments on commit be57d84

Please sign in to comment.