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

[frontend] Update dependency typescript to v5.7.2 #1917

Merged
merged 6 commits into from
Dec 13, 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: 11 additions & 10 deletions openbas-front/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"@types/react-syntax-highlighter": "15",
"@types/seamless-immutable": "7.1.19",
"@types/uuid": "10.0.0",
"@typescript-eslint/parser": "8.15.0",
"@typescript-eslint/parser": "8.16.0",
"@vitejs/plugin-react": "4.3.4",
"chokidar": "4.0.1",
"cross-env": "7.0.3",
Expand All @@ -115,12 +115,12 @@
"fs-extra": "11.2.0",
"globals": "15.12.0",
"jsdom": "25.0.1",
"nyc": "17.1.0",
"monocart-coverage-reports": "2.11.3",
"monocart-reporter": "2.9.11",
"swagger-typescript-api": "13.0.22",
"typescript": "5.6.2",
"typescript-eslint": "8.15.0",
"typescript": "5.7.2",
"typescript-eslint": "8.16.0",
"vite": "6.0.3",
"vite-plugin-istanbul": "6.0.2",
"vitest": "2.1.1"
},
"engines": {
Expand All @@ -132,14 +132,15 @@
"build": "node builder/prod/prod.js",
"lint": "cross-env DEBUG=eslint:eslint TIMING=1 eslint --max-warnings 0 --cache --rule \"{'import/namespace': 'error', 'import/no-cycle': ['error', {'ignoreExternal': true, 'disableScc': true}]}\" .",
"control": "yarn audit --groups dependencies --summary",
"test": "vitest run",
"check-ts": "tsc --noEmit",
"i18n-checker": "node i18n-checker.js",
"generate-types-from-api": "swagger-typescript-api --no-client -p http://localhost:8080/api-docs -o src/utils -n api-types.d.ts --sort-types",
"test:e2e": "yarn playwright test",
"test:e2e:ui": "yarn playwright test --ui",
"generate-test-e2e": "npx playwright codegen http://localhost:3001/",
"test:e2e:coverage": "npx nyc report --reporter=html && start \"\" coverage/index.html"
"test": "vitest run",
"test:e2e": "yarn playwright test --workers=1 --retries=2",
"test:e2e:ui": "yarn playwright test --ui --workers=1",
"test:e2e:coverage": "E2E_COVERAGE=true yarn playwright test && yarn show-report-e2e",
"generate-test-e2e": "yarn playwright codegen http://localhost:3001/",
"show-report-e2e": "start \"\" test-results/report.html && start \"\" test-results/coverage/index.html"
},
"resolutions": {
"mini-css-extract-plugin": "2.9.2",
Expand Down
31 changes: 28 additions & 3 deletions openbas-front/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,49 @@ export default defineConfig({
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'html',
reporter: [
['list'],
['monocart-reporter', {
name: `OpenBAS Report`,
outputFile: './test-results/report.html',
// global coverage report options
coverage: {
entryFilter: () => true,
sourceFilter: (sourcePath: string) => sourcePath.startsWith('src'),
},
/*
onEnd: async (reportData) => {
// teams integration with webhook
await teamsWebhook(reportData);
} */
}],
],
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
// baseURL: 'http://127.0.0.1:3000',
baseURL: 'http://localhost:3001',

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
screenshot: 'only-on-failure',
video: 'retain-on-failure',
ignoreHTTPSErrors: true,
},

expect: { timeout: 60000 },
timeout: 200000,
/* Configure projects for major browsers */
projects: [
{ name: 'setup', testMatch: /.*\.setup\.ts/ },
{
// Do not change the project name as it is hardcoded in the baseFixtures
name: 'chromium',
use: {
...devices['Desktop Chrome'],
storageState: 'tests_e2e/.auth/user.json',
viewport: {
width: 1920,
height: 1080,
},
},
dependencies: ['setup'],
},
Expand Down
27 changes: 27 additions & 0 deletions openbas-front/tests_e2e/conf/mcr.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { CoverageReportOptions } from 'monocart-coverage-reports';

// https://github.com/cenfun/monocart-coverage-reports
const coverageOptions: CoverageReportOptions = {

name: 'OpenBAS Playwright Coverage Report',

reports: [
'console-details',
'v8',
'lcovonly',
],

entryFilter: {
'**/node_modules/**': false,
'**/**': true,
},

sourceFilter: {
'**/node_modules/**': false,
'**/**': true,
},

outputDir: './test-results/coverage',
};

export default coverageOptions;
68 changes: 46 additions & 22 deletions openbas-front/tests_e2e/fixtures/baseFixtures.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,52 @@
/* eslint-disable @typescript-eslint/no-explicit-any, no-underscore-dangle */
import { test as baseTest } from '@playwright/test';
import * as crypto from 'crypto';
import * as fs from 'fs';
import * as path from 'path';
import { Page, test as testBase } from '@playwright/test';
import MCR from 'monocart-coverage-reports';

const istanbulCLIOutput = path.join(process.cwd(), '.nyc_output');
import coverageOptions from '../conf/mcr.config';

export function generateUUID(): string {
return crypto.randomBytes(16).toString('hex');
}
// fixtures
const test = testBase.extend<{
autoTestFixture: string;
}>({
autoTestFixture: [async ({ context }, use) => {
const activateCoverage = process.env.E2E_COVERAGE;
const isChromium = test.info().project.name === 'chromium';

guillaumejparis marked this conversation as resolved.
Show resolved Hide resolved
export const test = baseTest.extend({
context: async ({ context }, use) => {
await context.addInitScript(() => window.addEventListener('beforeunload', () => (window as any).collectIstanbulCoverage(JSON.stringify((window as any).__coverage__))));
await fs.promises.mkdir(istanbulCLIOutput, { recursive: true });
await context.exposeFunction('collectIstanbulCoverage', (coverageJSON: string) => {
if (coverageJSON) fs.writeFileSync(path.join(istanbulCLIOutput, `playwright_coverage_${generateUUID()}.json`), coverageJSON);
});
await use(context);
for (const page of context.pages()) {
// eslint-disable-next-line no-await-in-loop
await page.evaluate(() => (window as any).collectIstanbulCoverage(JSON.stringify((window as any).__coverage__)));
const handlePageEvent = async (page: Page) => {
await Promise.all([
page.coverage.startJSCoverage({
resetOnNavigation: false,
}),
page.coverage.startCSSCoverage({
resetOnNavigation: false,
}),
]);
};

// console.log('autoTestFixture setup...');
// coverage API is chromium only
if (activateCoverage && isChromium) {
context.on('page', handlePageEvent);
}

await use('autoTestFixture');

// console.log('autoTestFixture teardown...');
if (activateCoverage && isChromium) {
context.off('page', handlePageEvent);
const coverageList = await Promise.all(context.pages().map(async (page) => {
const jsCoverage = await page.coverage.stopJSCoverage();
const cssCoverage = await page.coverage.stopCSSCoverage();
return [...jsCoverage, ...cssCoverage];
}));
// console.log(coverageList.map((item) => item.url));
const mcr = MCR(coverageOptions);
await mcr.add(coverageList.flat());
}
},
}, {
scope: 'test',
auto: true,
}],
});

export const { expect } = test;
// eslint-disable-next-line import/prefer-default-export
export { test };
7 changes: 1 addition & 6 deletions openbas-front/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import react from '@vitejs/plugin-react';
import { createLogger, defineConfig, loadEnv, transformWithEsbuild } from 'vite';
import IstanbulPlugin from 'vite-plugin-istanbul';

const logger = createLogger();
const loggerError = logger.error;
Expand All @@ -27,6 +26,7 @@ export default ({ mode }: { mode: string }) => {
build: {
target: ['chrome58'],
sourcemap: true,
minify: false,
},

resolve: {
Expand Down Expand Up @@ -118,11 +118,6 @@ export default ({ mode }: { mode: string }) => {
},
},
react(),
[IstanbulPlugin({
include: 'src/*',
exclude: ['node_modules', 'test/'],
extension: ['.js', '.jsx', '.ts', '.tsx'],
})],
],

server: {
Expand Down
Loading
Loading