Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure Jest for TypeScript #12167

Merged
merged 67 commits into from Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from 59 commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
f7bb798
Install and configure ts-jest
swissspidy Aug 25, 2022
4ee0b17
Convert some test files to TS
swissspidy Aug 25, 2022
a5947e8
Update `testMatch` config
swissspidy Aug 25, 2022
7bc323d
Specifically install Jest types
swissspidy Aug 25, 2022
f2447c6
Downgrade `@jest/types`
swissspidy Aug 25, 2022
8122b13
Merge branch 'main' into add/12097-ts-jest
swissspidy Aug 29, 2022
4053160
Remove `@types/jest`
swissspidy Aug 29, 2022
6e0ea3a
Fix transform & update tests
swissspidy Aug 29, 2022
dd7f2a7
Change `mime/lite` import
swissspidy Aug 30, 2022
da5881c
Merge branch 'main' into add/12097-ts-jest
swissspidy Aug 30, 2022
37b5d10
Enable `jest/unbound-method` for TS tests
swissspidy Aug 30, 2022
fdf484d
Undo some changes
swissspidy Aug 30, 2022
6ea634f
Update `getBoundRect`
swissspidy Aug 30, 2022
1f67412
Update types & typescript
swissspidy Aug 30, 2022
f401a6a
Update deps
swissspidy Aug 30, 2022
700beab
Disable type checking for ts-jest for now
swissspidy Aug 31, 2022
335eaa9
Merge branch 'main' into add/12097-ts-jest
swissspidy Aug 31, 2022
e20af3c
Lint fixes
swissspidy Aug 31, 2022
228152e
Update deps
swissspidy Aug 31, 2022
44e6b62
Remove file
swissspidy Aug 31, 2022
fb3e5cc
Merge branch 'main' into add/12097-ts-jest
swissspidy Sep 2, 2022
8c2a6ff
Move `normalizeResourceSizes` to `wp-story-editor` package
swissspidy Sep 2, 2022
9f8a488
Move `normalizeResourceSizes` to `wp-story-editor`
swissspidy Sep 2, 2022
8eaeb82
Fix incorrect import
swissspidy Sep 2, 2022
87c4cf8
Remove incorrect import
swissspidy Sep 2, 2022
9fe1e96
Convert test to TypeScript
swissspidy Sep 2, 2022
750c424
Update some packages, try to resolve conflicts
swissspidy Sep 2, 2022
469785d
Update ts-jest config
swissspidy Sep 2, 2022
b1be90f
Update more deps
swissspidy Sep 2, 2022
0a49ee2
Update lock file
swissspidy Sep 2, 2022
a7ccd07
Resolve another todo
swissspidy Sep 2, 2022
7f263f4
Merge branch 'main' into add/12097-ts-jest
swissspidy Sep 6, 2022
d501fa3
Convert more tests
swissspidy Sep 6, 2022
bdae5d2
Add reference
swissspidy Sep 6, 2022
5f7b222
More tweaks
swissspidy Sep 6, 2022
1a9948a
Merge branch 'main' into add/12097-ts-jest
swissspidy Sep 10, 2022
b5bdc4d
Merge branch 'main' into add/12097-ts-jest
swissspidy Sep 12, 2022
83e4dbc
Merge branch 'main' into add/12097-ts-jest
swissspidy Sep 14, 2022
f1e6755
Merge branch 'main' into add/12097-ts-jest
swissspidy Sep 14, 2022
0048252
Start converting richt-text tests
swissspidy Sep 14, 2022
b72d4cd
Convert patterns tests
swissspidy Sep 14, 2022
7c6c976
Update date tests & types
swissspidy Sep 14, 2022
bc36baf
Convert wp-utils tests
swissspidy Sep 14, 2022
96af850
Update patterns test
swissspidy Sep 14, 2022
df1e45e
Fix type errors
swissspidy Sep 14, 2022
df6cf35
Update more rich-text tests
swissspidy Sep 14, 2022
cac675e
More adjustments
swissspidy Sep 14, 2022
f11b66e
Try updating test instead
swissspidy Sep 15, 2022
c58d20e
Merge branch 'main' into add/12097-ts-jest
swissspidy Sep 16, 2022
2ea2523
Merge branch 'main' into add/12097-ts-jest
swissspidy Sep 30, 2022
b9afa96
Merge branch 'main' into add/12097-ts-jest
swissspidy Oct 14, 2022
dd41dd3
Update ts-jest
swissspidy Oct 14, 2022
7a6acbd
Merge branch 'main' into add/12097-ts-jest
swissspidy Oct 26, 2022
97bc417
Just use babel-jest
swissspidy Oct 26, 2022
3316566
Update patterns tests
swissspidy Oct 26, 2022
a24d4bf
More fixes
swissspidy Oct 26, 2022
e4ff4f4
More fixes
swissspidy Oct 26, 2022
df9200c
Merge branch 'main' into add/12097-ts-jest
swissspidy Oct 26, 2022
f903b1b
Update resolver
swissspidy Oct 26, 2022
3d350dd
Merge branch 'main' into add/12097-ts-jest
swissspidy Nov 2, 2022
1b5fab2
Undo change to test
swissspidy Nov 2, 2022
86b4e65
Patch types instead
swissspidy Nov 2, 2022
9ed6537
Merge branch 'main' into add/12097-ts-jest
swissspidy Nov 7, 2022
b0ecf2b
Apply suggestions from code review
swissspidy Nov 7, 2022
940f3fe
Merge branch 'main' into add/12097-ts-jest
swissspidy Nov 8, 2022
51d8efd
Update lock file
swissspidy Nov 8, 2022
30dc7a2
lint fix
swissspidy Nov 8, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions .eslintrc
Expand Up @@ -386,7 +386,9 @@
"files": [
"__mocks__/**/*.js",
"**/test/**/*.js",
"**/test/**/*.ts",
"**/testUtils/**/*.js",
"**/testUtils/**/*.ts",
"tests/js/**/*.js"
],
"excludedFiles": [
Expand Down Expand Up @@ -430,6 +432,16 @@
"testing-library/no-dom-import": "error"
}
},
{
"files": [
"**/test/**/*.ts",
"**/testUtils/**/*.ts"
],
"rules": {
"@typescript-eslint/unbound-method": "off",
"jest/unbound-method": "error"
}
},
{
"files": [
"__mocks__/**/*.js"
Expand Down
4,687 changes: 1,299 additions & 3,388 deletions package-lock.json

Large diffs are not rendered by default.

37 changes: 22 additions & 15 deletions package.json
Expand Up @@ -33,10 +33,10 @@
},
"devDependencies": {
"@ampproject/toolbox-optimizer": "^2.9.0",
"@babel/core": "^7.19.3",
"@babel/core": "^7.19.6",
"@babel/eslint-parser": "^7.19.1",
"@babel/eslint-plugin": "^7.19.1",
"@babel/preset-env": "^7.19.3",
"@babel/preset-env": "^7.19.4",
"@babel/preset-react": "^7.18.6",
"@babel/preset-typescript": "^7.18.6",
"@googleforcreators/dashboard": "*",
Expand All @@ -46,13 +46,14 @@
"@googleforcreators/migration": "*",
"@googleforcreators/moveable": "*",
"@googleforcreators/story-editor": "*",
"@jest/types": "^29.0.1",
"@jsdevtools/coverage-istanbul-loader": "^3.0.5",
"@percy/cli": "^1.10.4",
"@percy/cli": "^1.12.0",
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.8",
"@prettier/plugin-xml": "^2.2.0",
"@rollup/plugin-babel": "^5.3.1",
"@rollup/plugin-commonjs": "^22.0.2",
"@rollup/plugin-dynamic-import-vars": "^1.4.4",
"@rollup/plugin-babel": "^6.0.2",
"@rollup/plugin-commonjs": "^23.0.2",
"@rollup/plugin-dynamic-import-vars": "^2.0.1",
"@rollup/plugin-json": "^5.0.1",
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-typescript": "^9.0.2",
Expand All @@ -78,10 +79,16 @@
"@testing-library/react": "^12.1.5",
"@testing-library/react-hooks": "^8.0.1",
"@testing-library/user-event": "^14.4.3",
"@types/eslint": "^8.4.6",
"@types/eslint-scope": "^3.7.4",
"@types/estree": "^1.0.0",
"@types/jest": "^29.0.0",
"@types/jsdom": "^20.0.0",
"@types/node": "^18.11.6",
"@types/styled-components": "^5.1.26",
"@types/uuid": "^8.3.4",
"@typescript-eslint/eslint-plugin": "^5.39.0",
"@typescript-eslint/parser": "^5.40.0",
"@typescript-eslint/eslint-plugin": "^5.41.0",
"@typescript-eslint/parser": "^5.41.0",
"@web-stories-wp/e2e-tests": "*",
"@web-stories-wp/eslint-import-resolver": "*",
"@web-stories-wp/jest-amp": "*",
Expand All @@ -103,18 +110,18 @@
"core-js": "^3.26.0",
"cross-env": "^7.0.3",
"css-loader": "^6.7.1",
"css-minimizer-webpack-plugin": "^4.2.1",
"css-minimizer-webpack-plugin": "^4.2.2",
"cssnano": "^5.1.13",
"eslint": "^8.25.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-header": "^3.1.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jasmine": "^4.1.3",
"eslint-plugin-jest": "^27.1.2",
"eslint-plugin-jest": "^27.1.3",
"eslint-plugin-jest-dom": "^4.0.2",
"eslint-plugin-jest-extended": "^2.0.0",
"eslint-plugin-jsdoc": "^39.3.13",
"eslint-plugin-jsdoc": "^39.3.25",
"eslint-plugin-jsx-a11y": "^6.6.1",
"eslint-plugin-markdown": "^3.0.0",
"eslint-plugin-node": "^11.1.0",
Expand All @@ -123,14 +130,14 @@
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-security": "^1.5.0",
"eslint-plugin-styled-components-a11y": "^1.0.0",
"eslint-plugin-testing-library": "^5.7.2",
"eslint-plugin-testing-library": "^5.9.1",
"glob": "^8.0.3",
"html-webpack-plugin": "^5.3.2",
"husky": "^8.0.1",
"jest": "^29.2.2",
"jest-axe": "^6.0.0",
"jest-canvas-mock": "^2.4.0",
"jest-environment-jsdom": "^29.2.0",
"jest-environment-jsdom": "^29.2.2",
"jest-extended": "^3.1.0",
"jest-fetch-mock": "^3.0.3",
"jest-matcher-deep-close-to": "^3.0.2",
Expand All @@ -149,7 +156,7 @@
"mockdate": "^3.0.5",
"npm-package-json-lint": "^6.3.0",
"npm-run-all": "^4.1.5",
"patch-package": "^6.4.7",
"patch-package": "^6.5.0",
"postcss-jsx": "^0.36.4",
"postcss-syntax": "^0.36.2",
"prettier": "^2.7.1",
Expand Down Expand Up @@ -177,7 +184,7 @@
"terser-webpack-plugin": "^5.3.6",
"typescript": "^4.8.4",
"webpack": "^5.74.0",
"webpack-bundle-analyzer": "^4.6.1",
"webpack-bundle-analyzer": "^4.7.0",
"webpack-cli": "^4.10.0",
"webpack-dev-server": "^4.11.1",
"webpackbar": "^5.0.2",
Expand Down
Expand Up @@ -17,7 +17,7 @@
/**
* External dependencies
*/
import { useCallback, useEffect, useMemo } from 'react';
import { useCallback, useEffect, useMemo } from '@googleforcreators/react';
import { Pill } from '@googleforcreators/design-system';
import { __, sprintf } from '@googleforcreators/i18n';
import styled from 'styled-components';
Expand Down
2 changes: 1 addition & 1 deletion packages/date/src/formatTime.ts
Expand Up @@ -26,7 +26,7 @@ import { getSettings } from './settings';
* @param date Date to format.
* @return Displayable relative date string
*/
function formatTime(date: Date) {
function formatTime(date: Date | string) {
const settings = getSettings();
const { timeFormat } = settings;
return format(date, timeFormat);
Expand Down
2 changes: 1 addition & 1 deletion packages/date/src/settings.ts
Expand Up @@ -56,7 +56,7 @@ export function resetSettings() {
*
* @param newSettings Date settings.
*/
export function updateSettings(newSettings: Settings) {
export function updateSettings(newSettings: Partial<Settings>) {
settings = {
...settings,
...newSettings,
Expand Down
Expand Up @@ -32,7 +32,8 @@ describe('date/convertFormatString', () => {
'converts PHP date format string to its date-fns equivalent',
(formatString, expectedOutput) => {
const convertedWithoutSeparator = convertFormatString(
formatString
formatString,
new Date()
).replace(FORMAT_TOKEN_SEPARATOR_REGEX, '');
expect(convertedWithoutSeparator).toStrictEqual(expectedOutput);
expect(() => format(new Date(), formatString)).not.toThrow();
Expand Down
File renamed without changes.
Expand Up @@ -31,7 +31,7 @@ import getOptions from '../getOptions';
/**
* Returns the current date in the site's timezone.
*
* @return {Date} Date object.
* @return Date object.
*/
function getCurrentDate() {
return toDate(new Date(), getOptions());
Expand Down Expand Up @@ -204,10 +204,4 @@ describe('date/getRelativeDisplayDate', () => {

expect(formattedDate).toBe('05/02/2020');
});

it('should return an empty string with a null date', () => {
const formattedDate = getRelativeDisplayDate(null);

expect(formattedDate).toBe('');
});
});
Expand Up @@ -68,9 +68,4 @@ describe('date/getTimeZoneString', () => {
updateSettings({ gmtOffset: -121.1 });
expect(getTimeZoneString()).toBe('-02:01');
});

it('returns default is offset if NaN', () => {
updateSettings({ gmtOffset: 'EST' });
expect(getTimeZoneString()).toBe('+00');
});
});
File renamed without changes.
17 changes: 16 additions & 1 deletion packages/design-system/src/components/dialog/index.js
Expand Up @@ -62,11 +62,26 @@ const DialogActions = styled.div`
}
}
`;

/**
* @typedef {Object} DialogProps
* @property {import('react').ReactNode} children Children.
* @property {string} title Title.
* @property {import('react').ReactNode[]} actions Actions.
* @property {boolean} isOpen Whether the dialog is open.
* @property {Function} onClose Close callback.
* @property {string} contentLabel Content label.
*/

/**
* Dialog component.
*
* Dialogs should be wrapped in a ThemeProvider
* and given the inverted theme to the app.
*
* @param {DialogProps} Dialog props.
* @return {import('react').ReactElement} Dialog.
*/

export function Dialog({
children,
title,
Expand Down
Expand Up @@ -45,9 +45,8 @@ import {
/**
* Allows keyboard arrow navigation through grids
*
* @param {UseGridViewKeysProps} props
* @param {UseGridViewKeysProps} props Grid view keys props.
*/

function useGridViewKeys(props) {
const {
currentItemId,
Expand Down
1 change: 0 additions & 1 deletion packages/design-system/src/components/tooltip/index.js
Expand Up @@ -102,7 +102,6 @@ let lastVisibleDelayedTooltip = null;
* @param {number} props.popupZIndexOverride If present, passes an override for z-index to popup
* @return {import('react').Component} BaseTooltip element
*/

function BaseTooltip({
title,
shortcut,
Expand Down
3 changes: 1 addition & 2 deletions packages/elements/tsconfig.json
Expand Up @@ -10,6 +10,5 @@
{ "path": "../patterns" },
{ "path": "../units" }
],
"include": ["src/**/*"],
"exclude": ["src/**/test/**/*"]
"include": ["src/**/*"]
}
Expand Up @@ -24,14 +24,15 @@ import { resolve } from 'path';
* Internal dependencies
*/
import { CURATED_FONT_NAMES } from '../constants';
import type { Font } from '../types';

describe('Curated fonts', () => {
const fonts = JSON.parse(
const fonts: Font[] = JSON.parse(
readFileSync(
resolve(process.cwd(), 'packages/fonts/src/fonts.json'),
'utf8'
)
);
) as Font[];
const fontNames = fonts.map(({ family }) => family);

// @see https://github.com/googleforcreators/web-stories-wp/issues/3880
Expand Down
Expand Up @@ -18,6 +18,7 @@
* External dependencies
*/
import { renderToStaticMarkup } from '@googleforcreators/react';
import type { ReactNode } from 'react';

/**
* Internal dependencies
Expand Down Expand Up @@ -57,7 +58,11 @@ describe('transformNode', () => {
node.setAttribute('class', 'bar');
node.textContent = 'Hello World';

const AwesomeComponent = ({ children }) => {
const AwesomeComponent = ({
children,
}: {
children?: ReactNode | undefined;
swissspidy marked this conversation as resolved.
Show resolved Hide resolved
}) => {
return (
<div id="bar" className="baz">
{children}
Expand All @@ -81,7 +86,11 @@ describe('transformNode', () => {
p.appendChild(span);
node.appendChild(p);

const AwesomeComponent = ({ children }) => {
const AwesomeComponent = ({
children,
}: {
children?: ReactNode | undefined;
}) => {
return (
<span id="bar" className="baz">
<em>{children}</em>
Expand Down
Expand Up @@ -20,13 +20,15 @@
import translateToExclusiveList from '../translateToExclusiveList';

describe('translateToExclusiveList', () => {
it.each`
options | result
${[]} | ${''}
${['one']} | ${'one'}
${['doctor', 'barnacle']} | ${'doctor or barnacle'}
${['apple', 'banana', 'mango', 'dragonfruit']} | ${'apple, banana, mango, or dragonfruit'}
`('should translate as expected', ({ options, result }) => {
it.each([
[[], ''],
[['one'], 'one'],
[['doctor', 'barnacle'], 'doctor or barnacle'],
[
['apple', 'banana', 'mango', 'dragonfruit'],
'apple, banana, mango, or dragonfruit',
],
])('should translate as expected', (options, result) => {
expect(translateToExclusiveList(options)).toBe(result);
});
});
Expand Up @@ -13,19 +13,22 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* Internal dependencies
*/
import translateToInclusiveList from '../translateToInclusiveList';

describe('translateToInclusiveList', () => {
it.each`
options | result
${[]} | ${''}
${['one']} | ${'one'}
${['doctor', 'barnacle']} | ${'doctor and barnacle'}
${['apple', 'banana', 'mango', 'dragonfruit']} | ${'apple, banana, mango, and dragonfruit'}
`('should translate as expected', ({ options, result }) => {
it.each([
[[], ''],
[['one'], 'one'],
[['doctor', 'barnacle'], 'doctor and barnacle'],
[
['apple', 'banana', 'mango', 'dragonfruit'],
'apple, banana, mango, and dragonfruit',
],
])('should translate as expected', (options, result) => {
expect(translateToInclusiveList(options)).toBe(result);
});
});
Expand Up @@ -18,6 +18,7 @@
* External dependencies
*/
import { renderToStaticMarkup } from '@googleforcreators/react';
import type { ReactNode } from 'react';

/**
* Internal dependencies
Expand Down Expand Up @@ -72,7 +73,10 @@ describe('TranslateWithMarkup component', () => {
it('returns expected React element for custom component', () => {
const string = 'This is a <a>link</a>!';

const Link = (props) => {
const Link = (props: {
href: string;
children?: ReactNode | undefined;
}) => {
return <a {...props}>{props.children}</a>;
};

Expand All @@ -86,7 +90,12 @@ describe('TranslateWithMarkup component', () => {
});

it('returns expected React element for multiple components', () => {
const Link = (props) => {
const Link = (props: {
href: string;
target: string;
rel: string;
children?: ReactNode | undefined;
}) => {
return <a {...props}>{props.children}</a>;
};

Expand Down