Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
3f16848
fix(plugin-typescript): include extended options
BioPhoton Aug 20, 2025
51c755b
test(plugin-typescript): fix path for windows
BioPhoton Aug 20, 2025
16eab1f
test(plugin-typescript-e2e): update snapshot
BioPhoton Aug 20, 2025
a440788
test(plugin-typescript-e2e): update test config
BioPhoton Aug 20, 2025
38c09e6
test(plugin-typescript): fix path for windows
BioPhoton Aug 20, 2025
bd6e003
test(plugin-typescript-e2e): fix path for windows
BioPhoton Aug 20, 2025
686ab91
fix(plugin-typescript-e2e): fix lint
BioPhoton Aug 20, 2025
062d9be
test(plugin-typescript-e2e): fix path for windows robust variant
BioPhoton Aug 20, 2025
f8220d9
test(plugin-typescript-e2e): fix path for windows robust variant 2
BioPhoton Aug 20, 2025
18f397c
test(plugin-typescript-e2e): fix path for windows robust variant 3
BioPhoton Aug 20, 2025
8210562
test(plugin-typescript-e2e): remove comments
BioPhoton Aug 20, 2025
8a63794
Update e2e/plugin-typescript-e2e/tests/collect.e2e.test.ts
BioPhoton Aug 20, 2025
25d636d
Update packages/plugin-typescript/src/lib/runner/utils.ts
BioPhoton Aug 20, 2025
c03338f
test: adjust test helper for message transform
BioPhoton Aug 20, 2025
7e1e45c
test(plugin-typescript): adjust checks
BioPhoton Aug 20, 2025
87851bb
test(plugin-typescript-e2e): adjust checks
BioPhoton Aug 20, 2025
6ec8df3
test(plugin-typescript-e2e): adjust checks 2
BioPhoton Aug 20, 2025
a0b5814
chore: add cloud-id
BioPhoton Aug 20, 2025
574beaa
chore(plugin-typescript-e2e): adjust checks for windows
BioPhoton Aug 20, 2025
2e1f646
chore(plugin-typescript-e2e): adjust checks for windows 3
BioPhoton Aug 20, 2025
5b22c58
chore: remove nx cloud id
BioPhoton Aug 20, 2025
e96b718
fix: adjust targets
BioPhoton Aug 20, 2025
af8634d
Update packages/plugin-typescript/src/lib/runner/runner.int.test.ts
BioPhoton Aug 21, 2025
68350d8
fix: format
Aug 21, 2025
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
2 changes: 1 addition & 1 deletion code-pushup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const config: CoreConfig = {
server: env.CP_SERVER,
apiKey: env.CP_API_KEY,
organization: env.CP_ORGANIZATION,
project: env.CP_PROJECT,
project: 'cli-workspace',
},
}),

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"rootDir": "./src",
"rootDir": "${configDir}/src",
"target": "ES6",
"module": "CommonJS",
"strict": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ exports[`PLUGIN collect report with typescript-plugin NPM package > should run p
"details": {
"issues": [
{
"message": "TS6059: File '<PATH>' is not under 'rootDir' '<PATH>'. 'rootDir' is expected to contain all source files.",
"message": "TS6059: File './exclude/utils.ts' is not under 'rootDir' './src'. 'rootDir' is expected to contain all source files.",
"severity": "error",
"source": {
"file": "tmp/e2e/plugin-typescript-e2e/src/6-configuration-errors.ts",
Expand Down
34 changes: 14 additions & 20 deletions e2e/plugin-typescript-e2e/tests/collect.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
E2E_ENVIRONMENTS_DIR,
TEST_OUTPUT_DIR,
omitVariableReportData,
osAgnosticAuditOutputs,
osAgnosticPath,
teardownTestFolder,
} from '@code-pushup/test-utils';
Expand All @@ -17,27 +18,20 @@ function sanitizeReportPaths(report: Report): Report {
...report,
plugins: report.plugins.map(plugin => ({
...plugin,
audits: plugin.audits.map(audit => ({
...audit,
...(audit.details && {
details: {
...audit.details,
issues: audit.details.issues?.map(issue => ({
...issue,
...(issue.source && {
source: {
...issue.source,
file: osAgnosticPath(issue.source.file),
},
}),
message: issue.message.replace(
/['"]([^'"]*[/\\][^'"]*)['"]/g,
"'<PATH>'",
),
})),
audits: osAgnosticAuditOutputs(plugin.audits, message =>
message.replace(
/['"]([^'"]*[/\\][^'"]*)['"]/g,
(fullMatch: string, capturedPath: string) => {
const osAgnostic = osAgnosticPath(capturedPath);
// Only replace directory paths, not .ts file paths
if (capturedPath.endsWith('.ts')) {
return `'${osAgnostic}'`;
}
// on Windows the path starts from "plugin-typescript-e2e/src" not "./". This normalizes it to "./<segment>"
return `'${['.', osAgnostic.split('/').slice(-1)].join('/')}'`;
},
}),
})),
),
),
})),
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"rootDir": "./src",
"rootDir": "${configDir}",
"verbatimModuleSyntax": false
},
"include": ["src/**/*.ts"]
Expand Down
25 changes: 5 additions & 20 deletions packages/plugin-typescript/src/lib/runner/runner.int.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { describe, expect } from 'vitest';
import { osAgnosticPath } from '@code-pushup/test-utils';
import type { AuditOutputs } from '@code-pushup/models';
import { osAgnosticAuditOutputs } from '@code-pushup/test-utils';
import { getAudits } from '../utils.js';
import { createRunnerFunction } from './runner.js';

Expand All @@ -13,24 +14,8 @@ describe('createRunnerFunction', () => {

const result = await runnerFunction();

const sanitizedResult = result.map(audit => ({
...audit,
...(audit.details && {
details: {
...audit.details,
issues: audit.details.issues?.map(issue => ({
...issue,
...(issue.source && {
source: {
...issue.source,
file: osAgnosticPath(issue.source.file),
},
}),
})),
},
}),
}));

await expect(sanitizedResult).toMatchSnapshot();
await expect(
Comment thread
BioPhoton marked this conversation as resolved.
Outdated
osAgnosticAuditOutputs(result as AuditOutputs),
).toMatchSnapshot();
}, 35_000);
});
6 changes: 3 additions & 3 deletions packages/plugin-typescript/src/lib/runner/utils.int.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as tsModule from 'typescript';
import { describe, expect } from 'vitest';
import { describe, expect, vi } from 'vitest';
import { osAgnosticPath } from '@code-pushup/test-utils';
import { loadTargetConfig } from './utils.js';

Expand Down Expand Up @@ -48,11 +48,11 @@ describe('loadTargetConfig', () => {
expect.objectContaining({
fileNames: expect.arrayContaining([
// from tsconfig.extends-base.json#includes and tsconfig.extends-extending.json#excludes
expect.stringContaining('src/0-no-diagnostics/'),
expect.stringMatching(/src[/\\]0-no-diagnostics[/\\]/),
]),
options: expect.objectContaining({
// Options from tsconfig.extends-base.json
rootDir: expect.stringContaining('src'),
rootDir: expect.stringMatching(/basic-setup$/),
// Options from tsconfig.extends-extending.json
module: 1,
configFilePath: expect.stringContaining(
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-typescript/src/lib/runner/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export function loadTargetConfig(tsConfigPath: string) {

if (error) {
throw new Error(
`Error reading TypeScript config file: \n${error.messageText}`,
`Error reading TypeScript config file at ${tsConfigPath}:\n${error.messageText}`,
);
}

Expand Down
2 changes: 1 addition & 1 deletion project.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@code-pushup/cli-source",
"name": "cli-workspace",
"$schema": "node_modules/nx/schemas/project-schema.json",
"targets": {
"code-pushup": {
Expand Down
17 changes: 10 additions & 7 deletions testing/test-utils/src/lib/utils/os-agnostic-paths.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import type {
AuditOutput,
AuditOutputs,
AuditReport,
} from '@code-pushup/models';
import type { AuditOutput, AuditReport } from '@code-pushup/models';

const AGNOSTIC_PATH_SEP_REGEX = /[/\\]/g;
const OS_AGNOSTIC_PATH_SEP = '/';
Expand Down Expand Up @@ -102,6 +98,7 @@ export function osAgnosticPath(filePath?: string): string | undefined {

export function osAgnosticAudit<T extends AuditOutput | AuditReport>(
audit: T,
transformMessage: (message: string) => string = s => s,
): T {
const { issues = [] } = audit.details ?? {};
if (issues.every(({ source }) => source == null)) {
Expand All @@ -119,12 +116,18 @@ export function osAgnosticAudit<T extends AuditOutput | AuditReport>(
...issue.source,
file: osAgnosticPath(issue.source.file),
},
message: transformMessage(issue.message),
},
),
},
};
}

export function osAgnosticAuditOutputs(audits: AuditOutputs): AuditOutputs {
return audits.map(osAgnosticAudit);
export function osAgnosticAuditOutputs<T extends AuditOutput | AuditReport>(
audits: T[],
transformAuditIssueMessage?: (message: string) => string,
): T[] {
return audits.map(audit =>
osAgnosticAudit(audit, transformAuditIssueMessage),
);
}
Loading