Skip to content

Commit

Permalink
feat: cleanup git status in folders that are checked in
Browse files Browse the repository at this point in the history
  • Loading branch information
BioPhoton authored Nov 10, 2024
2 parents c771255 + 0a5c2ae commit 5e2c9b5
Show file tree
Hide file tree
Showing 33 changed files with 617 additions and 63 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/code-pushup-fork.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Code PushUp (fork)

# separated from code-pushup.yml for security reasons
# => requires permissions to create PR comment
# => for PRs from forks, needs to run on `pull_request_target`, not `pull_request`
# => `pull_request_target` is a security risk when secrets are being used
# => secrets needed for code-pushup upload
# => code-pushup for forks runs in separate workflow with no secrets access

on:
pull_request_target:
branches: [main]

env:
NX_NON_NATIVE_HASHER: true

permissions:
pull-requests: write

jobs:
code-pushup:
runs-on: ubuntu-latest
name: Code PushUp
if: github.event.pull_request.head.repo.fork
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
cache: npm
- name: Install dependencies
run: npm ci
- name: Run Code PushUp action
uses: code-pushup/github-action@v0
with:
bin: npx nx code-pushup --
2 changes: 1 addition & 1 deletion .github/workflows/code-pushup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ jobs:
- name: Run Code PushUp action
uses: code-pushup/github-action@v0
with:
bin: npx nx run code-pushup
bin: npx nx run code-pushup -- --verbose
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
[![commit activity](https://img.shields.io/github/commit-activity/m/push-based/nx-verdaccio)](https://github.com/push-based/nx-verdaccio/pulse/monthly)
[![CI](https://github.com/push-based/nx-verdaccio/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/push-based/nx-verdaccio/actions/workflows/ci.yml?query=branch%3Amain)


Welcome to the **Verdaccio Testing Environments Nx Plugin** — your one-stop solution for running **blazingly fast**, **isolated**, and **scalable** end-to-end (e2e) tests with zero configuration. Yeah, you heard that right: **ZERO configuration**.

With this plugin, say goodbye to the old days of waiting around for your tests and hello to _next-level speed_. Plug it in, and you're good to go.
Expand Down Expand Up @@ -240,6 +239,12 @@ This is a first draft of how the benchmarks will look. ATM the data set it not b
| Graph Nodes | 1 | 13 | n/a | n/a |
| Parallelism ||| n/a | n/a |

## Next Steps

- [configure cacheable environments](./projects/nx-verdaccio/docs/static-environments.md)
- [static environments](.)
- [debugging](.)

## Stay Connected! 🔗

- [Check out our services](https://push-based.io)
Expand Down
16 changes: 11 additions & 5 deletions examples/e2e/cli-static-e2e/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@
"implicitDependencies": ["cli"],
"targets": {
"lint": {},
"e2e-static": {
"executor": "@nx/vite:test",
"inputs": ["default", "^production"],
"outputs": ["{options.reportsDirectory}"],
"nxv-e2e": {
"options": {
"envRoot": "static-environments/user-lists"
}
},
"nxv-env-setup": {
"options": {
"reportsDirectory": "../../../coverage/projects/cli-static-e2e"
"envRoot": "static-environments/user-lists"
}
},
"e2e": {
"executor": "@nx/vite:test",
"inputs": ["default", "^production"]
}
}
}
55 changes: 38 additions & 17 deletions examples/e2e/cli-static-e2e/test/cli-command-sort.spec.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
import { dirname, join, basename } from 'node:path';
import { basename, dirname, join } from 'node:path';
import { afterEach, describe, expect, it } from 'vitest';
import { mkdir, readFile, rm, writeFile } from 'node:fs/promises';
import { readFile, rm } from 'node:fs/promises';
import { executeProcess, objectToCliArgs } from '@push-based/test-utils';
import {
getTestFixturesDist,
getTestEnvironmentRoot,
} from '@push-based/test-utils';
import type { SimpleGit } from 'simple-git';
import { simpleGit } from 'simple-git';

describe('CLI command - sort', () => {
const fixturesDist = getTestFixturesDist('cli-command-sort', {
root: getTestEnvironmentRoot(process.env['NX_TASK_TARGET_PROJECT']),
});
const envRoot = join('static-environments', 'user-lists');
const baseDir = join(envRoot, 'src', 'lib');
const gitClient: SimpleGit = simpleGit(process.cwd());

afterEach(async () => {
await rm(fixturesDist, { recursive: true, force: true });
await gitClient.checkout([baseDir]);
await gitClient.clean('f', [baseDir]);
});

it('should execute CLI command sort when param file is given', async () => {
const testPath = join(fixturesDist, 'execute-sort-command', 'users.json');
await mkdir(dirname(testPath), { recursive: true });
await writeFile(
testPath,
JSON.stringify([{ name: 'Michael' }, { name: 'Alice' }])
);
const testPath = join(baseDir, 'unsorted-users.json');

const { code } = await executeProcess({
command: 'npx',
Expand All @@ -37,7 +31,34 @@ describe('CLI command - sort', () => {
expect(code).toBe(0);

const content = (await readFile(testPath)).toString();
expect(JSON.parse(content)).toEqual([
expect(JSON.parse(content)).toStrictEqual([
{ name: 'Alice' },
{ name: 'Michael' },
]);
});

it('should execute CLI command sort on sorted file', async () => {
const testPath = join(baseDir, 'sorted-users.json');

const contentBefore = (await readFile(testPath)).toString();
expect(JSON.parse(contentBefore)).toStrictEqual([
{ name: 'Alice' },
{ name: 'Michael' },
]);

const { code } = await executeProcess({
command: 'npx',
args: objectToCliArgs({
_: ['cli', 'sort'],
filePath: basename(testPath),
}),
cwd: baseDir,
});

expect(code).toBe(0);

const content = (await readFile(testPath)).toString();
expect(JSON.parse(content)).toStrictEqual([
{ name: 'Alice' },
{ name: 'Michael' },
]);
Expand Down
30 changes: 30 additions & 0 deletions examples/e2e/plugin-1-e2e/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"extends": ["../../../.eslintrc.base.json", "../../../.eslintrc.base.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.json"],
"parser": "jsonc-eslint-parser",
"rules": {
"@nx/dependency-checks": [
"error",
{
"ignoredFiles": ["{projectRoot}/vite.config.{js,ts,mjs,mts}"]
}
]
}
}
]
}
19 changes: 19 additions & 0 deletions examples/e2e/plugin-1-e2e/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "plugin-1-e2e",
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "projects/cli-e2e/test",
"projectType": "application",
"tags": ["type:e2e", "type:e2e-vi", "type:example"],
"implicitDependencies": ["cli", "plugin-1"],
"targets": {
"lint": {},
"e2e": {
"executor": "@nx/vite:test",
"inputs": ["default", "^production"],
"outputs": ["{options.reportsDirectory}"],
"options": {
"reportsDirectory": "../../../coverage/projects/cli-e2e"
}
}
}
}
50 changes: 50 additions & 0 deletions examples/e2e/plugin-1-e2e/test/cli-plugin-1-sort.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { dirname, join, basename } from 'node:path';
import { afterEach, describe, expect, it } from 'vitest';
import { mkdir, readFile, rm, writeFile } from 'node:fs/promises';
import { executeProcess, objectToCliArgs } from '@push-based/test-utils';
import {
getTestFixturesDist,
getTestEnvironmentRoot,
} from '@push-based/test-utils';

describe('CLI command - sort -p plugin-1', () => {
const fixturesDist = getTestFixturesDist('cli-command-sort', {
root: getTestEnvironmentRoot(process.env['NX_TASK_TARGET_PROJECT']),
});

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

it('should execute CLI command sort when param file is given', async () => {
const testPath = join(
fixturesDist,
'execute-sort-command-with-plugin',
'users.json'
);
await mkdir(dirname(testPath), { recursive: true });
await writeFile(
testPath,
JSON.stringify([{ name: 'B' }, { name: 'A' }, { name: 'C' }])
);

const { code } = await executeProcess({
command: 'npx',
args: objectToCliArgs({
_: ['cli', 'sort', '-p @push-based/plugin-1'],
filePath: basename(testPath),
}),
cwd: dirname(testPath),
verbose: true,
});

expect(code).toBe(0);

const content = (await readFile(testPath)).toString();
expect(JSON.parse(content)).toStrictEqual([
{ name: 'C' },
{ name: 'B' },
{ name: 'A' },
]);
});
});
19 changes: 19 additions & 0 deletions examples/e2e/plugin-1-e2e/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"module": "esnext",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
},
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.spec.json"
}
]
}
26 changes: 26 additions & 0 deletions examples/e2e/plugin-1-e2e/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../../dist/out-tsc",
"types": [
"vitest/globals",
"vitest/importMeta",
"vite/client",
"node",
"vitest"
]
},
"include": [
"vite.config.ts",
"vitest.config.ts",
"test/**/*.test.ts",
"test/**/*.spec.ts",
"test/**/*.test.tsx",
"test/**/*.spec.tsx",
"test/**/*.test.js",
"test/**/*.spec.js",
"test/**/*.test.jsx",
"test/**/*.spec.jsx",
"test/**/*.d.ts"
]
}
27 changes: 27 additions & 0 deletions examples/e2e/plugin-1-e2e/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { defineConfig } from 'vite';

import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';

export default defineConfig({
root: __dirname,
cacheDir: '../../../node_modules/.vite/projects/cli-e2e',

plugins: [nxViteTsPaths()],

// Uncomment this if you are using workers.
// worker: {
// plugins: [ nxViteTsPaths() ],
// },

test: {
globals: true,
cache: { dir: '../../../node_modules/.vitest' },
environment: 'node',
include: ['test/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
reporters: ['default'],
coverage: {
reportsDirectory: '../../../coverage/projects/cli-e2e',
provider: 'v8',
},
},
});
20 changes: 17 additions & 3 deletions examples/projects/cli/src/lib/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { sortUserFile } from '@push-based/core';

export type CliArgs = {
filePath: string;
plugin?: string;
};

const NOOP_BUILDER = <T>(_: Argv<T>) => void 0;
Expand All @@ -17,13 +18,26 @@ export function cli(args: string[]) {
description: 'Path to the user file',
demandOption: true,
},
plugin: {
type: 'string',
description: 'Path to the user file',
alias: 'p',
},
} satisfies Record<keyof CliArgs, Options>)
.command('*', 'Sort users', NOOP_BUILDER, sortCommandHandle)
.command('sort', 'Sort users', NOOP_BUILDER, sortCommandHandle);
}

export async function sortCommandHandle(args: CliArgs) {
const { filePath } = args;
await sortUserFile(filePath);
console.log(`Sorted users in ${filePath}`);
const { filePath, plugin } = args;
try {
const sortFn = plugin
? await import(plugin).then(({ default: d }) => d)
: sortUserFile;
await sortFn(filePath);
console.log(`Sorted users in ${filePath}`);
} catch (error) {
console.error(`Failed to load plugin: ${plugin}`);
throw error;
}
}
Loading

0 comments on commit 5e2c9b5

Please sign in to comment.