From f4c27ff56d8114cadd4f209c8ce06c6259963e10 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Wed, 25 Oct 2023 11:06:37 -0400 Subject: [PATCH 01/15] remove Babel and Enzyme use esbuild to compile use strict render for all add renderContext helper clean up types --- .babelrc.js | 15 - .eslintignore | 2 - .eslintrc.js | 38 +- .gitignore | 1 - .npmignore | 4 +- .nvmrc | 2 +- .prettierrc | 4 +- .vscode/settings.json | 6 +- __tests__/__snapshots__/misc.test.tsx.snap | 29 + __tests__/api/__snapshots__/base.test.js.snap | 5 - .../api/__snapshots__/base.test.tsx.snap | 5 + .../api/__snapshots__/client.test.js.snap | 17 - .../api/__snapshots__/client.test.tsx.snap | 17 + __tests__/api/__snapshots__/link.test.js.snap | 49 - .../api/__snapshots__/link.test.tsx.snap | 49 + __tests__/api/__snapshots__/meta.test.js.snap | 35 - .../api/__snapshots__/meta.test.tsx.snap | 35 + .../api/__snapshots__/noscript.test.js.snap | 5 - .../api/__snapshots__/noscript.test.tsx.snap | 5 + .../api/__snapshots__/script.test.js.snap | 13 - .../api/__snapshots__/script.test.tsx.snap | 13 + ...style.test.js.snap => style.test.tsx.snap} | 10 +- .../api/__snapshots__/title.test.js.snap | 53 - .../api/__snapshots__/title.test.tsx.snap | 53 + __tests__/api/{base.test.js => base.test.tsx} | 34 +- ...ibutes.test.js => bodyAttributes.test.tsx} | 76 +- .../api/{client.test.js => client.test.tsx} | 16 +- ...ibutes.test.js => htmlAttributes.test.tsx} | 142 +- __tests__/api/{link.test.js => link.test.tsx} | 266 +- __tests__/api/{meta.test.js => meta.test.tsx} | 201 +- .../{noscript.test.js => noscript.test.tsx} | 17 +- .../api/{script.test.js => script.test.tsx} | 84 +- .../api/{style.test.js => style.test.tsx} | 15 +- .../api/{title.test.js => title.test.tsx} | 6 +- ...butes.test.js => titleAttributes.test.tsx} | 45 +- __tests__/api/utils.js | 15 - __tests__/deferred.js | 95 - __tests__/deferred.test.tsx | 81 + .../{fragment.test.js => fragment.test.tsx} | 20 +- __tests__/{misc.test.js => misc.test.tsx} | 94 +- .../server/__snapshots__/base.test.js.snap | 9 - .../server/__snapshots__/base.test.tsx.snap | 9 + .../__snapshots__/bodyAttributes.test.js.snap | 5 - .../bodyAttributes.test.tsx.snap | 5 + .../__snapshots__/helmetData.test.js.snap | 15 - .../__snapshots__/helmetData.test.tsx.snap | 15 + .../__snapshots__/htmlAttributes.test.js.snap | 9 - .../htmlAttributes.test.tsx.snap | 9 + .../server/__snapshots__/link.test.js.snap | 9 - .../server/__snapshots__/link.test.tsx.snap | 9 + .../server/__snapshots__/meta.test.js.snap | 9 - .../server/__snapshots__/meta.test.tsx.snap | 9 + .../__snapshots__/noscript.test.js.snap | 5 - .../__snapshots__/noscript.test.tsx.snap | 5 + .../server/__snapshots__/script.test.js.snap | 9 - .../server/__snapshots__/script.test.tsx.snap | 9 + .../server/__snapshots__/server.test.js.snap | 13 - .../server/__snapshots__/server.test.tsx.snap | 13 + .../server/__snapshots__/style.test.js.snap | 9 - .../server/__snapshots__/style.test.tsx.snap | 9 + .../server/__snapshots__/title.test.js.snap | 35 - .../server/__snapshots__/title.test.tsx.snap | 35 + .../server/{base.test.js => base.test.tsx} | 36 +- ...ibutes.test.js => bodyAttributes.test.tsx} | 20 +- ...helmetData.test.js => helmetData.test.tsx} | 30 +- ...ibutes.test.js => htmlAttributes.test.tsx} | 36 +- .../server/{link.test.js => link.test.tsx} | 42 +- .../server/{meta.test.js => meta.test.tsx} | 42 +- .../{noscript.test.js => noscript.test.tsx} | 26 +- .../{script.test.js => script.test.tsx} | 42 +- .../{server.test.js => server.test.tsx} | 75 +- .../server/{style.test.js => style.test.tsx} | 38 +- .../server/{title.test.js => title.test.tsx} | 146 +- __tests__/server/utils.js | 15 - __tests__/setup-test-env.ts | 21 + __tests__/utils.tsx | 23 + build.ts | 20 + index.d.ts | 95 - jest.config.js | 5 - jest.setup.js | 45 - package.json | 79 +- src/{Dispatcher.js => Dispatcher.tsx} | 22 +- src/{HelmetData.js => HelmetData.ts} | 29 +- src/Provider.js | 45 - src/Provider.tsx | 32 + src/{client.js => client.ts} | 60 +- src/{constants.js => constants.ts} | 73 +- src/{index.js => index.tsx} | 98 +- src/{server.js => server.ts} | 60 +- src/types.ts | 101 + src/{utils.js => utils.ts} | 60 +- tsconfig.json | 21 + vitest.config.ts | 19 + yarn.lock | 8232 ++++++----------- 94 files changed, 4392 insertions(+), 7222 deletions(-) delete mode 100644 .babelrc.js create mode 100644 __tests__/__snapshots__/misc.test.tsx.snap delete mode 100644 __tests__/api/__snapshots__/base.test.js.snap create mode 100644 __tests__/api/__snapshots__/base.test.tsx.snap delete mode 100644 __tests__/api/__snapshots__/client.test.js.snap create mode 100644 __tests__/api/__snapshots__/client.test.tsx.snap delete mode 100644 __tests__/api/__snapshots__/link.test.js.snap create mode 100644 __tests__/api/__snapshots__/link.test.tsx.snap delete mode 100644 __tests__/api/__snapshots__/meta.test.js.snap create mode 100644 __tests__/api/__snapshots__/meta.test.tsx.snap delete mode 100644 __tests__/api/__snapshots__/noscript.test.js.snap create mode 100644 __tests__/api/__snapshots__/noscript.test.tsx.snap delete mode 100644 __tests__/api/__snapshots__/script.test.js.snap create mode 100644 __tests__/api/__snapshots__/script.test.tsx.snap rename __tests__/api/__snapshots__/{style.test.js.snap => style.test.tsx.snap} (67%) delete mode 100644 __tests__/api/__snapshots__/title.test.js.snap create mode 100644 __tests__/api/__snapshots__/title.test.tsx.snap rename __tests__/api/{base.test.js => base.test.tsx} (77%) rename __tests__/api/{bodyAttributes.test.js => bodyAttributes.test.tsx} (61%) rename __tests__/api/{client.test.js => client.test.tsx} (95%) rename __tests__/api/{htmlAttributes.test.js => htmlAttributes.test.tsx} (60%) rename __tests__/api/{link.test.js => link.test.tsx} (63%) rename __tests__/api/{meta.test.js => meta.test.tsx} (66%) rename __tests__/api/{noscript.test.js => noscript.test.tsx} (86%) rename __tests__/api/{script.test.js => script.test.tsx} (75%) rename __tests__/api/{style.test.js => style.test.tsx} (91%) rename __tests__/api/{title.test.js => title.test.tsx} (98%) rename __tests__/api/{titleAttributes.test.js => titleAttributes.test.tsx} (66%) delete mode 100644 __tests__/api/utils.js delete mode 100644 __tests__/deferred.js create mode 100644 __tests__/deferred.test.tsx rename __tests__/{fragment.test.js => fragment.test.tsx} (57%) rename __tests__/{misc.test.js => misc.test.tsx} (83%) delete mode 100644 __tests__/server/__snapshots__/base.test.js.snap create mode 100644 __tests__/server/__snapshots__/base.test.tsx.snap delete mode 100644 __tests__/server/__snapshots__/bodyAttributes.test.js.snap create mode 100644 __tests__/server/__snapshots__/bodyAttributes.test.tsx.snap delete mode 100644 __tests__/server/__snapshots__/helmetData.test.js.snap create mode 100644 __tests__/server/__snapshots__/helmetData.test.tsx.snap delete mode 100644 __tests__/server/__snapshots__/htmlAttributes.test.js.snap create mode 100644 __tests__/server/__snapshots__/htmlAttributes.test.tsx.snap delete mode 100644 __tests__/server/__snapshots__/link.test.js.snap create mode 100644 __tests__/server/__snapshots__/link.test.tsx.snap delete mode 100644 __tests__/server/__snapshots__/meta.test.js.snap create mode 100644 __tests__/server/__snapshots__/meta.test.tsx.snap delete mode 100644 __tests__/server/__snapshots__/noscript.test.js.snap create mode 100644 __tests__/server/__snapshots__/noscript.test.tsx.snap delete mode 100644 __tests__/server/__snapshots__/script.test.js.snap create mode 100644 __tests__/server/__snapshots__/script.test.tsx.snap delete mode 100644 __tests__/server/__snapshots__/server.test.js.snap create mode 100644 __tests__/server/__snapshots__/server.test.tsx.snap delete mode 100644 __tests__/server/__snapshots__/style.test.js.snap create mode 100644 __tests__/server/__snapshots__/style.test.tsx.snap delete mode 100644 __tests__/server/__snapshots__/title.test.js.snap create mode 100644 __tests__/server/__snapshots__/title.test.tsx.snap rename __tests__/server/{base.test.js => base.test.tsx} (73%) rename __tests__/server/{bodyAttributes.test.js => bodyAttributes.test.tsx} (75%) rename __tests__/server/{helmetData.test.js => helmetData.test.tsx} (81%) rename __tests__/server/{htmlAttributes.test.js => htmlAttributes.test.tsx} (74%) rename __tests__/server/{link.test.js => link.test.tsx} (81%) rename __tests__/server/{meta.test.js => meta.test.tsx} (84%) rename __tests__/server/{noscript.test.js => noscript.test.tsx} (83%) rename __tests__/server/{script.test.js => script.test.tsx} (81%) rename __tests__/server/{server.test.js => server.test.tsx} (83%) rename __tests__/server/{style.test.js => style.test.tsx} (82%) rename __tests__/server/{title.test.js => title.test.tsx} (74%) delete mode 100644 __tests__/server/utils.js create mode 100644 __tests__/setup-test-env.ts create mode 100644 __tests__/utils.tsx create mode 100644 build.ts delete mode 100644 index.d.ts delete mode 100644 jest.config.js delete mode 100644 jest.setup.js rename src/{Dispatcher.js => Dispatcher.tsx} (70%) rename src/{HelmetData.js => HelmetData.ts} (55%) delete mode 100644 src/Provider.js create mode 100644 src/Provider.tsx rename src/{client.js => client.ts} (72%) rename src/{constants.js => constants.ts} (50%) rename src/{index.js => index.tsx} (58%) rename src/{server.js => server.ts} (75%) create mode 100644 src/types.ts rename src/{utils.js => utils.ts} (82%) create mode 100644 tsconfig.json create mode 100644 vitest.config.ts diff --git a/.babelrc.js b/.babelrc.js deleted file mode 100644 index c4bd7aab..00000000 --- a/.babelrc.js +++ /dev/null @@ -1,15 +0,0 @@ -module.exports = { - presets: [ - [ - 'babel-preset-kyt-react', - { - includeRuntime: true, - }, - ], - ], - env: { - test: { - plugins: [['@babel/plugin-proposal-private-property-in-object', { loose: true }]], - }, - }, -}; diff --git a/.eslintignore b/.eslintignore index 09ddce2b..36831073 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,6 +1,4 @@ /lib -/es /coverage /node_modules package.json -package-lock.json diff --git a/.eslintrc.js b/.eslintrc.js index 960521e0..4e614343 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,17 +1,31 @@ +/** + * @type {import('@types/eslint').Linter.BaseConfig} + */ module.exports = { - extends: ['kyt'], - + extends: [ + '@remix-run/eslint-config', + '@remix-run/eslint-config/node', + '@remix-run/eslint-config/jest-testing-library', + 'prettier', + ], + plugins: ['prettier'], rules: { - 'react/static-property-placement': 0, - }, - - overrides: [ - { - files: ['*.test.js'], - rules: { - 'react/jsx-props-no-spreading': 0, - 'react/no-unknown-property': 0, + 'import/order': 'error', + 'prettier/prettier': [ + 'error', + { + singleQuote: true, + trailingComma: 'es5', + useTabs: false, + tabWidth: 2, + printWidth: 100, }, + ], + 'testing-library/render-result-naming-convention': 'off', + }, + settings: { + jest: { + version: 27, }, - ], + }, }; diff --git a/.gitignore b/.gitignore index f39528b3..3063f07d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ -es lib node_modules diff --git a/.npmignore b/.npmignore index 876e5a28..fe00227a 100644 --- a/.npmignore +++ b/.npmignore @@ -1,6 +1,6 @@ -.babelrc -.eslintrc.json +.eslintrc.js jest.setup.js +*.config.js node_modules src __tests__ diff --git a/.nvmrc b/.nvmrc index 832d3850..603606bc 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -16.14.0 +18.17.0 diff --git a/.prettierrc b/.prettierrc index d529ffc9..54983dda 100644 --- a/.prettierrc +++ b/.prettierrc @@ -2,5 +2,7 @@ "singleQuote": true, "trailingComma": "es5", "arrowParens": "avoid", - "printWidth": 100 + "printWidth": 100, + "useTabs": false, + "tabWidth": 2 } diff --git a/.vscode/settings.json b/.vscode/settings.json index 4a8edefa..56119ba6 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -6,6 +6,6 @@ "typescriptreact" ], "editor.codeActionsOnSave": { - "source.fixAll.eslint": true, - }, -} \ No newline at end of file + "source.fixAll.eslint": true + } +} diff --git a/__tests__/__snapshots__/misc.test.tsx.snap b/__tests__/__snapshots__/misc.test.tsx.snap new file mode 100644 index 00000000..a88069ad --- /dev/null +++ b/__tests__/__snapshots__/misc.test.tsx.snap @@ -0,0 +1,29 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`misc > API > encodes special characters 1`] = `""`; + +exports[`misc > API > only adds new tags and preserves tags when rendering additional Helmet instances 1`] = `""`; + +exports[`misc > API > only adds new tags and preserves tags when rendering additional Helmet instances 2`] = `""`; + +exports[`misc > API > only adds new tags and preserves tags when rendering additional Helmet instances 3`] = `""`; + +exports[`misc > API > only adds new tags and preserves tags when rendering additional Helmet instances 4`] = `""`; + +exports[`misc > API > only adds new tags and preserves tags when rendering additional Helmet instances 5`] = `""`; + +exports[`misc > API > recognizes valid tags regardless of attribute ordering 1`] = `""`; + +exports[`misc > Declarative API > encodes special characters 1`] = `""`; + +exports[`misc > Declarative API > only adds new tags and preserves tags when rendering additional Helmet instances 1`] = `""`; + +exports[`misc > Declarative API > only adds new tags and preserves tags when rendering additional Helmet instances 2`] = `""`; + +exports[`misc > Declarative API > only adds new tags and preserves tags when rendering additional Helmet instances 3`] = `""`; + +exports[`misc > Declarative API > only adds new tags and preserves tags when rendering additional Helmet instances 4`] = `""`; + +exports[`misc > Declarative API > only adds new tags and preserves tags when rendering additional Helmet instances 5`] = `""`; + +exports[`misc > Declarative API > recognizes valid tags regardless of attribute ordering 1`] = `""`; diff --git a/__tests__/api/__snapshots__/base.test.js.snap b/__tests__/api/__snapshots__/base.test.js.snap deleted file mode 100644 index 76328f55..00000000 --- a/__tests__/api/__snapshots__/base.test.js.snap +++ /dev/null @@ -1,5 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`base tag API sets base tag based on deepest nested component 1`] = `""`; - -exports[`base tag Declarative API sets base tag based on deepest nested component 1`] = `""`; diff --git a/__tests__/api/__snapshots__/base.test.tsx.snap b/__tests__/api/__snapshots__/base.test.tsx.snap new file mode 100644 index 00000000..d9681db6 --- /dev/null +++ b/__tests__/api/__snapshots__/base.test.tsx.snap @@ -0,0 +1,5 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`base tag > API > sets base tag based on deepest nested component 1`] = `""`; + +exports[`base tag > Declarative API > sets base tag based on deepest nested component 1`] = `""`; diff --git a/__tests__/api/__snapshots__/client.test.js.snap b/__tests__/api/__snapshots__/client.test.js.snap deleted file mode 100644 index 013561a8..00000000 --- a/__tests__/api/__snapshots__/client.test.js.snap +++ /dev/null @@ -1,17 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`onChangeClientState API when handling client state change, calls the function with new state, addedTags and removedTags 1`] = `""`; - -exports[`onChangeClientState API when handling client state change, calls the function with new state, addedTags and removedTags 2`] = `""`; - -exports[`onChangeClientState API when handling client state change, calls the function with new state, addedTags and removedTags 3`] = `""`; - -exports[`onChangeClientState API when handling client state change, calls the function with new state, addedTags and removedTags 4`] = `""`; - -exports[`onChangeClientState Declarative API when handling client state change, calls the function with new state, addedTags and removedTags 1`] = `""`; - -exports[`onChangeClientState Declarative API when handling client state change, calls the function with new state, addedTags and removedTags 2`] = `""`; - -exports[`onChangeClientState Declarative API when handling client state change, calls the function with new state, addedTags and removedTags 3`] = `""`; - -exports[`onChangeClientState Declarative API when handling client state change, calls the function with new state, addedTags and removedTags 4`] = `""`; diff --git a/__tests__/api/__snapshots__/client.test.tsx.snap b/__tests__/api/__snapshots__/client.test.tsx.snap new file mode 100644 index 00000000..2642229d --- /dev/null +++ b/__tests__/api/__snapshots__/client.test.tsx.snap @@ -0,0 +1,17 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`onChangeClientState > API > when handling client state change, calls the function with new state, addedTags and removedTags 1`] = `""`; + +exports[`onChangeClientState > API > when handling client state change, calls the function with new state, addedTags and removedTags 2`] = `""`; + +exports[`onChangeClientState > API > when handling client state change, calls the function with new state, addedTags and removedTags 3`] = `""`; + +exports[`onChangeClientState > API > when handling client state change, calls the function with new state, addedTags and removedTags 4`] = `""`; + +exports[`onChangeClientState > Declarative API > when handling client state change, calls the function with new state, addedTags and removedTags 1`] = `""`; + +exports[`onChangeClientState > Declarative API > when handling client state change, calls the function with new state, addedTags and removedTags 2`] = `""`; + +exports[`onChangeClientState > Declarative API > when handling client state change, calls the function with new state, addedTags and removedTags 3`] = `""`; + +exports[`onChangeClientState > Declarative API > when handling client state change, calls the function with new state, addedTags and removedTags 4`] = `""`; diff --git a/__tests__/api/__snapshots__/link.test.js.snap b/__tests__/api/__snapshots__/link.test.js.snap deleted file mode 100644 index 84926dff..00000000 --- a/__tests__/api/__snapshots__/link.test.js.snap +++ /dev/null @@ -1,49 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`link tags API allows duplicate link tags if specified in the same component 1`] = `""`; - -exports[`link tags API allows duplicate link tags if specified in the same component 2`] = `""`; - -exports[`link tags API does not render tag when primary attribute is null 1`] = `""`; - -exports[`link tags API overrides duplicate link tags with a single link tag in a nested component 1`] = `""`; - -exports[`link tags API overrides single link tag with duplicate link tags in a nested component 1`] = `""`; - -exports[`link tags API overrides single link tag with duplicate link tags in a nested component 2`] = `""`; - -exports[`link tags API sets link tags based on deepest nested component 1`] = `""`; - -exports[`link tags API sets link tags based on deepest nested component 2`] = `""`; - -exports[`link tags API sets link tags based on deepest nested component 3`] = `""`; - -exports[`link tags API tags 'rel' and 'href' properly use 'rel' as the primary identification for this tag, regardless of ordering 1`] = `""`; - -exports[`link tags API tags with rel='stylesheet' uses the href as the primary identification of the tag, regardless of ordering 1`] = `""`; - -exports[`link tags API tags with rel='stylesheet' uses the href as the primary identification of the tag, regardless of ordering 2`] = `""`; - -exports[`link tags Declarative API allows duplicate link tags if specified in the same component 1`] = `""`; - -exports[`link tags Declarative API allows duplicate link tags if specified in the same component 2`] = `""`; - -exports[`link tags Declarative API does not render tag when primary attribute is null 1`] = `""`; - -exports[`link tags Declarative API overrides duplicate link tags with a single link tag in a nested component 1`] = `""`; - -exports[`link tags Declarative API overrides single link tag with duplicate link tags in a nested component 1`] = `""`; - -exports[`link tags Declarative API overrides single link tag with duplicate link tags in a nested component 2`] = `""`; - -exports[`link tags Declarative API sets link tags based on deepest nested component 1`] = `""`; - -exports[`link tags Declarative API sets link tags based on deepest nested component 2`] = `""`; - -exports[`link tags Declarative API sets link tags based on deepest nested component 3`] = `""`; - -exports[`link tags Declarative API tags 'rel' and 'href' properly use 'rel' as the primary identification for this tag, regardless of ordering 1`] = `""`; - -exports[`link tags Declarative API tags with rel='stylesheet' uses the href as the primary identification of the tag, regardless of ordering 1`] = `""`; - -exports[`link tags Declarative API tags with rel='stylesheet' uses the href as the primary identification of the tag, regardless of ordering 2`] = `""`; diff --git a/__tests__/api/__snapshots__/link.test.tsx.snap b/__tests__/api/__snapshots__/link.test.tsx.snap new file mode 100644 index 00000000..370b1aa9 --- /dev/null +++ b/__tests__/api/__snapshots__/link.test.tsx.snap @@ -0,0 +1,49 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`link tags > API > allows duplicate link tags if specified in the same component 1`] = `""`; + +exports[`link tags > API > allows duplicate link tags if specified in the same component 2`] = `""`; + +exports[`link tags > API > does not render tag when primary attribute is null 1`] = `""`; + +exports[`link tags > API > overrides duplicate link tags with a single link tag in a nested component 1`] = `""`; + +exports[`link tags > API > overrides single link tag with duplicate link tags in a nested component 1`] = `""`; + +exports[`link tags > API > overrides single link tag with duplicate link tags in a nested component 2`] = `""`; + +exports[`link tags > API > sets link tags based on deepest nested component 1`] = `""`; + +exports[`link tags > API > sets link tags based on deepest nested component 2`] = `""`; + +exports[`link tags > API > sets link tags based on deepest nested component 3`] = `""`; + +exports[`link tags > API > tags 'rel' and 'href' properly use 'rel' as the primary identification for this tag, regardless of ordering 1`] = `""`; + +exports[`link tags > API > tags with rel='stylesheet' uses the href as the primary identification of the tag, regardless of ordering 1`] = `""`; + +exports[`link tags > API > tags with rel='stylesheet' uses the href as the primary identification of the tag, regardless of ordering 2`] = `""`; + +exports[`link tags > Declarative API > allows duplicate link tags if specified in the same component 1`] = `""`; + +exports[`link tags > Declarative API > allows duplicate link tags if specified in the same component 2`] = `""`; + +exports[`link tags > Declarative API > does not render tag when primary attribute is null 1`] = `""`; + +exports[`link tags > Declarative API > overrides duplicate link tags with a single link tag in a nested component 1`] = `""`; + +exports[`link tags > Declarative API > overrides single link tag with duplicate link tags in a nested component 1`] = `""`; + +exports[`link tags > Declarative API > overrides single link tag with duplicate link tags in a nested component 2`] = `""`; + +exports[`link tags > Declarative API > sets link tags based on deepest nested component 1`] = `""`; + +exports[`link tags > Declarative API > sets link tags based on deepest nested component 2`] = `""`; + +exports[`link tags > Declarative API > sets link tags based on deepest nested component 3`] = `""`; + +exports[`link tags > Declarative API > tags 'rel' and 'href' properly use 'rel' as the primary identification for this tag, regardless of ordering 1`] = `""`; + +exports[`link tags > Declarative API > tags with rel='stylesheet' uses the href as the primary identification of the tag, regardless of ordering 1`] = `""`; + +exports[`link tags > Declarative API > tags with rel='stylesheet' uses the href as the primary identification of the tag, regardless of ordering 2`] = `""`; diff --git a/__tests__/api/__snapshots__/meta.test.js.snap b/__tests__/api/__snapshots__/meta.test.js.snap deleted file mode 100644 index 93dba226..00000000 --- a/__tests__/api/__snapshots__/meta.test.js.snap +++ /dev/null @@ -1,35 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`meta tags API allows duplicate meta tags if specified in the same component 1`] = `""`; - -exports[`meta tags API allows duplicate meta tags if specified in the same component 2`] = `""`; - -exports[`meta tags API fails gracefully when meta is wrong shape 1`] = `"Helmet: meta should be of type \\"Array\\". Instead found type \\"object\\""`; - -exports[`meta tags API overrides duplicate meta tags with single meta tag in a nested component 1`] = `""`; - -exports[`meta tags API overrides single meta tag with duplicate meta tags in a nested component 1`] = `""`; - -exports[`meta tags API overrides single meta tag with duplicate meta tags in a nested component 2`] = `""`; - -exports[`meta tags API sets meta tags based on deepest nested component 1`] = `""`; - -exports[`meta tags API sets meta tags based on deepest nested component 2`] = `""`; - -exports[`meta tags API sets meta tags based on deepest nested component 3`] = `""`; - -exports[`meta tags Declarative API allows duplicate meta tags if specified in the same component 1`] = `""`; - -exports[`meta tags Declarative API allows duplicate meta tags if specified in the same component 2`] = `""`; - -exports[`meta tags Declarative API overrides duplicate meta tags with single meta tag in a nested component 1`] = `""`; - -exports[`meta tags Declarative API overrides single meta tag with duplicate meta tags in a nested component 1`] = `""`; - -exports[`meta tags Declarative API overrides single meta tag with duplicate meta tags in a nested component 2`] = `""`; - -exports[`meta tags Declarative API sets meta tags based on deepest nested component 1`] = `""`; - -exports[`meta tags Declarative API sets meta tags based on deepest nested component 2`] = `""`; - -exports[`meta tags Declarative API sets meta tags based on deepest nested component 3`] = `""`; diff --git a/__tests__/api/__snapshots__/meta.test.tsx.snap b/__tests__/api/__snapshots__/meta.test.tsx.snap new file mode 100644 index 00000000..83e3f683 --- /dev/null +++ b/__tests__/api/__snapshots__/meta.test.tsx.snap @@ -0,0 +1,35 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`meta tags > API > allows duplicate meta tags if specified in the same component 1`] = `""`; + +exports[`meta tags > API > allows duplicate meta tags if specified in the same component 2`] = `""`; + +exports[`meta tags > API > fails gracefully when meta is wrong shape 1`] = `"Helmet: meta should be of type \\"Array\\". Instead found type \\"object\\""`; + +exports[`meta tags > API > overrides duplicate meta tags with single meta tag in a nested component 1`] = `""`; + +exports[`meta tags > API > overrides single meta tag with duplicate meta tags in a nested component 1`] = `""`; + +exports[`meta tags > API > overrides single meta tag with duplicate meta tags in a nested component 2`] = `""`; + +exports[`meta tags > API > sets meta tags based on deepest nested component 1`] = `""`; + +exports[`meta tags > API > sets meta tags based on deepest nested component 2`] = `""`; + +exports[`meta tags > API > sets meta tags based on deepest nested component 3`] = `""`; + +exports[`meta tags > Declarative API > allows duplicate meta tags if specified in the same component 1`] = `""`; + +exports[`meta tags > Declarative API > allows duplicate meta tags if specified in the same component 2`] = `""`; + +exports[`meta tags > Declarative API > overrides duplicate meta tags with single meta tag in a nested component 1`] = `""`; + +exports[`meta tags > Declarative API > overrides single meta tag with duplicate meta tags in a nested component 1`] = `""`; + +exports[`meta tags > Declarative API > overrides single meta tag with duplicate meta tags in a nested component 2`] = `""`; + +exports[`meta tags > Declarative API > sets meta tags based on deepest nested component 1`] = `""`; + +exports[`meta tags > Declarative API > sets meta tags based on deepest nested component 2`] = `""`; + +exports[`meta tags > Declarative API > sets meta tags based on deepest nested component 3`] = `""`; diff --git a/__tests__/api/__snapshots__/noscript.test.js.snap b/__tests__/api/__snapshots__/noscript.test.js.snap deleted file mode 100644 index 9e1c59ae..00000000 --- a/__tests__/api/__snapshots__/noscript.test.js.snap +++ /dev/null @@ -1,5 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`noscript tags API updates noscript tags 1`] = `""`; - -exports[`noscript tags Declarative API updates noscript tags 1`] = `""`; diff --git a/__tests__/api/__snapshots__/noscript.test.tsx.snap b/__tests__/api/__snapshots__/noscript.test.tsx.snap new file mode 100644 index 00000000..d99ccac8 --- /dev/null +++ b/__tests__/api/__snapshots__/noscript.test.tsx.snap @@ -0,0 +1,5 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`noscript tags > API > updates noscript tags 1`] = `""`; + +exports[`noscript tags > Declarative API > updates noscript tags 1`] = `""`; diff --git a/__tests__/api/__snapshots__/script.test.js.snap b/__tests__/api/__snapshots__/script.test.js.snap deleted file mode 100644 index 3e2e4a4a..00000000 --- a/__tests__/api/__snapshots__/script.test.js.snap +++ /dev/null @@ -1,13 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`script tags API sets script tags based on deepest nested component 1`] = `""`; - -exports[`script tags API sets script tags based on deepest nested component 2`] = `""`; - -exports[`script tags API sets undefined attribute values to empty strings 1`] = `""`; - -exports[`script tags Declarative API sets script tags based on deepest nested component 1`] = `""`; - -exports[`script tags Declarative API sets script tags based on deepest nested component 2`] = `""`; - -exports[`script tags Declarative API sets undefined attribute values to empty strings 1`] = `""`; diff --git a/__tests__/api/__snapshots__/script.test.tsx.snap b/__tests__/api/__snapshots__/script.test.tsx.snap new file mode 100644 index 00000000..72d0db70 --- /dev/null +++ b/__tests__/api/__snapshots__/script.test.tsx.snap @@ -0,0 +1,13 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`script tags > API > sets script tags based on deepest nested component 1`] = `""`; + +exports[`script tags > API > sets script tags based on deepest nested component 2`] = `""`; + +exports[`script tags > API > sets undefined attribute values to empty strings 1`] = `""`; + +exports[`script tags > Declarative API > sets script tags based on deepest nested component 1`] = `""`; + +exports[`script tags > Declarative API > sets script tags based on deepest nested component 2`] = `""`; + +exports[`script tags > Declarative API > sets undefined attribute values to empty strings 1`] = `""`; diff --git a/__tests__/api/__snapshots__/style.test.js.snap b/__tests__/api/__snapshots__/style.test.tsx.snap similarity index 67% rename from __tests__/api/__snapshots__/style.test.js.snap rename to __tests__/api/__snapshots__/style.test.tsx.snap index d3d01962..f7fc5b2f 100644 --- a/__tests__/api/__snapshots__/style.test.js.snap +++ b/__tests__/api/__snapshots__/style.test.tsx.snap @@ -1,6 +1,6 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`Declarative API updates style tags 1`] = ` +exports[`Declarative API > updates style tags 1`] = ` "" `; -exports[`Declarative API updates style tags 2`] = ` +exports[`Declarative API > updates style tags 2`] = ` "" `; -exports[`style tags updates style tags 1`] = ` +exports[`style tags > updates style tags 1`] = ` "" `; -exports[`style tags updates style tags 2`] = ` +exports[`style tags > updates style tags 2`] = ` ""`; - -exports[`server API renders style tags as string 1`] = `""`; - -exports[`server Declarative API renders style tags as React components 1`] = `""`; - -exports[`server Declarative API renders style tags as string 1`] = `""`; diff --git a/__tests__/server/__snapshots__/style.test.tsx.snap b/__tests__/server/__snapshots__/style.test.tsx.snap new file mode 100644 index 00000000..4fb5a067 --- /dev/null +++ b/__tests__/server/__snapshots__/style.test.tsx.snap @@ -0,0 +1,9 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`server > API > renders style tags as React components 1`] = `""`; + +exports[`server > API > renders style tags as string 1`] = `""`; + +exports[`server > Declarative API > renders style tags as React components 1`] = `""`; + +exports[`server > Declarative API > renders style tags as string 1`] = `""`; diff --git a/__tests__/server/__snapshots__/title.test.js.snap b/__tests__/server/__snapshots__/title.test.js.snap deleted file mode 100644 index a77924dc..00000000 --- a/__tests__/server/__snapshots__/title.test.js.snap +++ /dev/null @@ -1,35 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`server API does not encode all characters with HTML character entity equivalents 1`] = `"膣膗 鍆錌雔"`; - -exports[`server API encodes special characters in title 1`] = `"Dangerous <script> include"`; - -exports[`server API opts out of string encoding 1`] = `"This is text and & and '."`; - -exports[`server API renders title as React component 1`] = `"Dangerous <script> include"`; - -exports[`server API renders title tag as string 1`] = `"Dangerous <script> include"`; - -exports[`server API renders title with itemprop name as React component 1`] = `"Title with Itemprop"`; - -exports[`server API renders title with itemprop name as string 1`] = `"Title with Itemprop"`; - -exports[`server Declarative API does not encode all characters with HTML character entity equivalents 1`] = `"膣膗 鍆錌雔"`; - -exports[`server Declarative API encodes special characters in title 1`] = `"Dangerous <script> include"`; - -exports[`server Declarative API opts out of string encoding 1`] = `"This is text and & and '."`; - -exports[`server Declarative API renders title and allows children containing expressions 1`] = `"Title: Some Great Title"`; - -exports[`server Declarative API renders title as React component 1`] = `"Dangerous <script> include"`; - -exports[`server Declarative API renders title tag as string 1`] = `"Dangerous <script> include"`; - -exports[`server Declarative API renders title with itemprop name as React component 1`] = `"Title with Itemprop"`; - -exports[`server Declarative API renders title with itemprop name as string 1`] = `"Title with Itemprop"`; - -exports[`server renderStatic does html encode title 1`] = `"Dangerous <script> include"`; - -exports[`server renderStatic renders title as React component 1`] = `"Dangerous <script> include"`; diff --git a/__tests__/server/__snapshots__/title.test.tsx.snap b/__tests__/server/__snapshots__/title.test.tsx.snap new file mode 100644 index 00000000..1a76da97 --- /dev/null +++ b/__tests__/server/__snapshots__/title.test.tsx.snap @@ -0,0 +1,35 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`server > API > does not encode all characters with HTML character entity equivalents 1`] = `"膣膗 鍆錌雔"`; + +exports[`server > API > encodes special characters in title 1`] = `"Dangerous <script> include"`; + +exports[`server > API > opts out of string encoding 1`] = `"This is text and & and '."`; + +exports[`server > API > renders title as React component 1`] = `"Dangerous <script> include"`; + +exports[`server > API > renders title tag as string 1`] = `"Dangerous <script> include"`; + +exports[`server > API > renders title with itemprop name as React component 1`] = `"Title with Itemprop"`; + +exports[`server > API > renders title with itemprop name as string 1`] = `"Title with Itemprop"`; + +exports[`server > Declarative API > does not encode all characters with HTML character entity equivalents 1`] = `"膣膗 鍆錌雔"`; + +exports[`server > Declarative API > encodes special characters in title 1`] = `"Dangerous <script> include"`; + +exports[`server > Declarative API > opts out of string encoding 1`] = `"This is text and & and '."`; + +exports[`server > Declarative API > renders title and allows children containing expressions 1`] = `"Title: Some Great Title"`; + +exports[`server > Declarative API > renders title as React component 1`] = `"Dangerous <script> include"`; + +exports[`server > Declarative API > renders title tag as string 1`] = `"Dangerous <script> include"`; + +exports[`server > Declarative API > renders title with itemprop name as React component 1`] = `"Title with Itemprop"`; + +exports[`server > Declarative API > renders title with itemprop name as string 1`] = `"Title with Itemprop"`; + +exports[`server > renderStatic > does html encode title 1`] = `"Dangerous <script> include"`; + +exports[`server > renderStatic > renders title as React component 1`] = `"Dangerous <script> include"`; diff --git a/__tests__/server/base.test.js b/__tests__/server/base.test.tsx similarity index 73% rename from __tests__/server/base.test.js rename to __tests__/server/base.test.tsx index 6a4743cb..0c50674e 100644 --- a/__tests__/server/base.test.js +++ b/__tests__/server/base.test.tsx @@ -2,7 +2,7 @@ import React from 'react'; import ReactServer from 'react-dom/server'; import { Helmet } from '../../src'; import Provider from '../../src/Provider'; -import { render } from './utils'; +import { renderContext, isArray } from '../utils'; Helmet.defaultProps.defer = false; @@ -14,16 +14,10 @@ afterAll(() => { Provider.canUseDOM = true; }); -const isArray = { - asymmetricMatch: actual => Array.isArray(actual), -}; - describe('server', () => { describe('API', () => { it('renders base tag as React component', () => { - const context = {}; - render(, context); - const head = context.helmet; + const head = renderContext(); expect(head.base).toBeDefined(); expect(head.base.toComponent).toBeDefined(); @@ -33,7 +27,7 @@ describe('server', () => { expect(baseComponent).toEqual(isArray); expect(baseComponent).toHaveLength(1); - baseComponent.forEach(base => { + baseComponent.forEach((base: Element) => { expect(base).toEqual(expect.objectContaining({ type: 'base' })); }); @@ -43,11 +37,7 @@ describe('server', () => { }); it('renders base tags as string', () => { - const context = {}; - render(, context); - - const head = context.helmet; - + const head = renderContext(); expect(head.base).toBeDefined(); expect(head.base.toString).toBeDefined(); expect(head.base.toString()).toMatchSnapshot(); @@ -56,16 +46,12 @@ describe('server', () => { describe('Declarative API', () => { it('renders base tag as React component', () => { - const context = {}; - render( + const head = renderContext( - , - context + ); - const head = context.helmet; - expect(head.base).toBeDefined(); expect(head.base.toComponent).toBeDefined(); @@ -74,7 +60,7 @@ describe('server', () => { expect(baseComponent).toEqual(isArray); expect(baseComponent).toHaveLength(1); - baseComponent.forEach(base => { + baseComponent.forEach((base: Element) => { expect(base).toEqual(expect.objectContaining({ type: 'base' })); }); @@ -84,16 +70,12 @@ describe('server', () => { }); it('renders base tags as string', () => { - const context = {}; - render( + const head = renderContext( - , - context + ); - const head = context.helmet; - expect(head.base).toBeDefined(); expect(head.base.toString).toBeDefined(); expect(head.base.toString()).toMatchSnapshot(); diff --git a/__tests__/server/bodyAttributes.test.js b/__tests__/server/bodyAttributes.test.tsx similarity index 75% rename from __tests__/server/bodyAttributes.test.js rename to __tests__/server/bodyAttributes.test.tsx index 9fcafca4..be9d8a9d 100644 --- a/__tests__/server/bodyAttributes.test.js +++ b/__tests__/server/bodyAttributes.test.tsx @@ -2,7 +2,7 @@ import React from 'react'; import ReactServer from 'react-dom/server'; import { Helmet } from '../../src'; import Provider from '../../src/Provider'; -import { render } from './utils'; +import { renderContext } from '../utils'; Helmet.defaultProps.defer = false; @@ -17,16 +17,12 @@ afterAll(() => { describe('server', () => { describe('Declarative API', () => { it('renders body attributes as component', () => { - const context = {}; - render( + const head = renderContext( - , - context + ); - - const { bodyAttributes } = context.helmet; - const attrs = bodyAttributes.toComponent(); + const attrs = head.bodyAttributes.toComponent(); expect(attrs).toBeDefined(); @@ -36,16 +32,12 @@ describe('server', () => { }); it('renders body attributes as string', () => { - const context = {}; - render( + const body = renderContext( - , - context + ); - const body = context.helmet; - expect(body.bodyAttributes).toBeDefined(); expect(body.bodyAttributes.toString).toBeDefined(); expect(body.bodyAttributes.toString()).toMatchSnapshot(); diff --git a/__tests__/server/helmetData.test.js b/__tests__/server/helmetData.test.tsx similarity index 81% rename from __tests__/server/helmetData.test.js rename to __tests__/server/helmetData.test.tsx index 867dcb7d..9458e249 100644 --- a/__tests__/server/helmetData.test.js +++ b/__tests__/server/helmetData.test.tsx @@ -1,18 +1,12 @@ -import React, { StrictMode } from 'react'; -import ReactDOM from 'react-dom'; +import React from 'react'; import { Helmet } from '../../src'; import Provider from '../../src/Provider'; import HelmetData from '../../src/HelmetData'; import { HELMET_ATTRIBUTE } from '../../src/constants'; +import { render } from '../utils'; Helmet.defaultProps.defer = false; -const render = node => { - const mount = document.getElementById('mount'); - - ReactDOM.render({node}, mount); -}; - describe('Helmet Data', () => { describe('server', () => { beforeAll(() => { @@ -75,7 +69,7 @@ describe('Helmet Data', () => { }); it('works with the same context object but separate HelmetData instances', () => { - const context = {}; + const context = {} as any; render(
@@ -104,15 +98,15 @@ describe('Helmet Data', () => { ); - const existingTags = document.head.querySelectorAll(`base[${HELMET_ATTRIBUTE}]`); - const firstTag = [].slice.call(existingTags)[0]; + const existingTags = [...document.head.querySelectorAll(`base[${HELMET_ATTRIBUTE}]`)]; + const [firstTag] = existingTags; expect(existingTags).toBeDefined(); expect(existingTags).toHaveLength(1); expect(firstTag).toBeInstanceOf(Element); expect(firstTag.getAttribute).toBeDefined(); - expect(firstTag.getAttribute('href')).toBe('http://localhost/'); + expect(firstTag).toHaveAttribute('href', 'http://localhost/'); expect(firstTag.outerHTML).toMatchSnapshot(); }); @@ -125,15 +119,15 @@ describe('Helmet Data', () => { ); - const existingTags = document.head.querySelectorAll(`base[${HELMET_ATTRIBUTE}]`); - const firstTag = [].slice.call(existingTags)[0]; + const existingTags = [...document.head.querySelectorAll(`base[${HELMET_ATTRIBUTE}]`)]; + const [firstTag] = existingTags; expect(existingTags).toBeDefined(); expect(existingTags).toHaveLength(1); expect(firstTag).toBeInstanceOf(Element); expect(firstTag.getAttribute).toBeDefined(); - expect(firstTag.getAttribute('href')).toBe('http://localhost/'); + expect(firstTag).toHaveAttribute('href', 'http://localhost/'); expect(firstTag.outerHTML).toMatchSnapshot(); }); @@ -151,15 +145,15 @@ describe('Helmet Data', () => {
); - const existingTags = document.head.querySelectorAll(`base[${HELMET_ATTRIBUTE}]`); - const firstTag = [].slice.call(existingTags)[0]; + const existingTags = [...document.head.querySelectorAll(`base[${HELMET_ATTRIBUTE}]`)]; + const [firstTag] = existingTags; expect(existingTags).toBeDefined(); expect(existingTags).toHaveLength(1); expect(firstTag).toBeInstanceOf(Element); expect(firstTag.getAttribute).toBeDefined(); - expect(firstTag.getAttribute('href')).toBe('http://mysite.com/public'); + expect(firstTag).toHaveAttribute('href', 'http://mysite.com/public'); expect(firstTag.outerHTML).toMatchSnapshot(); }); }); diff --git a/__tests__/server/htmlAttributes.test.js b/__tests__/server/htmlAttributes.test.tsx similarity index 74% rename from __tests__/server/htmlAttributes.test.js rename to __tests__/server/htmlAttributes.test.tsx index 871b7f15..59f54072 100644 --- a/__tests__/server/htmlAttributes.test.js +++ b/__tests__/server/htmlAttributes.test.tsx @@ -2,7 +2,7 @@ import React from 'react'; import ReactServer from 'react-dom/server'; import { Helmet } from '../../src'; import Provider from '../../src/Provider'; -import { render } from './utils'; +import { renderContext } from '../utils'; Helmet.defaultProps.defer = false; @@ -17,19 +17,16 @@ afterAll(() => { describe('server', () => { describe('API', () => { it('renders html attributes as component', () => { - const context = {}; - render( + const head = renderContext( , - context + /> ); - const { htmlAttributes } = context.helmet; - const attrs = htmlAttributes.toComponent(); + const attrs = head.htmlAttributes.toComponent(); expect(attrs).toBeDefined(); @@ -39,19 +36,15 @@ describe('server', () => { }); it('renders html attributes as string', () => { - const context = {}; - render( + const head = renderContext( , - context + /> ); - const head = context.helmet; - expect(head.htmlAttributes).toBeDefined(); expect(head.htmlAttributes.toString).toBeDefined(); expect(head.htmlAttributes.toString()).toMatchSnapshot(); @@ -60,16 +53,13 @@ describe('server', () => { describe('Declarative API', () => { it('renders html attributes as component', () => { - const context = {}; - render( + const head = renderContext( - , - context + ); - const { htmlAttributes } = context.helmet; - const attrs = htmlAttributes.toComponent(); + const attrs = head.htmlAttributes.toComponent(); expect(attrs).toBeDefined(); @@ -79,16 +69,12 @@ describe('server', () => { }); it('renders html attributes as string', () => { - const context = {}; - render( + const head = renderContext( - , - context + ); - const head = context.helmet; - expect(head.htmlAttributes).toBeDefined(); expect(head.htmlAttributes.toString).toBeDefined(); expect(head.htmlAttributes.toString()).toMatchSnapshot(); diff --git a/__tests__/server/link.test.js b/__tests__/server/link.test.tsx similarity index 81% rename from __tests__/server/link.test.js rename to __tests__/server/link.test.tsx index 32efeaec..1281c90d 100644 --- a/__tests__/server/link.test.js +++ b/__tests__/server/link.test.tsx @@ -2,7 +2,7 @@ import React from 'react'; import ReactServer from 'react-dom/server'; import { Helmet } from '../../src'; import Provider from '../../src/Provider'; -import { render } from './utils'; +import { renderContext, isArray } from '../utils'; Helmet.defaultProps.defer = false; @@ -14,15 +14,10 @@ afterAll(() => { Provider.canUseDOM = true; }); -const isArray = { - asymmetricMatch: actual => Array.isArray(actual), -}; - describe('server', () => { describe('API', () => { it('renders link tags as React components', () => { - const context = {}; - render( + const head = renderContext( { type: 'text/css', }, ]} - />, - context + /> ); - const head = context.helmet; - expect(head.link).toBeDefined(); expect(head.link.toComponent).toBeDefined(); @@ -46,7 +38,7 @@ describe('server', () => { expect(linkComponent).toEqual(isArray); expect(linkComponent).toHaveLength(2); - linkComponent.forEach(link => { + linkComponent.forEach((link: Element) => { expect(link).toEqual(expect.objectContaining({ type: 'link' })); }); @@ -56,8 +48,7 @@ describe('server', () => { }); it('renders link tags as string', () => { - const context = {}; - render( + const head = renderContext( { type: 'text/css', }, ]} - />, - context + /> ); - const head = context.helmet; - expect(head.link).toBeDefined(); expect(head.link.toString).toBeDefined(); expect(head.link.toString()).toMatchSnapshot(); @@ -81,17 +69,13 @@ describe('server', () => { describe('Declarative API', () => { it('renders link tags as React components', () => { - const context = {}; - render( + const head = renderContext( - , - context + ); - const head = context.helmet; - expect(head.link).toBeDefined(); expect(head.link.toComponent).toBeDefined(); @@ -100,7 +84,7 @@ describe('server', () => { expect(linkComponent).toEqual(isArray); expect(linkComponent).toHaveLength(2); - linkComponent.forEach(link => { + linkComponent.forEach((link: Element) => { expect(link).toEqual(expect.objectContaining({ type: 'link' })); }); @@ -110,17 +94,13 @@ describe('server', () => { }); it('renders link tags as string', () => { - const context = {}; - render( + const head = renderContext( - , - context + ); - const head = context.helmet; - expect(head.link).toBeDefined(); expect(head.link.toString).toBeDefined(); expect(head.link.toString()).toMatchSnapshot(); diff --git a/__tests__/server/meta.test.js b/__tests__/server/meta.test.tsx similarity index 84% rename from __tests__/server/meta.test.js rename to __tests__/server/meta.test.tsx index a62fe3f8..a2ebb06d 100644 --- a/__tests__/server/meta.test.js +++ b/__tests__/server/meta.test.tsx @@ -2,7 +2,7 @@ import React from 'react'; import ReactServer from 'react-dom/server'; import { Helmet } from '../../src'; import Provider from '../../src/Provider'; -import { render } from './utils'; +import { renderContext, isArray } from '../utils'; Helmet.defaultProps.defer = false; @@ -14,15 +14,10 @@ afterAll(() => { Provider.canUseDOM = true; }); -const isArray = { - asymmetricMatch: actual => Array.isArray(actual), -}; - describe('server', () => { describe('API', () => { it('renders meta tags as React components', () => { - const context = {}; - render( + const head = renderContext( { { property: 'og:type', content: 'article' }, { itemprop: 'name', content: 'Test name itemprop' }, ]} - />, - context + /> ); - const head = context.helmet; - expect(head.meta).toBeDefined(); expect(head.meta.toComponent).toBeDefined(); @@ -48,7 +40,7 @@ describe('server', () => { expect(metaComponent).toEqual(isArray); expect(metaComponent).toHaveLength(5); - metaComponent.forEach(meta => { + metaComponent.forEach((meta: Element) => { expect(meta).toEqual(expect.objectContaining({ type: 'meta' })); }); @@ -58,8 +50,7 @@ describe('server', () => { }); it('renders meta tags as string', () => { - const context = {}; - render( + const head = renderContext( { { property: 'og:type', content: 'article' }, { itemprop: 'name', content: 'Test name itemprop' }, ]} - />, - context + /> ); - const head = context.helmet; - expect(head.meta).toBeDefined(); expect(head.meta.toString).toBeDefined(); expect(head.meta.toString()).toMatchSnapshot(); @@ -85,8 +73,7 @@ describe('server', () => { describe('Declarative API', () => { it('renders meta tags as React components', () => { - const context = {}; - render( + const head = renderContext( { - , - context + ); - const head = context.helmet; - expect(head.meta).toBeDefined(); expect(head.meta.toComponent).toBeDefined(); @@ -110,7 +94,7 @@ describe('server', () => { expect(metaComponent).toEqual(isArray); expect(metaComponent).toHaveLength(5); - metaComponent.forEach(meta => { + metaComponent.forEach((meta: Element) => { expect(meta).toEqual(expect.objectContaining({ type: 'meta' })); }); @@ -120,8 +104,7 @@ describe('server', () => { }); it('renders meta tags as string', () => { - const context = {}; - render( + const head = renderContext( { - , - context + ); - const head = context.helmet; - expect(head.meta).toBeDefined(); expect(head.meta.toString).toBeDefined(); expect(head.meta.toString()).toMatchSnapshot(); diff --git a/__tests__/server/noscript.test.js b/__tests__/server/noscript.test.tsx similarity index 83% rename from __tests__/server/noscript.test.js rename to __tests__/server/noscript.test.tsx index 5430591b..ff93fdcd 100644 --- a/__tests__/server/noscript.test.js +++ b/__tests__/server/noscript.test.tsx @@ -2,7 +2,7 @@ import React from 'react'; import ReactServer from 'react-dom/server'; import { Helmet } from '../../src'; import Provider from '../../src/Provider'; -import { render } from './utils'; +import { renderContext, isArray } from '../utils'; Helmet.defaultProps.defer = false; @@ -14,15 +14,10 @@ afterAll(() => { Provider.canUseDOM = true; }); -const isArray = { - asymmetricMatch: actual => Array.isArray(actual), -}; - describe('server', () => { describe('API', () => { it('renders noscript tags as React components', () => { - const context = {}; - render( + const head = renderContext( { innerHTML: '', }, ]} - />, - context + /> ); - const head = context.helmet; - expect(head.noscript).toBeDefined(); expect(head.noscript.toComponent).toBeDefined(); @@ -48,7 +40,7 @@ describe('server', () => { expect(noscriptComponent).toEqual(isArray); expect(noscriptComponent).toHaveLength(2); - noscriptComponent.forEach(noscript => { + noscriptComponent.forEach((noscript: Element) => { expect(noscript).toEqual(expect.objectContaining({ type: 'noscript' })); }); @@ -60,17 +52,13 @@ describe('server', () => { describe('Declarative API', () => { it('renders noscript tags as React components', () => { - const context = {}; - render( + const head = renderContext( - , - context + ); - const head = context.helmet; - expect(head.noscript).toBeDefined(); expect(head.noscript.toComponent).toBeDefined(); @@ -79,7 +67,7 @@ describe('server', () => { expect(noscriptComponent).toEqual(isArray); expect(noscriptComponent).toHaveLength(2); - noscriptComponent.forEach(noscript => { + noscriptComponent.forEach((noscript: Element) => { expect(noscript).toEqual(expect.objectContaining({ type: 'noscript' })); }); diff --git a/__tests__/server/script.test.js b/__tests__/server/script.test.tsx similarity index 81% rename from __tests__/server/script.test.js rename to __tests__/server/script.test.tsx index 3f697728..e3dca01b 100644 --- a/__tests__/server/script.test.js +++ b/__tests__/server/script.test.tsx @@ -2,7 +2,7 @@ import React from 'react'; import ReactServer from 'react-dom/server'; import { Helmet } from '../../src'; import Provider from '../../src/Provider'; -import { render } from './utils'; +import { renderContext, isArray } from '../utils'; Helmet.defaultProps.defer = false; @@ -14,15 +14,10 @@ afterAll(() => { Provider.canUseDOM = true; }); -const isArray = { - asymmetricMatch: actual => Array.isArray(actual), -}; - describe('server', () => { describe('API', () => { it('renders script tags as React components', () => { - const context = {}; - render( + const head = renderContext( { type: 'text/javascript', }, ]} - />, - context + /> ); - const head = context.helmet; - expect(head.script).toBeDefined(); expect(head.script.toComponent).toBeDefined(); @@ -48,7 +40,7 @@ describe('server', () => { expect(scriptComponent).toEqual(isArray); expect(scriptComponent).toHaveLength(2); - scriptComponent.forEach(script => { + scriptComponent.forEach((script: Element) => { expect(script).toEqual(expect.objectContaining({ type: 'script' })); }); @@ -58,8 +50,7 @@ describe('server', () => { }); it('renders script tags as string', () => { - const context = {}; - render( + const head = renderContext( { type: 'text/javascript', }, ]} - />, - context + /> ); - const head = context.helmet; - expect(head.script).toBeDefined(); expect(head.script.toString).toBeDefined(); expect(head.script.toString()).toMatchSnapshot(); @@ -85,17 +73,13 @@ describe('server', () => { describe('Declarative API', () => { it('renders script tags as React components', () => { - const context = {}; - render( + const head = renderContext(