Skip to content

Commit

Permalink
Merge pull request #83 from the-collab-lab/firebase-hosting-fix
Browse files Browse the repository at this point in the history
Remove manual chunks
  • Loading branch information
ahsanatzapier authored Oct 19, 2024
2 parents 69c1c17 + 3158b6a commit a7faf05
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 32 deletions.
42 changes: 25 additions & 17 deletions tests/List.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { render, screen } from '@testing-library/react';
import { MemoryRouter } from 'react-router-dom';
import { List } from '../src/views/List';
import { mockShoppingListData } from '../src/mocks/__fixtures__/shoppingListData';
import { useStateWithStorage, useEnsureListPath } from '../src/hooks';
import {
useStateWithStorage,
useEnsureListPath,
useUrgency,
} from '../src/hooks';
import {
getDateLastPurchasedOrDateCreated,
getDaysFromDate,
Expand All @@ -12,20 +16,7 @@ import {
vi.mock('../src/hooks', () => ({
useEnsureListPath: vi.fn(),
useStateWithStorage: vi.fn(),
useUrgency: vi.fn(() => ({
getUrgency: vi.fn((name) => {
if (name === 'nutella') return 'soon';
if (name === 'Cheese') return 'overdue';
return 'notSoon';
}),
urgencyObject: {
overdue: [{ name: 'nutella', id: '0T1ByXr8YJSOzujOlLMI' }],
soon: [{ name: 'Cheese', id: '1MFWOWMCzDtEHQboFZfR' }],
kindOfSoon: [],
notSoon: [{ name: 'Jam', id: 'MnUiYUmhg8iCzX1eMxW8' }],
inactive: [],
},
})),
useUrgency: vi.fn(),
}));

vi.mock('../src/utils', () => ({
Expand All @@ -36,6 +27,7 @@ vi.mock('../src/utils', () => ({
}));

beforeEach(() => {
vi.clearAllMocks();
Object.defineProperty(window, 'localStorage', {
value: {
getItem: vi.fn((key) => {
Expand All @@ -52,6 +44,21 @@ beforeEach(() => {

vi.spyOn(window, 'alert').mockImplementation(() => {});
useStateWithStorage.mockReturnValue(['/groceries']);
useEnsureListPath.mockReturnValue(false);
useUrgency.mockReturnValue({
getUrgency: vi.fn((name) => {
if (name === 'nutella') return 'soon';
if (name === 'Cheese') return 'overdue';
return 'notSoon';
}),
urgencyObject: {
overdue: [{ name: 'nutella', id: '0T1ByXr8YJSOzujOlLMI' }],
soon: [{ name: 'Cheese', id: '1MFWOWMCzDtEHQboFZfR' }],
kindOfSoon: [],
notSoon: [{ name: 'Jam', id: 'MnUiYUmhg8iCzX1eMxW8' }],
inactive: [],
},
});
getDateLastPurchasedOrDateCreated.mockReturnValue(new Date());
getDaysFromDate.mockReturnValue(10);
getDaysBetweenDates.mockReturnValue(5);
Expand Down Expand Up @@ -81,6 +88,9 @@ describe('List Component', () => {
);

expect(screen.getByText('Welcome to groceries!')).toBeInTheDocument();
expect(
screen.getByText('Ready to add your first item? Start adding below!'),
).toBeInTheDocument();
expect(screen.getByLabelText('Item Name:')).toBeInTheDocument();
expect(screen.getByLabelText('Soon')).toBeInTheDocument();
expect(screen.getByLabelText('Kind of soon')).toBeInTheDocument();
Expand All @@ -89,8 +99,6 @@ describe('List Component', () => {
});

test('triggers alert and redirects when no list path is found in localStorage', () => {
window.localStorage.getItem.mockReturnValueOnce(null);

useEnsureListPath.mockImplementation(() => {
window.alert(
'It seems like you landed here without first creating a list or selecting an existing one. Please select or create a new list first. Redirecting to Home.',
Expand Down
16 changes: 1 addition & 15 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,7 @@ export default defineConfig(({ mode }) => ({
build: {
outDir: './build',
target: 'esnext',
rollupOptions: {
output: {
manualChunks: (id) => {
if (id.includes('node_modules')) {
if (id.includes('react')) {
return 'vendor__react';
}
if (id.includes('firebase')) {
return 'vendor__firebase';
}
return 'vendor';
}
},
},
},
rollupOptions: {},
},
plugins: [
mode === 'development' && eslint(),
Expand Down

0 comments on commit a7faf05

Please sign in to comment.