Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Reduce build size #951

Merged
merged 6 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions frontend/craco.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,32 @@ module.exports = {
// See https://github.com/alex3165/react-mapbox-gl/issues/931
// See https://github.com/mapbox/mapbox-gl-js/issues/10565
// eslint-disable-next-line import/no-webpack-loader-syntax
ignore: ['./node_modules/maplibre-gl/dist/maplibre-gl.js'],
},
ignore: ['./node_modules/maplibre-gl/dist/maplibre-gl.js']
}
},
typescript: {
// Disable type checking by react-scripts because it takes tsconfig.json
// blindlessly, and compiles tests and mocks, although it should not.
// Instead, we manually compile with tsconfig.build.json,
// as we would do using vite.
enableTypeChecking: false
},
jest: {
configure(config) {
config.rootDir = '.';
config.setupFiles = ['<rootDir>/jest.polyfills.js'];
config.setupFilesAfterEnv = [
'jest-extended/all',
'<rootDir>/src/setupTests.ts',
'<rootDir>/src/setupTests.ts'
];
config.testTimeout = 30_000;
config.transformIgnorePatterns = [
'<rootDir>/node_modules/(?!@codegouvfr)/.+\\.js$',
'<rootDir>/node_modules/.store/(?!@codegouvfr)/.+\\.js$',
'<rootDir>/node_modules/.store/(?!@codegouvfr)/.+\\.js$'
];
config.moduleNameMapper['^@zerologementvacant/models/fixtures$'] =
'<rootDir>/node_modules/@zerologementvacant/models/dist/test/fixtures.js';
return config;
},
},
}
}
};
3 changes: 2 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"scripts": {
"clean": "rimraf build",
"icons": "only-include-used-icons",
"build": "yarn clean && yarn icons && DISABLE_ESLINT_PLUGIN=true craco build",
"build": "yarn clean && yarn icons && tsc -b tsconfig.build.json && DISABLE_ESLINT_PLUGIN=true craco build",
"dev": "yarn icons && DISABLE_ESLINT_PLUGIN=true craco start",
"test": "DISABLE_ESLINT_PLUGIN=true craco test",
"postinstall": "copy-dsfr-to-public"
Expand Down Expand Up @@ -93,6 +93,7 @@
"jest-fetch-mock": "^3.0.3",
"jest-watch-typeahead": "^2.2.2",
"randomstring": "^1.3.0",
"react-dev-utils": "^12.0.1",
"rimraf": "^5.0.10",
"sass": "^1.79.4",
"typescript": "^5.6.2",
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/GroupHeader/GroupHeader.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { http, HttpResponse } from 'msw';
import { Provider } from 'react-redux';
import { MemoryRouter as Router } from 'react-router-dom';

import { genGroupDTO, genUserDTO, GroupDTO } from '@zerologementvacant/models';
import { GroupDTO } from '@zerologementvacant/models';
import { genGroupDTO, genUserDTO } from '@zerologementvacant/models/fixtures';
import GroupHeader, { DISPLAY_GROUPS } from './GroupHeader';
import configureTestStore from '../../utils/test/storeUtils';
import { mockAPI } from '../../mocks/mock-api';
Expand Down
16 changes: 9 additions & 7 deletions frontend/src/mocks/handlers/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,22 @@ import {
DatafoncierHousing,
DraftDTO,
EventDTO,
GroupDTO,
HousingDTO,
NoteDTO,
OwnerDTO,
UserDTO
} from '@zerologementvacant/models';
import {
genCampaignDTO,
genDatafoncierHousingDTO,
genDraftDTO,
genGroupDTO,
genHousingDTO,
genOwnerDTO,
genSenderDTO,
genUserDTO,
GroupDTO,
HousingDTO,
NoteDTO,
OwnerDTO,
UserDTO
} from '@zerologementvacant/models';
genUserDTO
} from '@zerologementvacant/models/fixtures';

const campaigns: CampaignDTO[] = Array.from({ length: 10 }, genCampaignDTO);

Expand Down
8 changes: 3 additions & 5 deletions frontend/src/mocks/handlers/group-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import { faker } from '@faker-js/faker';
import { http, HttpResponse, RequestHandler } from 'msw';
import { constants } from 'node:http2';

import {
genGroupDTO,
GroupDTO,
GroupPayloadDTO
} from '@zerologementvacant/models';
import { GroupDTO, GroupPayloadDTO } from '@zerologementvacant/models';
import { genGroupDTO } from '@zerologementvacant/models/fixtures';

import config from '../../utils/config';
import data from './data';

Expand Down
17 changes: 11 additions & 6 deletions frontend/src/views/Campaign/test/CampaignView.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@
import {
CampaignDTO,
DraftDTO,
genCampaignDTO,
genDraftDTO,
genHousingDTO,
genOwnerDTO,
genSenderDTO,
HousingDTO,
OwnerDTO,
SenderDTO
} from '@zerologementvacant/models';
import {
genCampaignDTO,
genDraftDTO,
genHousingDTO,
genOwnerDTO,
genSenderDTO
} from '@zerologementvacant/models/fixtures';

import data from '../../../mocks/handlers/data';
import { sources } from '../../../../test/event-source-mock';
import config from '../../../utils/config';
Expand Down Expand Up @@ -96,7 +99,9 @@

renderComponent();

const rename = await screen.findByRole('button', { name: /^Modifier le nom/ });
const rename = await screen.findByRole('button', {
name: /^Modifier le nom/
});
await user.click(rename);
const modal = await screen.findByRole('dialog');
const input = within(modal).getByRole('textbox', {
Expand Down Expand Up @@ -147,7 +152,7 @@
expect(alert).toBeVisible();
});

it.skip('should update the draft on button click', async () => {

Check warning on line 155 in frontend/src/views/Campaign/test/CampaignView.test.tsx

View workflow job for this annotation

GitHub Actions / build (20.x)

Disabled test
renderComponent();

// Fill the form
Expand Down
7 changes: 4 additions & 3 deletions frontend/src/views/Group/GroupView.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import userEvent from '@testing-library/user-event';
import { Provider } from 'react-redux';
import { MemoryRouter as Router, Route } from 'react-router-dom';

import { GroupDTO } from '@zerologementvacant/models';
import {
genCampaignDTO,
genGroupDTO,
genUserDTO,
GroupDTO
} from '@zerologementvacant/models';
genUserDTO
} from '@zerologementvacant/models/fixtures';

import data from '../../mocks/handlers/data';
import configureTestStore from '../../utils/test/storeUtils';
import GroupView from './GroupView';
Expand Down
8 changes: 5 additions & 3 deletions frontend/src/views/Housing/test/HousingView.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import { Provider } from 'react-redux';
import { MemoryRouter as Router, Route } from 'react-router-dom';

import {
genHousingDTO,
genHousingOwnerDTO,
genOwnerDTO,
HousingDTO,
HousingOwnerDTO,
OwnerDTO
} from '@zerologementvacant/models';
import {
genHousingDTO,
genHousingOwnerDTO,
genOwnerDTO
} from '@zerologementvacant/models/fixtures';
import configureTestStore from '../../../utils/test/storeUtils';
import HousingView from '../HousingView';
import data from '../../../mocks/handlers/data';
Expand Down
7 changes: 4 additions & 3 deletions frontend/src/views/HousingList/HousingListView.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
import { Provider } from 'react-redux';
import { MemoryRouter as Router, Route } from 'react-router-dom';

import { HousingKind } from '@zerologementvacant/models';
import {
genDatafoncierHousingDTO,
genGroupDTO,
genUserDTO,
HousingKind
} from '@zerologementvacant/models';
genUserDTO
} from '@zerologementvacant/models/fixtures';

import HousingListView from './HousingListView';
import config from '../../utils/config';
import configureTestStore from '../../utils/test/storeUtils';
Expand Down Expand Up @@ -93,7 +94,7 @@
});

// TODO: should be resolved by the relevant bug story
describe.skip('If the user does not know the local id', () => {

Check warning on line 97 in frontend/src/views/HousingList/HousingListView.test.tsx

View workflow job for this annotation

GitHub Actions / build (20.x)

Disabled test suite
const datafoncierHousing = genDatafoncierHousingDTO();
data.datafoncierHousings.push(datafoncierHousing);

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/views/Login/LoginView.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import userEvent from '@testing-library/user-event';
import { Provider } from 'react-redux';
import { MemoryRouter as Router, Route } from 'react-router-dom';

import { genUserDTO } from '@zerologementvacant/models';
import { genUserDTO } from '@zerologementvacant/models/fixtures';
import { store } from '../../store/store';
import LoginView from './LoginView';
import data from '../../mocks/handlers/data';
Expand Down
8 changes: 3 additions & 5 deletions frontend/test/fixtures.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ import { Prospect } from '../src/models/Prospect';
import { LocalityKinds } from '../src/models/Locality';
import { Group } from '../src/models/Group';
import { DatafoncierHousing } from '../../shared';
import {
AddressKinds,
genAddressDTO,
HousingStatus
} from '@zerologementvacant/models';
import { AddressKinds, HousingStatus } from '@zerologementvacant/models';
import { genAddressDTO } from '@zerologementvacant/models/fixtures';

import fp from 'lodash/fp';

export const genBoolean = () => Math.random() < 0.5;
Expand Down
18 changes: 14 additions & 4 deletions frontend/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"moduleResolution": "bundler"
},
"exclude": ["node_modules", "dist","src/**/*.test.ts", "src/**/*.test.tsx"]
"references": [
{ "path": "../packages/models/tsconfig.build.json" },
{ "path": "../packages/utils/tsconfig.build.json" },
{ "path": "../queue/tsconfig.build.json" }
],
"exclude": [
"node_modules",
"build",
"src/mocks/**/*.ts",
"src/setupTests.ts",
"src/**/*.test.ts",
"src/**/*.test.tsx",
"test/fixtures.test.ts"
]
}
3 changes: 0 additions & 3 deletions frontend/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"extends": "@tsconfig/create-react-app/tsconfig.json",
"compilerOptions": {
"moduleResolution": "node"
},
"include": ["src"]
}
16 changes: 13 additions & 3 deletions packages/models/package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
{
"name": "@zerologementvacant/models",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"exports": {
".": {
"import": "./dist/index.js",
"require": "./dist/index.js",
"types": "./dist/index.d.ts"
},
"./fixtures": {
"import": "./dist/test/fixtures.js",
"require": "./dist/test/fixtures.js",
"types": "./dist/test/fixtures.d.ts"
}
},
"scripts": {
"clean": "rimraf dist tsconfig.build.tsbuildinfo",
"build": "tsc -b tsconfig.build.json",
"test": "jest",
"dev": "nodemon --watch src -e ts --exec 'yarn build'"
},
"dependencies": {
"@faker-js/faker": "^8.4.1",
"@zerologementvacant/draft": "workspace:*",
"lodash": "^4.17.21"
},
"devDependencies": {
"@faker-js/faker": "^8.4.1",
"@tsconfig/node20": "^20.1.4",
"@types/geojson": "^7946.0.14",
"@types/jest": "^29.5.13",
Expand Down
1 change: 0 additions & 1 deletion packages/models/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from './test/fixtures';
export * from './AddressDTO';
export * from './BeneficiaryCount';
export * from './BuildingPeriod';
Expand Down
7 changes: 6 additions & 1 deletion packages/models/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"extends": "./tsconfig.json",
"references": [{ "path": "../draft/tsconfig.build.json" }],
"exclude": ["node_modules", "dist", "src/**/*.test.ts"]
"exclude": [
"node_modules",
"dist",
"src/**/*.test.ts",
"src/test/setup-tests.ts"
]
}
10 changes: 6 additions & 4 deletions server/src/controllers/ownerController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { v4 as uuidv4 } from 'uuid';
import {
AddressDTO,
AddressKinds,
genHousingOwnerDTO,
HousingOwnerPayloadDTO,
OwnerDTO,
OwnerPayloadDTO
Expand All @@ -31,7 +30,7 @@ import {
OwnerEventDBO,
ownerEventsTable
} from '~/repositories/eventRepository';
import { OwnerApi, toOwnerDTO } from '~/models/OwnerApi';
import { OwnerApi } from '~/models/OwnerApi';
import db from '~/infra/database';
import {
banAddressesTable,
Expand Down Expand Up @@ -309,8 +308,11 @@ describe('Owner API', () => {
rank: number
): HousingOwnerPayloadDTO {
return {
...genHousingOwnerDTO(toOwnerDTO(owner)),
rank
id: owner.id,
rank: rank,
locprop: null,
idprocpte: null,
idprodroit: null
};
}

Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9414,6 +9414,7 @@ __metadata:
prop-types: "npm:^15.8.1"
randomstring: "npm:^1.3.0"
react: "npm:^18.3.1"
react-dev-utils: "npm:^12.0.1"
react-dom: "npm:^18.3.1"
react-map-gl: "npm:^7.1.7"
react-redux: "npm:^8.1.3"
Expand Down
Loading