0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00

refactor: remove unused patches (#6179)

This commit is contained in:
Gao Sun 2024-07-08 13:15:34 +08:00 committed by GitHub
parent a5fd7ff506
commit 164c42054a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 182 additions and 270 deletions

View file

@ -80,7 +80,7 @@
"i18next-browser-languagedetector": "^8.0.0",
"identity-obj-proxy": "^3.0.0",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.0.0",
"jest-environment-jsdom": "^29.7.0",
"jest-transform-stub": "^2.0.0",
"jest-transformer-svg": "^2.0.0",
"just-kebab-case": "^4.2.0",

View file

@ -62,7 +62,7 @@
"i18next-browser-languagedetector": "^8.0.0",
"identity-obj-proxy": "^3.0.0",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.0.0",
"jest-environment-jsdom": "^29.7.0",
"jest-transform-stub": "^2.0.0",
"jest-transformer-svg": "^2.0.0",
"js-base64": "^3.7.5",

View file

@ -5,15 +5,15 @@ import { getCountryList } from '@/utils/country-code';
import CountryCodeDropdown from '.';
// Need to mock the scrollIntoView method because jsdom doesn't support it
// eslint-disable-next-line @silverhand/fp/no-mutation
Element.prototype.scrollIntoView = jest.fn();
jest.mock('i18next', () => ({
language: 'en',
t: (key: string) => key,
}));
// Need to mock the scrollIntoView method because jsdom doesn't support it
// eslint-disable-next-line @silverhand/fp/no-mutation
Element.prototype.scrollIntoView = jest.fn();
describe('CountryCodeDropdown', () => {
const onChange = jest.fn();
const onClose = jest.fn();

View file

@ -47,7 +47,7 @@ const useSendVerificationCode = (flow: UserFlow, replaceCurrentPage?: boolean) =
navigate(
{
pathname: `/${flow}/verification-code`,
search: location.search,
search: window.location.search,
},
{
replace: replaceCurrentPage,

View file

@ -1,26 +1,8 @@
// https://jestjs.io/docs/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom
import { type LocalePhrase } from '@logto/phrases-experience';
import { type DeepPartial } from '@silverhand/essentials';
import i18next from 'i18next';
import { initReactI18next } from 'react-i18next';
// eslint-disable-next-line @silverhand/fp/no-mutating-methods
Object.defineProperty(window, 'matchMedia', {
writable: true,
value: jest.fn().mockImplementation((query) => ({
matches: false,
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
media: query,
onchange: null,
addListener: jest.fn(), // Deprecated
removeListener: jest.fn(), // Deprecated
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
dispatchEvent: jest.fn(),
})),
});
// Simple resources for testing
const defaultI18nResources: DeepPartial<LocalePhrase> = {
translation: { action: { agree: 'Agree' } },

View file

@ -38,19 +38,30 @@ const useParams = useParamsMock as jest.Mock;
const assign = jest.fn();
const replace = jest.fn();
const search = jest.fn();
const originalLocation = window.location;
const originalSearch = window.location.search;
// eslint-disable-next-line @silverhand/fp/no-mutating-methods
Object.defineProperty(window, 'location', {
value: {
assign,
replace,
},
writable: true,
beforeAll(() => {
// eslint-disable-next-line @silverhand/fp/no-mutating-methods
Object.defineProperty(window, 'location', {
value: {
assign,
replace,
},
writable: true,
});
// eslint-disable-next-line @silverhand/fp/no-mutating-methods
Object.defineProperty(window.location, 'search', {
get: search,
});
});
// eslint-disable-next-line @silverhand/fp/no-mutating-methods
Object.defineProperty(window.location, 'search', {
get: search,
afterAll(() => {
// eslint-disable-next-line @silverhand/fp/no-mutating-methods
Object.defineProperty(window, 'location', {
value: originalLocation,
});
});
describe('DirectSignIn', () => {

View file

@ -30,6 +30,7 @@ describe('ForgotPasswordForm', () => {
const email = 'foo@logto.io';
const countryCode = '86';
const phone = '13911111111';
const originalLocation = window.location;
const renderForm = (defaultType: VerificationCodeIdentifier, defaultValue?: string) =>
renderWithPageContext(
@ -42,6 +43,13 @@ describe('ForgotPasswordForm', () => {
</UserInteractionContextProvider>
);
afterEach(() => {
// eslint-disable-next-line @silverhand/fp/no-mutating-methods
Object.defineProperty(window, 'location', {
value: originalLocation,
});
});
describe.each([
{ identifier: SignInIdentifier.Email, value: email },
{ identifier: SignInIdentifier.Phone, value: `${countryCode}${phone}` },

View file

@ -11,15 +11,15 @@ import SocialLanding from '.';
describe(`SocialLanding Page`, () => {
const replace = jest.fn();
const callbackLink = 'logto:logto.android.com';
const redirectUri = 'http://www.github.com';
const originalLocation = window.location;
it('Should set session storage and redirect', async () => {
const callbackLink = 'logto:logto.android.com';
const redirectUri = 'http://www.github.com';
beforeAll(() => {
/* eslint-disable @silverhand/fp/no-mutating-methods */
Object.defineProperty(window, 'location', {
value: {
origin,
origin: 'http://localhost',
href: `/social/landing?`,
search: queryStringify({
[SearchParameters.RedirectTo]: redirectUri,
@ -29,7 +29,16 @@ describe(`SocialLanding Page`, () => {
},
});
/* eslint-enable @silverhand/fp/no-mutating-methods */
});
afterAll(() => {
// eslint-disable-next-line @silverhand/fp/no-mutating-methods
Object.defineProperty(window, 'location', {
value: originalLocation,
});
});
it('Should set session storage and redirect', async () => {
renderWithPageContext(
<SettingsProvider>
<Routes>

View file

@ -1,14 +1,11 @@
import dotenv from 'dotenv';
import { setDefaultOptions } from 'expect-puppeteer';
import { TextDecoder, TextEncoder } from 'text-encoder';
const { jest } = import.meta;
dotenv.config();
/* eslint-disable @silverhand/fp/no-mutation */
global.TextDecoder = TextDecoder;
global.TextEncoder = TextEncoder;
global.fail = (message) => {
throw new Error(message);
};

View file

@ -47,7 +47,6 @@
"openapi-types": "^12.1.3",
"prettier": "^3.0.0",
"puppeteer": "^22.6.5",
"text-encoder": "^0.0.4",
"typescript": "^5.3.3",
"zod": "^3.22.4"
},

File diff suppressed because it is too large Load diff