Skip to content
Draft
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
4 changes: 2 additions & 2 deletions e2e/cli-e2e/tests/print-config.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('CLI print-config', () => {
'print-config',
'--output=config.json',
`--config=${configFilePath(ext)}`,
'--tsconfig=tsconfig.base.json',
`--tsconfig=${path.join(process.cwd(), 'tsconfig.base.json')}`,
'--persist.outputDir=output-dir',
'--persist.format=md',
`--persist.filename=${ext}-report`,
Expand All @@ -64,7 +64,7 @@ describe('CLI print-config', () => {
expect(JSON.parse(output)).toEqual(
expect.objectContaining({
config: expect.stringContaining(`code-pushup.config.${ext}`),
tsconfig: 'tsconfig.base.json',
tsconfig: path.join(process.cwd(), 'tsconfig.base.json'),
plugins: [
expect.objectContaining({
slug: 'dummy-plugin',
Expand Down
42 changes: 38 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"@nx/react": "22.3.3",
"@nx/vite": "22.3.3",
"@nx/workspace": "22.3.3",
"@push-based/jiti-tsc": "^0.0.2",
"@push-based/nx-verdaccio": "0.0.7",
"@swc-node/register": "1.9.2",
"@swc/cli": "0.6.0",
Expand Down Expand Up @@ -102,7 +103,7 @@
"husky": "^8.0.0",
"inquirer": "^9.3.7",
"jest-extended": "^6.0.0",
"jiti": "2.4.2",
"jiti": "^2.6.1",
"jsdom": "~24.0.0",
"jsonc-eslint-parser": "^2.4.0",
"knip": "^5.33.3",
Expand Down
43 changes: 43 additions & 0 deletions packages/cli/mocks/fixtures/configs/code-pushup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
export default {
upload: {
organization: 'code-pushup',
project: 'cli-js',
apiKey: 'e2e-api-key',
server: 'https://e2e.com/api',
},
categories: [
{
slug: 'category-1',
title: 'Category 1',
refs: [
{
type: 'audit',
plugin: 'node',
slug: 'node-version',
weight: 1,
},
],
},
],
plugins: [
{
audits: [
{
slug: 'node-version',
title: 'Node version',
description: 'prints node version to file',
docsUrl: 'https://nodejs.org/',
},
],
runner: {
command: 'node',
args: ['-v'],
outputFile: 'output.json',
},
groups: [],
slug: 'node',
title: 'Node.js',
icon: 'javascript',
},
],
};
43 changes: 43 additions & 0 deletions packages/cli/mocks/fixtures/configs/code-pushup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
export default {
upload: {
organization: 'code-pushup',
project: 'cli-mjs',
apiKey: 'e2e-api-key',
server: 'https://e2e.com/api',
},
categories: [
{
slug: 'category-1',
title: 'Category 1',
refs: [
{
type: 'audit',
plugin: 'node',
slug: 'node-version',
weight: 1,
},
],
},
],
plugins: [
{
audits: [
{
slug: 'node-version',
title: 'Node version',
description: 'prints node version to file',
docsUrl: 'https://nodejs.org/',
},
],
runner: {
command: 'node',
args: ['-v'],
outputFile: 'output.json',
},
groups: [],
slug: 'node',
title: 'Node.js',
icon: 'javascript',
},
],
};
45 changes: 45 additions & 0 deletions packages/cli/mocks/fixtures/configs/code-pushup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { type CoreConfig } from '@code-pushup/models';

export default {
upload: {
organization: 'code-pushup',
project: 'cli-ts',
apiKey: 'e2e-api-key',
server: 'https://e2e.com/api',
},
categories: [
{
slug: 'category-1',
title: 'Category 1',
refs: [
{
type: 'audit',
plugin: 'node',
slug: 'node-version',
weight: 1,
},
],
},
],
plugins: [
{
audits: [
{
slug: 'node-version',
title: 'Node version',
description: 'prints node version to file',
docsUrl: 'https://nodejs.org/',
},
],
runner: {
command: 'node',
args: ['-v'],
outputFile: 'output.json',
},
groups: [],
slug: 'node',
title: 'Node.js',
icon: 'javascript',
},
],
} satisfies CoreConfig;
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// the point is to test runtime import which relies on alias defined in tsconfig.json "paths"
// non-type import from '@example/custom-plugin' wouldn't work without --tsconfig
// eslint-disable-next-line import/no-unresolved
import customPlugin from '@definitely-non-existent-package/custom-plugin';

const config = {
plugins: [customPlugin],
};

export default config;
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// the point is to test runtime import which relies on alias defined in tsconfig.json "paths"
// non-type import from '@example/custom-plugin' wouldn't work without --tsconfig
// eslint-disable-next-line import/no-unresolved
import customPlugin from '@definitely-non-existent-package/custom-plugin';

const config = {
plugins: [customPlugin],
};

export default config;
24 changes: 24 additions & 0 deletions packages/cli/mocks/fixtures/configs/custom-plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const customPluginConfig = {
slug: 'good-feels',
title: 'Good feels',
icon: 'javascript',
audits: [
{
slug: 'always-perfect',
title: 'Always perfect',
},
],
runner: () => [
{
slug: 'always-perfect',
score: 1,
value: 100,
displayValue: '✅ Perfect! 👌',
},
],
};

export function customPlugin() {
return customPluginConfig;
}
export default customPluginConfig;
7 changes: 7 additions & 0 deletions packages/cli/mocks/fixtures/configs/tsconfig.alias.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"compilerOptions": {
"paths": {
"@definitely-non-existent-package/custom-plugin": ["./custom-plugin.ts"]
}
}
}
5 changes: 5 additions & 0 deletions packages/cli/mocks/fixtures/configs/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"paths": {}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,12 @@ import { fileURLToPath } from 'node:url';
import { describe, expect } from 'vitest';
import { coreConfigMiddleware } from './core-config.middleware.js';

const configDirPath = path.join(
const localMocks = path.join(
fileURLToPath(path.dirname(import.meta.url)),
'..',
'..',
'..',
'..',
'..',
'testing',
'test-fixtures',
'src',
'lib',
'mocks',
'fixtures',
'configs',
);
Expand All @@ -29,7 +24,7 @@ describe('coreConfigMiddleware', () => {
'should load a valid .%s config',
async extension => {
const config = await coreConfigMiddleware({
config: path.join(configDirPath, `code-pushup.config.${extension}`),
config: path.join(localMocks, `code-pushup.config.${extension}`),
...CLI_DEFAULTS,
});
expect(config.config).toContain(`code-pushup.config.${extension}`);
Expand All @@ -46,11 +41,8 @@ describe('coreConfigMiddleware', () => {
it('should load config which relies on provided --tsconfig', async () => {
await expect(
coreConfigMiddleware({
config: path.join(
configDirPath,
'code-pushup.needs-tsconfig.config.ts',
),
tsconfig: path.join(configDirPath, 'tsconfig.json'),
config: path.join(localMocks, 'code-pushup.needs-tsconfig.config.ts'),
tsconfig: path.join(localMocks, 'tsconfig.alias.json'),
...CLI_DEFAULTS,
}),
).resolves.toBeTruthy();
Expand All @@ -60,11 +52,13 @@ describe('coreConfigMiddleware', () => {
await expect(
coreConfigMiddleware({
config: path.join(
configDirPath,
'code-pushup.needs-tsconfig.config.ts',
localMocks,
'code-pushup.needs-tsconfig-fail.config.ts',
),
...CLI_DEFAULTS,
}),
).rejects.toThrow("Cannot find package '@example/custom-plugin'");
).rejects.toThrow(
"Cannot find module '@definitely-non-existent-package/custom-plugin'",
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ describe('readRcByPath', () => {
});

it('should throw if the path is empty', async () => {
await expect(readRcByPath('')).rejects.toThrow("File '' does not exist");
await expect(readRcByPath('')).rejects.toThrow(
"Importing module failed. File '' does not exist",
);
});

it('should throw if the file does not exist', async () => {
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/lib/implementation/read-rc-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export async function readRcByPath(
const result = await importModule({
filepath: filePath,
tsconfig,
format: 'esm',
});
return { result, message: `Imported config from ${formattedTarget}` };
},
Expand Down
Loading
Loading