Prevent superfluous logs in tests

This does add another devDependency; we could also simulate this
ourselves by e.g. augmenting the console methods in jest.setup.ts
to throw Errors - however, this gives us a nice error message that
gives some pointers on how to proceed if you do expect the console,
the package is pretty widely used, and is not part of the final
bundle.
This commit is contained in:
Vincent 2023-08-30 12:51:13 +02:00 коммит произвёл Vincent
Родитель 9e1b0e3c83
Коммит 78f2ddbc2a
3 изменённых файлов: 78 добавлений и 0 удалений

Просмотреть файл

@ -7,6 +7,7 @@ import { setProjectAnnotations } from "@storybook/react";
import { toHaveNoViolations } from "jest-axe";
import { expect } from "@jest/globals";
import { defaultFallbackInView } from "react-intersection-observer";
import failOnConsole from "jest-fail-on-console";
import * as globalStorybookConfig from "./.storybook/preview";
@ -16,6 +17,11 @@ setProjectAnnotations(
expect.extend(toHaveNoViolations);
// Prevent logs from cluttering up actual problems in our tests:
failOnConsole({
shouldFailOnWarn: true,
});
// See https://www.benmvp.com/blog/avoiding-react-act-warning-when-accessibility-testing-next-link-jest-axe/
// If no `IntersectionObserver` exists, Next.js's <Link> will do a state update
// immediately after rendering, causing warnings about wrapping tests in act().

71
package-lock.json сгенерированный
Просмотреть файл

@ -82,6 +82,7 @@
"jest": "^29.6.1",
"jest-axe": "^7.0.1",
"jest-environment-jsdom": "^29.5.0",
"jest-fail-on-console": "^3.1.1",
"lint-staged": "^13.2.2",
"node-mocks-http": "^1.12.1",
"nodemon": "^2.0.20",
@ -23863,6 +23864,46 @@
"node": "^14.15.0 || ^16.10.0 || >=18.0.0"
}
},
"node_modules/jest-fail-on-console": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/jest-fail-on-console/-/jest-fail-on-console-3.1.1.tgz",
"integrity": "sha512-g9HGhKcWOz8lHeZhLCXGg+RD/7upngiKkkBrHimsO/tGB0qi++QZffOgybjeI2bDW1qgdFiJJEG6t/WeTlfmOw==",
"dev": true,
"dependencies": {
"chalk": "^4.1.0"
}
},
"node_modules/jest-fail-on-console/node_modules/ansi-styles": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
"integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
"dev": true,
"dependencies": {
"color-convert": "^2.0.1"
},
"engines": {
"node": ">=8"
},
"funding": {
"url": "https://github.com/chalk/ansi-styles?sponsor=1"
}
},
"node_modules/jest-fail-on-console/node_modules/chalk": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
"integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
"dev": true,
"dependencies": {
"ansi-styles": "^4.1.0",
"supports-color": "^7.1.0"
},
"engines": {
"node": ">=10"
},
"funding": {
"url": "https://github.com/chalk/chalk?sponsor=1"
}
},
"node_modules/jest-get-type": {
"version": "29.4.3",
"resolved": "https://registry.npmjs.org/jest-get-type/-/jest-get-type-29.4.3.tgz",
@ -50359,6 +50400,36 @@
}
}
},
"jest-fail-on-console": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/jest-fail-on-console/-/jest-fail-on-console-3.1.1.tgz",
"integrity": "sha512-g9HGhKcWOz8lHeZhLCXGg+RD/7upngiKkkBrHimsO/tGB0qi++QZffOgybjeI2bDW1qgdFiJJEG6t/WeTlfmOw==",
"dev": true,
"requires": {
"chalk": "^4.1.0"
},
"dependencies": {
"ansi-styles": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
"integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
"dev": true,
"requires": {
"color-convert": "^2.0.1"
}
},
"chalk": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
"integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
"dev": true,
"requires": {
"ansi-styles": "^4.1.0",
"supports-color": "^7.1.0"
}
}
}
},
"jest-get-type": {
"version": "29.4.3",
"resolved": "https://registry.npmjs.org/jest-get-type/-/jest-get-type-29.4.3.tgz",

Просмотреть файл

@ -119,6 +119,7 @@
"jest": "^29.6.1",
"jest-axe": "^7.0.1",
"jest-environment-jsdom": "^29.5.0",
"jest-fail-on-console": "^3.1.1",
"lint-staged": "^13.2.2",
"node-mocks-http": "^1.12.1",
"nodemon": "^2.0.20",