Skip to content

Commit

Permalink
Merge 9993401 into 304b229
Browse files Browse the repository at this point in the history
  • Loading branch information
BioPhoton authored Aug 19, 2024
2 parents 304b229 + 9993401 commit eb4f54a
Show file tree
Hide file tree
Showing 38 changed files with 1,107 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ jobs:
- name: Install dependencies
run: npm ci
- name: E2E test affected projects
run: npx nx affected:e2e --parallel=3
run: npx nx affected:e2e --parallel=1

build:
runs-on: ubuntu-latest
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ This table provides a quick overview of the environmental setup, with detailed e
**❗️** Test Inclusion Logic

- `INCLUDE_SLOW_TESTS='false'` skips long tests.
- without `INCLUDE_SLOW_TESTS`, tests run if `CI` is set.
- Without `INCLUDE_SLOW_TESTS`, tests run if `CI` is set.

**❗️❗️** Windows specific path set only in CI

- some setups also require this setting locally
- Some setups also require this setting locally.

## Development

Expand Down
12 changes: 12 additions & 0 deletions e2e/create-cli-e2e/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*", "code-pushup.config*.ts"],
"overrides": [
{
"files": ["*.ts", "*.tsx"],
"parserOptions": {
"project": ["e2e/create-cli-e2e/tsconfig.*?.json"]
}
}
]
}
14 changes: 14 additions & 0 deletions e2e/create-cli-e2e/mocks/create-npm-workshpace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { mkdir, writeFile } from "node:fs/promises";
import { join } from "node:path";

export async function createNpmWorkspace(cwd: string) {
await mkdir(cwd, { recursive: true });
await writeFile(join(cwd, 'package.json'), JSON.stringify({
name: 'create-npm-workspace',
version: '0.0.1',
scripts: {
test: 'echo "Error: no test specified" && exit 1',
},
keywords: [],
}, null, 2));
}
23 changes: 23 additions & 0 deletions e2e/create-cli-e2e/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "create-cli-e2e",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "examples/create-cli-e2e/src",
"projectType": "application",
"targets": {
"lint": {
"executor": "@nx/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["e2e/create-cli-e2e/**/*.ts"]
}
},
"e2e": {
"executor": "@nx/vite:test",
"options": {
"configFile": "e2e/create-cli-e2e/vite.config.e2e.ts"
}
}
},
"implicitDependencies": ["create-cli"],
"tags": ["scope:tooling", "type:e2e"]
}
69 changes: 69 additions & 0 deletions e2e/create-cli-e2e/tests/init.e2e.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { rm } from 'node:fs/promises';
import { join, relative } from 'node:path';
import { afterEach, expect } from 'vitest';
import { removeColorCodes } from '@code-pushup/test-utils';
import { executeProcess } from '@code-pushup/utils';
import { createNpmWorkspace } from '../mocks/create-npm-workshpace';

describe('create-cli-node', () => {
const baseDir = join('tmp', 'create-cli-e2e');
const bin = 'dist/packages/create-cli';
const binPath = (cwd?: string) =>
cwd ? relative(join(process.cwd(), cwd), join(process.cwd(), bin)) : bin;

afterEach(async () => {
await rm(baseDir, { recursive: true, force: true });
});

// eslint-disable-next-line vitest/no-disabled-tests
it.skip('should execute index.js correctly over node', async () => {
const cwd = join(baseDir, 'node-index-js');
await createNpmWorkspace(cwd);
const { code, stdout } = await executeProcess({
command: 'node',
args: [join(binPath(cwd), 'index.js')],
cwd,
});

expect(code).toBe(0);
const cleanedStdout = removeColorCodes(stdout);
expect(cleanedStdout).toContain(
'<↗> Generating @code-pushup/nx-plugin:configuration',
);
});

// eslint-disable-next-line vitest/no-disabled-tests
it.skip('should execute package correctly over npm exec', async () => {
const cwd = join(baseDir, 'npm-exec');
await createNpmWorkspace(cwd);
const { code, stdout } = await executeProcess({
command: 'npm',
args: ['exec', '@code-pushup/create-cli'],
cwd,
observer: { onStdout: console.info },
});

expect(code).toBe(0);
const cleanedStdout = removeColorCodes(stdout);
expect(cleanedStdout).toContain(
'<↗> Generating @code-pushup/nx-plugin:configuration',
);
});

it('should execute package correctly over npm init', async () => {
const cwd = join(baseDir, 'npm-init');
await createNpmWorkspace(cwd);
const { code, stdout } = await executeProcess({
command: 'npm',
args: ['init', '@code-pushup/cli'],
cwd,
observer: { onStdout: console.info },
});

expect(code).toBe(0);
const cleanedStdout = removeColorCodes(stdout);
expect(cleanedStdout).toContain(
'<↗> Generating @code-pushup/nx-plugin:configuration',
);
});
});
20 changes: 20 additions & 0 deletions e2e/create-cli-e2e/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"module": "ESNext",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"types": ["vitest"]
},
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.test.json"
}
]
}
13 changes: 13 additions & 0 deletions e2e/create-cli-e2e/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"types": ["vitest/globals", "vitest/importMeta", "vite/client", "node"]
},
"include": [
"vite.config.e2e.ts",
"tests/**/*.e2e.test.ts",
"tests/**/*.d.ts",
"mocks/**/*.ts"
]
}
22 changes: 22 additions & 0 deletions e2e/create-cli-e2e/vite.config.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/// <reference types="vitest" />
import { defineConfig } from 'vite';
import { tsconfigPathAliases } from '../../tools/vitest-tsconfig-path-aliases';

export default defineConfig({
cacheDir: '../../node_modules/.vite/create-cli-e2e',
test: {
reporters: ['basic'],
testTimeout: 60_000,
globals: true,
alias: tsconfigPathAliases(),
pool: 'threads',
poolOptions: { threads: { singleThread: true } },
cache: {
dir: '../../node_modules/.vitest',
},
environment: 'node',
include: ['tests/**/*.e2e.test.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
globalSetup: ['../../global-setup.e2e.ts'],
setupFiles: ['../../testing/test-setup/src/lib/reset.mocks.ts'],
},
});
15 changes: 0 additions & 15 deletions e2e/nx-plugin-e2e/tests/__snapshots__/nx-plugin.e2e.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,6 @@ exports[`nx-plugin > should NOT add config targets dynamically if the project is
}
`;

exports[`nx-plugin > should NOT add targets dynamically if plugin is not registered 1`] = `
{
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"implicitDependencies": [],
"name": "my-lib",
"projectType": "library",
"root": "libs/my-lib",
"sourceRoot": "libs/my-lib/src",
"tags": [
"scope:plugin",
],
"targets": {},
}
`;

exports[`nx-plugin > should add configuration target dynamically 1`] = `
{
"$schema": "../../node_modules/nx/schemas/project-schema.json",
Expand Down
2 changes: 1 addition & 1 deletion e2e/nx-plugin-e2e/tests/init.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ describe('nx-plugin g init', () => {
args: [
'nx',
'g',
`${relativePathToDist(cwd)}:init `,
`${relativePathToDist(cwd)}:init`,
project,
'--skipInstall',
'--skipPackageJson',
Expand Down
3 changes: 1 addition & 2 deletions e2e/nx-plugin-e2e/tests/nx-plugin.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ describe('nx-plugin', () => {
});
});

it('should NOT add targets dynamically if plugin is not registered', async () => {
it('should NOT add targets dynamically if plugin is NOT registered', async () => {
const cwd = join(baseDir, 'plugin-not-registered');
await materializeTree(tree, cwd);

Expand All @@ -251,6 +251,5 @@ describe('nx-plugin', () => {
expect(code).toBe(0);

expect(projectJson.targets).toStrictEqual({});
expect(projectJson).toMatchSnapshot();
});
});
14 changes: 11 additions & 3 deletions global-setup.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,26 @@ const localRegistryNxTarget = '@code-pushup/cli-source:local-registry';

export async function setup() {
await globalSetup();
await setupTestFolder('tmp/local-registry');
await setupTestFolder('tmp/e2e');

try {
await setupTestFolder('tmp/local-registry');
await startLocalRegistry({ localRegistryTarget: localRegistryNxTarget });
} catch (error) {
console.error('Error starting local verdaccio registry:\n' + error.message);
throw error;
}

try {
console.info('Installing packages');
execFileSync(
'npx',
['nx', 'run-many', '--targets=npm-install', '--parallel=1'],
{ env: process.env, stdio: 'inherit', shell: true },
);
await setupTestFolder('tmp/e2e');
} catch (error) {
console.info('setup error: ' + error.message);
console.error('Error installing packages:\n' + error.message);
throw error;
}
}

Expand Down
25 changes: 25 additions & 0 deletions packages/create-cli/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx"],
"parserOptions": {
"project": ["packages/create-cli/tsconfig.*?.json"]
},
"rules": {}
},
{
"files": ["*.json"],
"parser": "jsonc-eslint-parser",
"rules": {
"@nx/dependency-checks": [
"error",
{
"ignoredDependencies": ["@code-pushup/nx-plugin"] // nx-plugin is run via CLI
}
]
}
}
]
}
32 changes: 32 additions & 0 deletions packages/create-cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# @code-pushup/create-cli

[![npm](https://img.shields.io/npm/v/%40code-pushup%2Fcreate-cli.svg)](https://www.npmjs.com/package/@code-pushup/create-cli)
[![downloads](https://img.shields.io/npm/dm/%40code-pushup%2Fcreate-cli)](https://npmtrends.com/@code-pushup/create-cli)
[![dependencies](https://img.shields.io/librariesio/release/npm/%40code-pushup/create-cli)](https://www.npmjs.com/package/@code-pushup/create-cli?activeTab=dependencies)

A CLI tool to set up Code PushUp in your repository.

## Usage

To set up Code PushUp, run the following command:

```bash
npx init @code-pushup/cli
```

alternatives:

```bash
npx @code-pushup/create-cli
npm exec @code-pushup/create-cli
```

It should generate the following output:

```bash
> <> Generating @code-pushup/nx-plugin:init

> <> Generating @code-pushup/nx-plugin:configuration

CREATE code-pushup.config.ts
```
10 changes: 10 additions & 0 deletions packages/create-cli/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "@code-pushup/create-cli",
"version": "0.0.0",
"license": "MIT",
"bin": "index.js",
"dependencies": {
"@code-pushup/nx-plugin": "*",
"@code-pushup/utils": "*"
}
}
Loading

0 comments on commit eb4f54a

Please sign in to comment.