From 34131cdfcc3c4001834e3f2e394b88023d200af0 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sun, 8 Oct 2023 22:18:34 -0500 Subject: [PATCH] Convert all tests to ESM --- src/actions/accounts.test.ts | 4 +- src/actions/announcements.test.ts | 3 +- src/actions/blocks.test.ts | 8 +- src/actions/preload.test.ts | 4 +- src/actions/rules.test.ts | 2 +- src/actions/status-quotes.test.ts | 8 +- src/actions/statuses.test.ts | 6 +- src/components/ui/icon/svg-icon.test.tsx | 5 +- .../components/notification.test.tsx | 44 +++++----- src/normalizers/account.test.ts | 86 +++++++++---------- src/normalizers/instance.test.ts | 41 +++++---- .../soapbox/soapbox-config.test.ts | 5 +- src/normalizers/status.test.ts | 40 ++++----- src/reducers/announcements.test.ts | 2 +- src/reducers/auth.test.ts | 6 +- src/reducers/compose.test.ts | 24 ++++-- src/reducers/instance.test.ts | 22 +++-- src/reducers/statuses.test.ts | 42 ++++----- src/schemas/group.test.ts | 4 +- src/schemas/poll.test.ts | 8 +- src/utils/status.test.ts | 4 +- 21 files changed, 192 insertions(+), 176 deletions(-) diff --git a/src/actions/accounts.test.ts b/src/actions/accounts.test.ts index 3d0c4deb8..0f6af8cb0 100644 --- a/src/actions/accounts.test.ts +++ b/src/actions/accounts.test.ts @@ -98,8 +98,8 @@ describe('fetchAccount()', () => { }); }); - describe('with a successful API request', () => { - const account = require('soapbox/__fixtures__/pleroma-account.json'); + describe('with a successful API request', async () => { + const account = await import('soapbox/__fixtures__/pleroma-account.json'); beforeEach(() => { const state = rootState; diff --git a/src/actions/announcements.test.ts b/src/actions/announcements.test.ts index 5295873cd..e90dbca77 100644 --- a/src/actions/announcements.test.ts +++ b/src/actions/announcements.test.ts @@ -1,5 +1,6 @@ import { List as ImmutableList } from 'immutable'; +import announcements from 'soapbox/__fixtures__/announcements.json'; import { fetchAnnouncements, dismissAnnouncement, addReaction, removeReaction } from 'soapbox/actions/announcements'; import { __stub } from 'soapbox/api'; import { buildInstance } from 'soapbox/jest/factory'; @@ -8,8 +9,6 @@ import { normalizeAnnouncement } from 'soapbox/normalizers'; import type { APIEntity } from 'soapbox/types/entities'; -const announcements = require('soapbox/__fixtures__/announcements.json'); - describe('fetchAnnouncements()', () => { describe('with a successful API request', () => { it('should fetch announcements from the API', async() => { diff --git a/src/actions/blocks.test.ts b/src/actions/blocks.test.ts index bfa67c4be..4c96052df 100644 --- a/src/actions/blocks.test.ts +++ b/src/actions/blocks.test.ts @@ -35,8 +35,8 @@ describe('fetchBlocks()', () => { }); describe('with a successful API request', () => { - beforeEach(() => { - const blocks = require('soapbox/__fixtures__/blocks.json'); + beforeEach(async () => { + const blocks = await import('soapbox/__fixtures__/blocks.json'); __stub((mock) => { mock.onGet('/api/v1/blocks').reply(200, blocks, { @@ -132,8 +132,8 @@ describe('expandBlocks()', () => { }); describe('with a successful API request', () => { - beforeEach(() => { - const blocks = require('soapbox/__fixtures__/blocks.json'); + beforeEach(async () => { + const blocks = await import('soapbox/__fixtures__/blocks.json'); __stub((mock) => { mock.onGet('example').reply(200, blocks, { diff --git a/src/actions/preload.test.ts b/src/actions/preload.test.ts index 029a8a833..8e4b30f5c 100644 --- a/src/actions/preload.test.ts +++ b/src/actions/preload.test.ts @@ -11,8 +11,8 @@ import { } from './preload'; describe('preloadMastodon()', () => { - it('creates the expected actions', () => { - const data = require('soapbox/__fixtures__/mastodon_initial_state.json'); + it('creates the expected actions', async () => { + const data = await import('soapbox/__fixtures__/mastodon_initial_state.json'); __stub(mock => { mock.onGet('/api/v1/accounts/verify_credentials') diff --git a/src/actions/rules.test.ts b/src/actions/rules.test.ts index d25b54dbd..5fd32c6fe 100644 --- a/src/actions/rules.test.ts +++ b/src/actions/rules.test.ts @@ -5,7 +5,7 @@ import { fetchRules, RULES_FETCH_REQUEST, RULES_FETCH_SUCCESS } from './rules'; describe('fetchRules()', () => { it('sets the rules', async () => { - const rules = require('soapbox/__fixtures__/rules.json'); + const rules = await import('soapbox/__fixtures__/rules.json'); __stub((mock) => { mock.onGet('/api/v1/instance/rules').reply(200, rules); diff --git a/src/actions/status-quotes.test.ts b/src/actions/status-quotes.test.ts index 1e18904a3..85edb8994 100644 --- a/src/actions/status-quotes.test.ts +++ b/src/actions/status-quotes.test.ts @@ -31,8 +31,8 @@ describe('fetchStatusQuotes()', () => { }); describe('with a successful API request', () => { - beforeEach(() => { - const quotes = require('soapbox/__fixtures__/status-quotes.json'); + beforeEach(async () => { + const quotes = await import('soapbox/__fixtures__/status-quotes.json'); __stub((mock) => { mock.onGet(`/api/v1/pleroma/statuses/${statusId}/quotes`).reply(200, quotes, { @@ -103,8 +103,8 @@ describe('expandStatusQuotes()', () => { }); describe('with a successful API request', () => { - beforeEach(() => { - const quotes = require('soapbox/__fixtures__/status-quotes.json'); + beforeEach(async () => { + const quotes = await import('soapbox/__fixtures__/status-quotes.json'); __stub((mock) => { mock.onGet('example').reply(200, quotes, { diff --git a/src/actions/statuses.test.ts b/src/actions/statuses.test.ts index 8004a47ca..ba2200480 100644 --- a/src/actions/statuses.test.ts +++ b/src/actions/statuses.test.ts @@ -9,7 +9,7 @@ import { deleteStatus, fetchContext } from './statuses'; describe('fetchContext()', () => { it('handles Mitra context', async () => { - const statuses = require('soapbox/__fixtures__/mitra-context.json'); + const statuses = await import('soapbox/__fixtures__/mitra-context.json'); __stub(mock => { mock.onGet('/api/v1/statuses/017ed505-5926-392f-256a-f86d5075df70/context') @@ -60,8 +60,8 @@ describe('deleteStatus()', () => { describe('with a successful API request', () => { let status: any; - beforeEach(() => { - status = require('soapbox/__fixtures__/pleroma-status-deleted.json'); + beforeEach(async () => { + status = await import('soapbox/__fixtures__/pleroma-status-deleted.json'); __stub((mock) => { mock.onDelete(`/api/v1/statuses/${statusId}`).reply(200, status); diff --git a/src/components/ui/icon/svg-icon.test.tsx b/src/components/ui/icon/svg-icon.test.tsx index b00380ddf..8dc01be21 100644 --- a/src/components/ui/icon/svg-icon.test.tsx +++ b/src/components/ui/icon/svg-icon.test.tsx @@ -1,3 +1,4 @@ +import IconCode from '@tabler/icons/code.svg'; import React from 'react'; import { render, screen } from 'soapbox/jest/test-helpers'; @@ -5,8 +6,8 @@ import { render, screen } from 'soapbox/jest/test-helpers'; import SvgIcon from './svg-icon'; describe('', () => { - it('renders loading element with default size', () => { - render(); + it('renders loading element with default size', async () => { + render(); const svg = screen.getByTestId('svg-icon-loader'); expect(svg.getAttribute('width')).toBe('24'); diff --git a/src/features/notifications/components/notification.test.tsx b/src/features/notifications/components/notification.test.tsx index 31d43e23a..7a99bdb6c 100644 --- a/src/features/notifications/components/notification.test.tsx +++ b/src/features/notifications/components/notification.test.tsx @@ -19,8 +19,8 @@ const normalize = (notification: any) => { }; describe('', () => { - it('renders a follow notification', async() => { - const { notification, state } = normalize(require('soapbox/__fixtures__/notification-follow.json')); + it('renders a follow notification', async () => { + const { notification, state } = normalize(await import('soapbox/__fixtures__/notification-follow.json')); render(, undefined, state); @@ -30,9 +30,9 @@ describe('', () => { }); describe('grouped notifications', () => { - it('renders a grouped follow notification for more than 2', async() => { + it('renders a grouped follow notification for more than 2', async () => { const { notification, state } = normalize({ - ...require('soapbox/__fixtures__/notification-follow.json'), + ...await import('soapbox/__fixtures__/notification-follow.json'), total_count: 5, }); @@ -43,9 +43,9 @@ describe('', () => { expect(screen.getByTestId('message')).toHaveTextContent('Nekobit + 4 others followed you'); }); - it('renders a grouped follow notification for 1', async() => { + it('renders a grouped follow notification for 1', async () => { const { notification, state } = normalize({ - ...require('soapbox/__fixtures__/notification-follow.json'), + ...await import('soapbox/__fixtures__/notification-follow.json'), total_count: 2, }); @@ -57,8 +57,8 @@ describe('', () => { }); }); - it('renders a favourite notification', async() => { - const { notification, state } = normalize(require('soapbox/__fixtures__/notification-favourite.json')); + it('renders a favourite notification', async () => { + const { notification, state } = normalize(await import('soapbox/__fixtures__/notification-favourite.json')); render(, undefined, state); @@ -66,8 +66,8 @@ describe('', () => { expect(screen.getByTestId('status')).toContainHTML('https://media.gleasonator.com'); }); - // it('renders a follow_request notification', async() => { - // const { notification, state } = normalize(require('soapbox/__fixtures__/notification-follow_request.json')); + // it('renders a follow_request notification', async () => { + // const { notification, state } = normalize(await import('soapbox/__fixtures__/notification-follow_request.json')); // render(, undefined, state); @@ -75,8 +75,8 @@ describe('', () => { // expect(screen.getByTestId('account')).toContainHTML('alex@spinster.xyz'); // }); - it('renders a mention notification', async() => { - const { notification, state } = normalize(require('soapbox/__fixtures__/notification-mention.json')); + it('renders a mention notification', async () => { + const { notification, state } = normalize(await import('soapbox/__fixtures__/notification-mention.json')); render(, undefined, state); @@ -84,8 +84,8 @@ describe('', () => { expect(screen.getByTestId('status')).toContainHTML('ActivityPub spec'); }); - it('renders a move notification', async() => { - const { notification, state } = normalize(require('soapbox/__fixtures__/notification-move.json')); + it('renders a move notification', async () => { + const { notification, state } = normalize(await import('soapbox/__fixtures__/notification-move.json')); render(, undefined, state); @@ -93,8 +93,8 @@ describe('', () => { expect(screen.getByTestId('account')).toContainHTML('benis911'); }); - it('renders a pleroma:emoji_reaction notification', async() => { - const { notification, state } = normalize(require('soapbox/__fixtures__/notification-pleroma-emoji_reaction.json')); + it('renders a pleroma:emoji_reaction notification', async () => { + const { notification, state } = normalize(await import('soapbox/__fixtures__/notification-pleroma-emoji_reaction.json')); render(, undefined, state); @@ -102,16 +102,16 @@ describe('', () => { expect(screen.getByTestId('status')).toContainHTML('Super Mario 64'); }); - it('renders a pleroma:chat_mention notification', async() => { - const { notification, state } = normalize(require('soapbox/__fixtures__/notification-pleroma-chat_mention.json')); + it('renders a pleroma:chat_mention notification', async () => { + const { notification, state } = normalize(await import('soapbox/__fixtures__/notification-pleroma-chat_mention.json')); render(, undefined, state); expect(screen.getByTestId('notification')).toContainHTML('dave'); }); - it('renders a poll notification', async() => { - const { notification, state } = normalize(require('soapbox/__fixtures__/notification-poll.json')); + it('renders a poll notification', async () => { + const { notification, state } = normalize(await import('soapbox/__fixtures__/notification-poll.json')); render(, undefined, state); @@ -119,8 +119,8 @@ describe('', () => { expect(screen.getByTestId('status')).toContainHTML('what do you guys think?'); }); - it('renders a reblog notification', async() => { - const { notification, state } = normalize(require('soapbox/__fixtures__/notification-reblog.json')); + it('renders a reblog notification', async () => { + const { notification, state } = normalize(await import('soapbox/__fixtures__/notification-reblog.json')); render(, undefined, state); diff --git a/src/normalizers/account.test.ts b/src/normalizers/account.test.ts index 219d2399c..15a26ecdc 100644 --- a/src/normalizers/account.test.ts +++ b/src/normalizers/account.test.ts @@ -1,9 +1,9 @@ import { Record as ImmutableRecord, fromJS } from 'immutable'; -import { normalizeAccount } from './account'; +import AVATAR_MISSING from 'soapbox/assets/images/avatar-missing.png'; +import HEADER_MISSING from 'soapbox/assets/images/header-missing.png'; -const AVATAR_MISSING = require('soapbox/assets/images/avatar-missing.png'); -const HEADER_MISSING = require('soapbox/assets/images/header-missing.png'); +import { normalizeAccount } from './account'; describe('normalizeAccount()', () => { it('adds base fields', () => { @@ -33,29 +33,29 @@ describe('normalizeAccount()', () => { expect(result.verified).toBe(false); }); - it('normalizes Fedibird birthday', () => { - const account = require('soapbox/__fixtures__/fedibird-account.json'); + it('normalizes Fedibird birthday', async () => { + const account = await import('soapbox/__fixtures__/fedibird-account.json'); const result = normalizeAccount(account); expect(result.birthday).toEqual('1993-07-03'); }); - it('normalizes Pleroma birthday', () => { - const account = require('soapbox/__fixtures__/pleroma-account.json'); + it('normalizes Pleroma birthday', async () => { + const account = await import('soapbox/__fixtures__/pleroma-account.json'); const result = normalizeAccount(account); expect(result.birthday).toEqual('1993-07-03'); }); - it('normalizes undefined birthday to empty string', () => { - const account = require('soapbox/__fixtures__/mastodon-account.json'); + it('normalizes undefined birthday to empty string', async () => { + const account = await import('soapbox/__fixtures__/mastodon-account.json'); const result = normalizeAccount(account); expect(result.birthday).toEqual(''); }); - it('normalizes Pleroma legacy fields', () => { - const account = require('soapbox/__fixtures__/pleroma-2.2.2-account.json'); + it('normalizes Pleroma legacy fields', async () => { + const account = await import('soapbox/__fixtures__/pleroma-2.2.2-account.json'); const result = normalizeAccount(account); expect(result.getIn(['pleroma', 'is_active'])).toBe(true); @@ -65,8 +65,8 @@ describe('normalizeAccount()', () => { expect(result.hasIn(['pleroma', 'confirmation_pending'])).toBe(false); }); - it('prefers new Pleroma fields', () => { - const account = require('soapbox/__fixtures__/pleroma-account.json'); + it('prefers new Pleroma fields', async () => { + const account = await import('soapbox/__fixtures__/pleroma-account.json'); const result = normalizeAccount(account); expect(result.getIn(['pleroma', 'is_active'])).toBe(true); @@ -74,38 +74,38 @@ describe('normalizeAccount()', () => { expect(result.getIn(['pleroma', 'is_approved'])).toBe(true); }); - it('normalizes a verified Pleroma user', () => { - const account = require('soapbox/__fixtures__/mk.json'); + it('normalizes a verified Pleroma user', async () => { + const account = await import('soapbox/__fixtures__/mk.json'); const result = normalizeAccount(account); expect(result.verified).toBe(true); }); - it('normalizes an unverified Pleroma user', () => { - const account = require('soapbox/__fixtures__/pleroma-account.json'); + it('normalizes an unverified Pleroma user', async () => { + const account = await import('soapbox/__fixtures__/pleroma-account.json'); const result = normalizeAccount(account); expect(result.verified).toBe(false); }); - it('normalizes a verified Truth Social user', () => { - const account = require('soapbox/__fixtures__/realDonaldTrump.json'); + it('normalizes a verified Truth Social user', async () => { + const account = await import('soapbox/__fixtures__/realDonaldTrump.json'); const result = normalizeAccount(account); expect(result.verified).toBe(true); }); - it('normalizes Fedibird location', () => { - const account = require('soapbox/__fixtures__/fedibird-account.json'); + it('normalizes Fedibird location', async () => { + const account = await import('soapbox/__fixtures__/fedibird-account.json'); const result = normalizeAccount(account); expect(result.location).toBe('Texas, USA'); }); - it('normalizes Truth Social location', () => { - const account = require('soapbox/__fixtures__/truthsocial-account.json'); + it('normalizes Truth Social location', async () => { + const account = await import('soapbox/__fixtures__/truthsocial-account.json'); const result = normalizeAccount(account); expect(result.location).toBe('Texas'); }); - it('normalizes Truth Social website', () => { - const account = require('soapbox/__fixtures__/truthsocial-account.json'); + it('normalizes Truth Social website', async () => { + const account = await import('soapbox/__fixtures__/truthsocial-account.json'); const result = normalizeAccount(account); expect(result.website).toBe('https://soapbox.pub'); }); @@ -128,27 +128,27 @@ describe('normalizeAccount()', () => { expect(result.display_name).toBe('alex'); }); - it('emojifies display name as `display_name_html`', () => { - const account = require('soapbox/__fixtures__/account-with-emojis.json'); + it('emojifies display name as `display_name_html`', async () => { + const account = await import('soapbox/__fixtures__/account-with-emojis.json'); const result = normalizeAccount(account); expect(result.display_name_html).toContain('emojione'); }); - it('emojifies note as `note_emojified`', () => { - const account = require('soapbox/__fixtures__/account-with-emojis.json'); + it('emojifies note as `note_emojified`', async () => { + const account = await import('soapbox/__fixtures__/account-with-emojis.json'); const result = normalizeAccount(account); expect(result.note_emojified).toContain('emojione'); }); - it('unescapes HTML note as `note_plain`', () => { - const account = require('soapbox/__fixtures__/account-with-emojis.json'); + it('unescapes HTML note as `note_plain`', async () => { + const account = await import('soapbox/__fixtures__/account-with-emojis.json'); const result = normalizeAccount(account); const expected = 'I create Fediverse software that empowers people online. :soapbox:\n\nI\'m vegan btw\n\nNote: If you have a question for me, please tag me publicly. This gives the opportunity for others to chime in, and bystanders to learn.'; expect(result.note_plain).toBe(expected); }); - it('emojifies custom profile field', () => { - const account = require('soapbox/__fixtures__/account-with-emojis.json'); + it('emojifies custom profile field', async () => { + const account = await import('soapbox/__fixtures__/account-with-emojis.json'); const result = normalizeAccount(account); const field = result.fields.get(1); @@ -157,8 +157,8 @@ describe('normalizeAccount()', () => { expect(field?.value_plain).toBe('https://soapbox.pub :soapbox:'); }); - it('adds default avatar and banner to GoToSocial account', () => { - const account = require('soapbox/__fixtures__/gotosocial-account.json'); + it('adds default avatar and banner to GoToSocial account', async () => { + const account = await import('soapbox/__fixtures__/gotosocial-account.json'); const result = normalizeAccount(account); expect(result.avatar).toEqual(AVATAR_MISSING); @@ -167,15 +167,15 @@ describe('normalizeAccount()', () => { expect(result.header_static).toEqual(HEADER_MISSING); }); - it('adds fqn to Mastodon account', () => { - const account = require('soapbox/__fixtures__/mastodon-account.json'); + it('adds fqn to Mastodon account', async () => { + const account = await import('soapbox/__fixtures__/mastodon-account.json'); const result = normalizeAccount(account); expect(result.fqn).toEqual('benis911@mastodon.social'); }); - it('normalizes Pleroma staff', () => { - const account = require('soapbox/__fixtures__/pleroma-account.json'); + it('normalizes Pleroma staff', async () => { + const account = await import('soapbox/__fixtures__/pleroma-account.json'); const result = normalizeAccount(account); expect(result.admin).toBe(true); @@ -183,15 +183,15 @@ describe('normalizeAccount()', () => { expect(result.moderator).toBe(false); }); - it('normalizes Pleroma favicon', () => { - const account = require('soapbox/__fixtures__/pleroma-account.json'); + it('normalizes Pleroma favicon', async () => { + const account = await import('soapbox/__fixtures__/pleroma-account.json'); const result = normalizeAccount(account); expect(result.favicon).toEqual('https://gleasonator.com/favicon.png'); }); - it('adds account domain', () => { - const account = require('soapbox/__fixtures__/pleroma-account.json'); + it('adds account domain', async () => { + const account = await import('soapbox/__fixtures__/pleroma-account.json'); const result = normalizeAccount(account); expect(result.domain).toEqual('gleasonator.com'); diff --git a/src/normalizers/instance.test.ts b/src/normalizers/instance.test.ts index 1319aaf5d..46793dfaf 100644 --- a/src/normalizers/instance.test.ts +++ b/src/normalizers/instance.test.ts @@ -72,8 +72,8 @@ describe('normalizeInstance()', () => { expect(result.toJS()).toEqual(expected); }); - it('normalizes Pleroma instance with Mastodon configuration format', () => { - const instance = require('soapbox/__fixtures__/pleroma-instance.json'); + it('normalizes Pleroma instance with Mastodon configuration format', async () => { + const instance = await import('soapbox/__fixtures__/pleroma-instance.json'); const expected = { configuration: { @@ -94,8 +94,8 @@ describe('normalizeInstance()', () => { expect(result.toJS()).toMatchObject(expected); }); - it('normalizes Mastodon instance with retained configuration', () => { - const instance = require('soapbox/__fixtures__/mastodon-instance.json'); + it('normalizes Mastodon instance with retained configuration', async () => { + const instance = await import('soapbox/__fixtures__/mastodon-instance.json'); const expected = { configuration: { @@ -124,8 +124,8 @@ describe('normalizeInstance()', () => { expect(result.toJS()).toMatchObject(expected); }); - it('normalizes Mastodon 3.0.0 instance with default configuration', () => { - const instance = require('soapbox/__fixtures__/mastodon-3.0.0-instance.json'); + it('normalizes Mastodon 3.0.0 instance with default configuration', async () => { + const instance = await import('soapbox/__fixtures__/mastodon-3.0.0-instance.json'); const expected = { configuration: { @@ -146,8 +146,8 @@ describe('normalizeInstance()', () => { expect(result.toJS()).toMatchObject(expected); }); - it('normalizes Fedibird instance', () => { - const instance = require('soapbox/__fixtures__/fedibird-instance.json'); + it('normalizes Fedibird instance', async () => { + const instance = await import('soapbox/__fixtures__/fedibird-instance.json'); const result = normalizeInstance(instance); // Sets description_limit @@ -157,8 +157,8 @@ describe('normalizeInstance()', () => { expect(result.fedibird_capabilities).toEqual(fromJS(instance.fedibird_capabilities)); }); - it('normalizes Mitra instance', () => { - const instance = require('soapbox/__fixtures__/mitra-instance.json'); + it('normalizes Mitra instance', async () => { + const instance = await import('soapbox/__fixtures__/mitra-instance.json'); const result = normalizeInstance(instance); // Adds configuration and description_limit @@ -166,8 +166,8 @@ describe('normalizeInstance()', () => { expect(result.get('description_limit')).toBe(1500); }); - it('normalizes GoToSocial instance', () => { - const instance = require('soapbox/__fixtures__/gotosocial-instance.json'); + it('normalizes GoToSocial instance', async () => { + const instance = await import('soapbox/__fixtures__/gotosocial-instance.json'); const result = normalizeInstance(instance); // Normalizes max_toot_chars @@ -179,8 +179,8 @@ describe('normalizeInstance()', () => { expect(result.get('description_limit')).toBe(1500); }); - it('normalizes Friendica instance', () => { - const instance = require('soapbox/__fixtures__/friendica-instance.json'); + it('normalizes Friendica instance', async () => { + const instance = await import('soapbox/__fixtures__/friendica-instance.json'); const result = normalizeInstance(instance); // Normalizes max_toot_chars @@ -192,24 +192,23 @@ describe('normalizeInstance()', () => { expect(result.get('description_limit')).toBe(1500); }); - it('normalizes a Mastodon RC version', () => { - const instance = require('soapbox/__fixtures__/mastodon-instance-rc.json'); + it('normalizes a Mastodon RC version', async () => { + const instance = await import('soapbox/__fixtures__/mastodon-instance-rc.json'); const result = normalizeInstance(instance); expect(result.version).toEqual('3.5.0-rc1'); }); - it('normalizes Pixelfed instance', () => { - const instance = require('soapbox/__fixtures__/pixelfed-instance.json'); + it('normalizes Pixelfed instance', async () => { + const instance = await import('soapbox/__fixtures__/pixelfed-instance.json'); const result = normalizeInstance(instance); expect(result.title).toBe('pixelfed'); }); - it('renames Akkoma to Pleroma', () => { - const instance = require('soapbox/__fixtures__/akkoma-instance.json'); + it('renames Akkoma to Pleroma', async () => { + const instance = await import('soapbox/__fixtures__/akkoma-instance.json'); const result = normalizeInstance(instance); expect(result.version).toEqual('2.7.2 (compatible; Pleroma 2.4.50+akkoma)'); - }); }); diff --git a/src/normalizers/soapbox/soapbox-config.test.ts b/src/normalizers/soapbox/soapbox-config.test.ts index 2b96d6678..e142c09d7 100644 --- a/src/normalizers/soapbox/soapbox-config.test.ts +++ b/src/normalizers/soapbox/soapbox-config.test.ts @@ -28,8 +28,9 @@ describe('normalizeSoapboxConfig()', () => { expect(result.toJS()).toMatchObject(expected); }); - it('normalizes promoPanel', () => { - const result = normalizeSoapboxConfig(require('soapbox/__fixtures__/spinster-soapbox.json')); + it('normalizes promoPanel', async () => { + const soapboxConfig = await import('soapbox/__fixtures__/spinster-soapbox.json'); + const result = normalizeSoapboxConfig(soapboxConfig); expect(ImmutableRecord.isRecord(result.promoPanel)).toBe(true); expect(ImmutableRecord.isRecord(result.promoPanel.items.get(0))).toBe(true); expect(result.promoPanel.items.get(2)?.icon).toBe('question-circle'); diff --git a/src/normalizers/status.test.ts b/src/normalizers/status.test.ts index 4ffd82f5d..e5bf6b2c8 100644 --- a/src/normalizers/status.test.ts +++ b/src/normalizers/status.test.ts @@ -18,8 +18,8 @@ describe('normalizeStatus()', () => { expect(result.visibility).toBe('public'); }); - it('fixes the order of mentions', () => { - const status = require('soapbox/__fixtures__/status-unordered-mentions.json'); + it('fixes the order of mentions', async () => { + const status = await import('soapbox/__fixtures__/status-unordered-mentions.json'); const expected = ['NEETzsche', 'alex', 'Lumeinshin', 'sneeden']; @@ -31,8 +31,8 @@ describe('normalizeStatus()', () => { expect(result).toEqual(expected); }); - it('adds mention to self in self-reply on Mastodon', () => { - const status = require('soapbox/__fixtures__/mastodon-reply-to-self.json'); + it('adds mention to self in self-reply on Mastodon', async () => { + const status = await import('soapbox/__fixtures__/mastodon-reply-to-self.json'); const expected = { id: '106801667066418367', @@ -64,8 +64,8 @@ describe('normalizeStatus()', () => { expect(result.toJS()).toEqual(expected); }); - it('normalizes Mitra attachments', () => { - const status = require('soapbox/__fixtures__/mitra-status-with-attachments.json'); + it('normalizes Mitra attachments', async () => { + const status = await import('soapbox/__fixtures__/mitra-status-with-attachments.json'); const expected = [{ id: '017eeb0e-e5df-30a4-77a7-a929145cb836', @@ -98,8 +98,8 @@ describe('normalizeStatus()', () => { expect(result.media_attachments.toJS()).toMatchObject(expected); }); - it('leaves Pleroma attachments alone', () => { - const status = require('soapbox/__fixtures__/pleroma-status-with-attachments.json'); + it('leaves Pleroma attachments alone', async () => { + const status = await import('soapbox/__fixtures__/pleroma-status-with-attachments.json'); const result = normalizeStatus(status).media_attachments; expect(result.size).toBe(4); @@ -108,16 +108,16 @@ describe('normalizeStatus()', () => { expect(ImmutableRecord.isRecord(result.get(3))).toBe(true); }); - it('normalizes Pleroma quote post', () => { - const status = require('soapbox/__fixtures__/pleroma-quote-post.json'); + it('normalizes Pleroma quote post', async () => { + const status = await import('soapbox/__fixtures__/pleroma-quote-post.json'); const result = normalizeStatus(status); expect(result.quote).toEqual(fromJS(status.pleroma.quote)); expect(result.pleroma.get('quote')).toBe(undefined); }); - it('normalizes GoToSocial status', () => { - const status = require('soapbox/__fixtures__/gotosocial-status.json'); + it('normalizes GoToSocial status', async () => { + const status = await import('soapbox/__fixtures__/gotosocial-status.json'); const result = normalizeStatus(status); // Adds missing fields @@ -132,8 +132,8 @@ describe('normalizeStatus()', () => { expect(result).toMatchObject(missing); }); - it('normalizes Friendica status', () => { - const status = require('soapbox/__fixtures__/friendica-status.json'); + it('normalizes Friendica status', async () => { + const status = await import('soapbox/__fixtures__/friendica-status.json'); const result = normalizeStatus(status); // Adds missing fields @@ -168,8 +168,8 @@ describe('normalizeStatus()', () => { expect(poll).toMatchObject(expected); }); - it('normalizes a Pleroma logged-out poll', () => { - const status = require('soapbox/__fixtures__/pleroma-status-with-poll.json'); + it('normalizes a Pleroma logged-out poll', async () => { + const status = await import('soapbox/__fixtures__/pleroma-status-with-poll.json'); const result = normalizeStatus(status); const poll = result.poll as Poll; @@ -178,8 +178,8 @@ describe('normalizeStatus()', () => { expect(poll.own_votes).toBe(null); }); - it('normalizes poll with emojis', () => { - const status = require('soapbox/__fixtures__/pleroma-status-with-poll-with-emojis.json'); + it('normalizes poll with emojis', async () => { + const status = await import('soapbox/__fixtures__/pleroma-status-with-poll-with-emojis.json'); const result = normalizeStatus(status); const poll = result.poll as Poll; @@ -190,8 +190,8 @@ describe('normalizeStatus()', () => { expect(poll.emojis[1].shortcode).toEqual('soapbox'); }); - it('normalizes a card', () => { - const status = require('soapbox/__fixtures__/status-with-card.json'); + it('normalizes a card', async () => { + const status = await import('soapbox/__fixtures__/status-with-card.json'); const result = normalizeStatus(status); const card = result.card as Card; diff --git a/src/reducers/announcements.test.ts b/src/reducers/announcements.test.ts index f1299a816..70358f333 100644 --- a/src/reducers/announcements.test.ts +++ b/src/reducers/announcements.test.ts @@ -1,5 +1,6 @@ import { List as ImmutableList, Record as ImmutableRecord, Set as ImmutableSet } from 'immutable'; +import announcements from 'soapbox/__fixtures__/announcements.json'; import { ANNOUNCEMENTS_FETCH_SUCCESS, ANNOUNCEMENTS_UPDATE, @@ -7,7 +8,6 @@ import { import reducer from './announcements'; -const announcements = require('soapbox/__fixtures__/announcements.json'); describe('accounts reducer', () => { it('should return the initial state', () => { diff --git a/src/reducers/auth.test.ts b/src/reducers/auth.test.ts index 927db942b..fbee6005f 100644 --- a/src/reducers/auth.test.ts +++ b/src/reducers/auth.test.ts @@ -317,10 +317,12 @@ describe('auth reducer', () => { }); describe('MASTODON_PRELOAD_IMPORT', () => { - it('imports the user and token', () => { + it('imports the user and token', async () => { + const data = await import('soapbox/__fixtures__/mastodon_initial_state.json'); + const action = { type: MASTODON_PRELOAD_IMPORT, - data: require('soapbox/__fixtures__/mastodon_initial_state.json'), + data, }; const expected = { diff --git a/src/reducers/compose.test.ts b/src/reducers/compose.test.ts index 456860f05..c13e0bd4a 100644 --- a/src/reducers/compose.test.ts +++ b/src/reducers/compose.test.ts @@ -39,11 +39,13 @@ describe('compose reducer', () => { }); describe('COMPOSE_SET_STATUS', () => { - it('strips Pleroma integer attachments', () => { + it('strips Pleroma integer attachments', async () => { + const status = await import('soapbox/__fixtures__/pleroma-status-deleted.json'); + const action = { type: actions.COMPOSE_SET_STATUS, id: 'compose-modal', - status: normalizeStatus(fromJS(require('soapbox/__fixtures__/pleroma-status-deleted.json'))), + status: normalizeStatus(fromJS(status)), v: { software: 'Pleroma' }, withRedraft: true, }; @@ -52,35 +54,41 @@ describe('compose reducer', () => { expect(result.get('compose-modal')!.media_attachments.isEmpty()).toBe(true); }); - it('leaves non-Pleroma integer attachments alone', () => { + it('leaves non-Pleroma integer attachments alone', async () => { + const status = await import('soapbox/__fixtures__/pleroma-status-deleted.json'); + const action = { type: actions.COMPOSE_SET_STATUS, id: 'compose-modal', - status: normalizeStatus(fromJS(require('soapbox/__fixtures__/pleroma-status-deleted.json'))), + status: normalizeStatus(fromJS(status)), }; const result = reducer(undefined, action as any); expect(result.get('compose-modal')!.media_attachments.getIn([0, 'id'])).toEqual('508107650'); }); - it('sets the id when editing a post', () => { + it('sets the id when editing a post', async () => { + const status = await import('soapbox/__fixtures__/pleroma-status-deleted.json'); + const action = { id: 'compose-modal', withRedraft: false, type: actions.COMPOSE_SET_STATUS, - status: normalizeStatus(fromJS(require('soapbox/__fixtures__/pleroma-status-deleted.json'))), + status: normalizeStatus(fromJS(status)), }; const result = reducer(undefined, action as any); expect(result.get('compose-modal')!.id).toEqual('AHU2RrX0wdcwzCYjFQ'); }); - it('does not set the id when redrafting a post', () => { + it('does not set the id when redrafting a post', async () => { + const status = await import('soapbox/__fixtures__/pleroma-status-deleted.json'); + const action = { id: 'compose-modal', withRedraft: true, type: actions.COMPOSE_SET_STATUS, - status: normalizeStatus(fromJS(require('soapbox/__fixtures__/pleroma-status-deleted.json'))), + status: normalizeStatus(fromJS(status)), }; const result = reducer(undefined, action as any); diff --git a/src/reducers/instance.test.ts b/src/reducers/instance.test.ts index 93a06ee06..183b8ba38 100644 --- a/src/reducers/instance.test.ts +++ b/src/reducers/instance.test.ts @@ -32,10 +32,12 @@ describe('instance reducer', () => { }); describe('rememberInstance.fulfilled', () => { - it('normalizes Pleroma instance with Mastodon configuration format', () => { + it('normalizes Pleroma instance with Mastodon configuration format', async () => { + const payload = await import('soapbox/__fixtures__/pleroma-instance.json'); + const action = { type: rememberInstance.fulfilled.type, - payload: require('soapbox/__fixtures__/pleroma-instance.json'), + payload, }; const result = reducer(undefined, action); @@ -58,10 +60,12 @@ describe('instance reducer', () => { expect(result).toMatchObject(expected); }); - it('normalizes Mastodon instance with retained configuration', () => { + it('normalizes Mastodon instance with retained configuration', async () => { + const payload = await import('soapbox/__fixtures__/mastodon-instance.json'); + const action = { type: rememberInstance.fulfilled.type, - payload: require('soapbox/__fixtures__/mastodon-instance.json'), + payload, }; const result = reducer(undefined, action); @@ -92,10 +96,12 @@ describe('instance reducer', () => { expect(result).toMatchObject(expected); }); - it('normalizes Mastodon 3.0.0 instance with default configuration', () => { + it('normalizes Mastodon 3.0.0 instance with default configuration', async () => { + const payload = await import('soapbox/__fixtures__/mastodon-3.0.0-instance.json'); + const action = { type: rememberInstance.fulfilled.type, - payload: require('soapbox/__fixtures__/mastodon-3.0.0-instance.json'), + payload, }; const result = reducer(undefined, action); @@ -119,8 +125,8 @@ describe('instance reducer', () => { }); }); - describe('ADMIN_CONFIG_UPDATE_REQUEST', () => { - const { configs } = require('soapbox/__fixtures__/pleroma-admin-config.json'); + describe('ADMIN_CONFIG_UPDATE_REQUEST', async () => { + const { configs } = await import('soapbox/__fixtures__/pleroma-admin-config.json'); it('imports the configs', () => { const action = { diff --git a/src/reducers/statuses.test.ts b/src/reducers/statuses.test.ts index 01923d134..824e53e56 100644 --- a/src/reducers/statuses.test.ts +++ b/src/reducers/statuses.test.ts @@ -20,16 +20,16 @@ describe('statuses reducer', () => { }); describe('STATUS_IMPORT', () => { - it('parses the status as a Record', () => { - const status = require('soapbox/__fixtures__/pleroma-quote-post.json'); + it('parses the status as a Record', async () => { + const status = await import('soapbox/__fixtures__/pleroma-quote-post.json'); const action = { type: STATUS_IMPORT, status }; const result = reducer(undefined, action).get('AFmFMSpITT9xcOJKcK'); expect(ImmutableRecord.isRecord(result)).toBe(true); }); - it('fixes the order of mentions', () => { - const status = require('soapbox/__fixtures__/status-unordered-mentions.json'); + it('fixes the order of mentions', async () => { + const status = await import('soapbox/__fixtures__/status-unordered-mentions.json'); const action = { type: STATUS_IMPORT, status }; const expected = ['NEETzsche', 'alex', 'Lumeinshin', 'sneeden']; @@ -42,9 +42,9 @@ describe('statuses reducer', () => { expect(result).toEqual(expected); }); - it('preserves the quote', () => { - const quotePost = require('soapbox/__fixtures__/pleroma-quote-post.json'); - const quotedQuotePost = require('soapbox/__fixtures__/pleroma-quote-of-quote-post.json'); + it('preserves the quote', async () => { + const quotePost = await import('soapbox/__fixtures__/pleroma-quote-post.json'); + const quotedQuotePost = await import('soapbox/__fixtures__/pleroma-quote-of-quote-post.json'); let state = undefined; state = reducer(state, { type: STATUS_IMPORT, status: quotePost }); @@ -53,8 +53,8 @@ describe('statuses reducer', () => { expect(state.getIn(['AFmFMSpITT9xcOJKcK', 'quote'])).toEqual('AFmFLcd6XYVdjWCrOS'); }); - it('normalizes Mitra attachments', () => { - const status = require('soapbox/__fixtures__/mitra-status-with-attachments.json'); + it('normalizes Mitra attachments', async () => { + const status = await import('soapbox/__fixtures__/mitra-status-with-attachments.json'); const state = reducer(undefined, { type: STATUS_IMPORT, status }); @@ -87,8 +87,8 @@ describe('statuses reducer', () => { expect(state.get('017eeb0e-e5e7-98fe-6b2b-ad02349251fb')?.media_attachments.toJS()).toMatchObject(expected); }); - it('fixes Pleroma attachments', () => { - const status = require('soapbox/__fixtures__/pleroma-status-with-attachments.json'); + it('fixes Pleroma attachments', async () => { + const status = await import('soapbox/__fixtures__/pleroma-status-with-attachments.json'); const action = { type: STATUS_IMPORT, status }; const state = reducer(undefined, action); const result = state.get('AGNkA21auFR5lnEAHw')?.media_attachments; @@ -98,24 +98,24 @@ describe('statuses reducer', () => { expect(result?.getIn([1, 'pleroma', 'mime_type'])).toBe('application/x-nes-rom'); }); - it('hides CWs', () => { - const status = require('soapbox/__fixtures__/status-cw.json'); + it('hides CWs', async () => { + const status = await import('soapbox/__fixtures__/status-cw.json'); const action = { type: STATUS_IMPORT, status }; const hidden = reducer(undefined, action).getIn(['107831528995252317', 'hidden']); expect(hidden).toBe(true); }); - it('expands CWs when expandSpoilers is enabled', () => { - const status = require('soapbox/__fixtures__/status-cw.json'); + it('expands CWs when expandSpoilers is enabled', async () => { + const status = await import('soapbox/__fixtures__/status-cw.json'); const action = { type: STATUS_IMPORT, status, expandSpoilers: true }; const hidden = reducer(undefined, action).getIn(['107831528995252317', 'hidden']); expect(hidden).toBe(false); }); - it('parses custom emojis', () => { - const status = require('soapbox/__fixtures__/status-custom-emoji.json'); + it('parses custom emojis', async () => { + const status = await import('soapbox/__fixtures__/status-custom-emoji.json'); const action = { type: STATUS_IMPORT, status }; const expected = 'Hello :ablobcathyper: :ageblobcat: 😂 world 😋 test :blobcatphoto:'; @@ -124,8 +124,8 @@ describe('statuses reducer', () => { expect(result).toBe(expected); }); - it('builds search_index', () => { - const status = require('soapbox/__fixtures__/status-with-poll.json'); + it('builds search_index', async () => { + const status = await import('soapbox/__fixtures__/status-with-poll.json'); const action = { type: STATUS_IMPORT, status }; const expected = `What is tolerance? @@ -138,8 +138,8 @@ Promoting free speech, even for people and ideas you dislike`; expect(result).toEqual(expected); }); - it('builds search_index with mentions', () => { - const status = require('soapbox/__fixtures__/pleroma-status-reply-with-mentions.json'); + it('builds search_index with mentions', async () => { + const status = await import('soapbox/__fixtures__/pleroma-status-reply-with-mentions.json'); const action = { type: STATUS_IMPORT, status }; const expected = `DMs are definitely only federated to the servers of the recipients tho. So if I DM a kfcc user, the kfcc admins can see it, but no other instance admins can. diff --git a/src/schemas/group.test.ts b/src/schemas/group.test.ts index 5e37acfd2..b227ad856 100644 --- a/src/schemas/group.test.ts +++ b/src/schemas/group.test.ts @@ -1,7 +1,7 @@ import { groupSchema } from './group'; -test('groupSchema with a TruthSocial group', () => { - const data = require('soapbox/__fixtures__/group-truthsocial.json'); +test('groupSchema with a TruthSocial group', async () => { + const data = await import('soapbox/__fixtures__/group-truthsocial.json'); const group = groupSchema.parse(data); expect(group.display_name_html).toEqual('PATRIOT PATRIOTS'); }); \ No newline at end of file diff --git a/src/schemas/poll.test.ts b/src/schemas/poll.test.ts index ceff672aa..88deca8db 100644 --- a/src/schemas/poll.test.ts +++ b/src/schemas/poll.test.ts @@ -22,8 +22,8 @@ describe('normalizePoll()', () => { expect(result).toMatchObject(expected); }); - it('normalizes a Pleroma logged-out poll', () => { - const { poll } = require('soapbox/__fixtures__/pleroma-status-with-poll.json'); + it('normalizes a Pleroma logged-out poll', async () => { + const { poll } = await import('soapbox/__fixtures__/pleroma-status-with-poll.json'); const result = pollSchema.parse(poll); // Adds logged-in fields @@ -31,8 +31,8 @@ describe('normalizePoll()', () => { expect(result.own_votes).toBe(null); }); - it('normalizes poll with emojis', () => { - const { poll } = require('soapbox/__fixtures__/pleroma-status-with-poll-with-emojis.json'); + it('normalizes poll with emojis', async () => { + const { poll } = await import('soapbox/__fixtures__/pleroma-status-with-poll-with-emojis.json'); const result = pollSchema.parse(poll); // Emojifies poll options diff --git a/src/utils/status.test.ts b/src/utils/status.test.ts index 2528781fe..4cdb8f8f5 100644 --- a/src/utils/status.test.ts +++ b/src/utils/status.test.ts @@ -7,8 +7,8 @@ import { } from './status'; describe('hasIntegerMediaIds()', () => { - it('returns true for a Pleroma deleted status', () => { - const status = buildStatus(require('soapbox/__fixtures__/pleroma-status-deleted.json')); + it('returns true for a Pleroma deleted status', async () => { + const status = buildStatus(await import('soapbox/__fixtures__/pleroma-status-deleted.json') as any); expect(hasIntegerMediaIds(status)).toBe(true); }); });