diff --git a/e2e/cli-e2e-original/README.md b/e2e/cli-e2e-original/README.md index cc100c68..6a94aa75 100644 --- a/e2e/cli-e2e-original/README.md +++ b/e2e/cli-e2e-original/README.md @@ -2,19 +2,10 @@ End-to-end tests for the `cli` library. -## Running the tests +## Included plugins +- `tools/plugins/original.plugin.ts` -- `nx e2e cli-e2e-original` - run E2E tests for the `cli-e2e-original` library. - - run vitest setup - `e2e/cli-e2e-original/setup/global-setup.ts#setup` - - `nx local-registry --storage` - - `nx run-many --targets=nx-release-publish` - - `nx run-many --targets=npm-install-e2e` - - run tests - - run vitest teardown - `e2e/cli-e2e-original/setup/global-setup.ts#teardown` - - stop server - - delete folder - -### Included targets +### Dynamic targets generated by the plugin - `workspace-source` - targets @@ -29,6 +20,19 @@ End-to-end tests for the `cli` library. - `original-npm.install` - `original-npm-uninstall` + +## Running the tests + +- `nx e2e cli-e2e-original` - run E2E tests for the `cli-e2e-original` library. + - run vitest setup - `e2e/cli-e2e-original/setup/global-setup.ts#setup` + - `nx local-registry --storage` + - `nx run-many --targets=nx-release-publish` + - `nx run-many --targets=npm-install-e2e` + - run tests + - run vitest teardown - `e2e/cli-e2e-original/setup/global-setup.ts#teardown` + - stop server + - delete folder + ### Changed or generated files during e2e ```sh @@ -55,6 +59,96 @@ User/ ## Troubleshooting -- `nx start-server` -- `nx start-server ` -- `nx start-server --storage tmp/e2e//storage` +### Is my environment free up from any artefacts from previous runs? + +1. Check if any package is installed from previouse runs + - run `npm ls ` to see if the package is installed in your workspace + Example output: +```sh +@org/source@0.0.0 /Users// +└── /@0.0.1 # 👈 this is a potential left over package from your e2e test +``` +1. 1. Remove the package from your workspace + - run `nx run-many -t npm-uninstall-original` to remove the package from your workspace + Example output of clean `npm ls ` run: + +```sh +@org/source@0.0.0 /Users// +└── (empty) +``` + +### Is my environment free up from any configuration from previous runs? + +1. Check if your environment is clean + - run `npm config list -ls` to see if there are any unexpected registries or tokens in any of your config files + Example Output: +```sh +; "default" config from default values +# ... +metrics-registry = "http://localhost:4873/" +prefix = "/usr/local" +# ... +; registry = "https://registry.npmjs.org/" ; overridden by user +# ... +userconfig = "/Users/michael_hladky/.npmrc" +# ... +; "user" config from /Users/michael_hladky/.npmrc + +registry = "http://localhost:4873/" # 👈 this is a potential left over configuration form your e2e test + +; "cli" config from command line options + +# ... +``` + +- Clean potential entries from your OS user specific npm config + - `npm config delete registry` + - `npm config delete :_authToken` + +Example output after cleanup: +```sh +; "default" config from default values + +# ... +metrics-registry = "https://registry.npmjs.org/" +prefix = "/usr/local" +registry = "https://registry.npmjs.org/" +# ... +userconfig = "/Users/michael_hladky/.npmrc" +# ... +; "cli" config from command line options + +# ... +``` + +### Is Verdaccio server running correctly? + +While the tests are running you can open your browser and visit http://localhost:/ to see the Verdaccio web interface. + +To start it manually do the following steps: +1. Start local registry manually with `nx local-registry --verbose` - logs port +2. 1. Run `npm config list -ls` to see if the registry and auth token are configured correctly + Example output with correct configuration: +```sh +; "default" config from default values +# ... +metrics-registry = "http://localhost:4873/" +prefix = "/usr/local" +# ... +; registry = "https://registry.npmjs.org/" ; overridden by user +# ... +userconfig = "/Users/michael_hladky/.npmrc" +# ... +; "user" config from /Users/michael_hladky/.npmrc + +//localhost:4874/:_authToken = (protected) # 👈 this is the auth token for your Verdaccio registry +registry = "http://localhost:4873/" # 👈 this the default registry + +; "cli" config from command line options + +# ... +``` +2. 2. Check if a package is published with `nx npm-check --registry=http://localhost:4873` +Example of an empty web interface: + +### Is my e2e script publishing to the right registry? diff --git a/e2e/cli-e2e-original/setup/global-setup.ts b/e2e/cli-e2e-original/setup/global-setup.ts index fb91cf09..dc2d4d23 100644 --- a/e2e/cli-e2e-original/setup/global-setup.ts +++ b/e2e/cli-e2e-original/setup/global-setup.ts @@ -8,7 +8,7 @@ import { configureRegistry, unconfigureRegistry, } from '../../../tools/utils/npm'; -import * as process from 'process'; +import * as process from "process"; const isVerbose: boolean = true; // process.env.NX_VERBOSE_LOGGING === 'true' ?? false; @@ -26,25 +26,25 @@ export async function setup() { // configure env with verdaccio registry as default // exec commands: - // - `npm config set //${host}:${port}/:_authToken "secretVerdaccioToken"` // - `npm config set registry "${url}"` + // - `npm config set //${host}:${port}/:_authToken "secretVerdaccioToken"` configureRegistry(registry, isVerbose); // package publish all projects await executeProcess({ command: 'nx', - args: objectToCliArgs({ _: ['run-many'], targets: 'nx-release-publish' }), + args: objectToCliArgs({ _: ['run-many'], targets: 'nx-release-publish,!tag:type:testing', exclude: 'tag:type:testing', skipNxCache: true }), verbose: isVerbose, }); // package install all projects await executeProcess({ command: 'nx', - args: objectToCliArgs({ _: ['run-many'], targets: 'original-npm-install' }), + args: objectToCliArgs({ _: ['run-many'], targets: 'original-npm-install', force: true, exclude: 'tag:type:testing', skipNxCache: true}), verbose: isVerbose, }); } - +/* export async function teardown() { // uninstall all projects await executeProcess({ @@ -62,3 +62,4 @@ export async function teardown() { // unconfigureRegistry(activeRegistry, isVerbose); // await rm(activeRegistry.storage, {recursive: true, force: true}); } +*/ diff --git a/e2e/cli-e2e-original/test/cli-command-sort.spec.ts b/e2e/cli-e2e-original/test/cli-command-sort.spec.ts index 3a8edefa..4cf46700 100644 --- a/e2e/cli-e2e-original/test/cli-command-sort.spec.ts +++ b/e2e/cli-e2e-original/test/cli-command-sort.spec.ts @@ -27,7 +27,6 @@ describe('CLI command - sort', () => { _: ['@org/cli', 'sort'], file: testPath, }), - cwd: workspaceRoot, verbose: true, }) ).rejects.toThrow( diff --git a/e2e/cli-e2e-original/vite.config.ts b/e2e/cli-e2e-original/vite.config.ts index 2e7dbda0..ff27e18c 100644 --- a/e2e/cli-e2e-original/vite.config.ts +++ b/e2e/cli-e2e-original/vite.config.ts @@ -4,7 +4,7 @@ import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin'; export default defineConfig({ root: __dirname, - cacheDir: '../../node_modules/.vite/projects/cli', + cacheDir: '../../node_modules/.vite/projects/cli-e2e-original', plugins: [nxViteTsPaths()], @@ -21,7 +21,7 @@ export default defineConfig({ reporters: ['default'], globalSetup: ['./setup/global-setup.ts'], coverage: { - reportsDirectory: '../../coverage/projects/cli', + reportsDirectory: '../../coverage/projects/cli-e2e-original', provider: 'v8', }, }, diff --git a/images/registry-web-interface--packages-published.png b/images/registry-web-interface--packages-published.png new file mode 100644 index 00000000..03324908 Binary files /dev/null and b/images/registry-web-interface--packages-published.png differ diff --git a/package-lock.json b/package-lock.json index bbed547c..1ba9778f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,7 +19,8 @@ "@nx/vite": "18.2.4", "@nx/web": "18.2.4", "@nx/workspace": "18.2.4", - "@org/cli": "^0.0.1", + "@org/core": "^0.0.1", + "@org/models": "^0.0.1", "@org/utils": "^0.0.1", "@swc-node/register": "~1.8.0", "@swc/core": "^1.7.22", @@ -30,6 +31,7 @@ "@typescript-eslint/parser": "^7.3.0", "@vitest/coverage-v8": "^1.0.4", "@vitest/ui": "^1.3.1", + "0.0.1": "^1.0.1", "ansis": "^3.3.2", "esbuild": "^0.19.2", "eslint": "~8.57.0", @@ -3083,14 +3085,17 @@ "yargs-parser": "21.1.1" } }, - "node_modules/@org/cli": { + "node_modules/@org/core": { "version": "0.0.1", - "resolved": "http://localhost:4874/@org/cli/-/cli-0.0.1.tgz", - "integrity": "sha512-B6SUXBm+5F9ssThtbWg/350RS5aIPSFnUo7fqXSwbYyrrL2DZUm8rENj3G0Cae3Cu/8bFLQNdiLSRwgoWIVNDA==", - "dev": true, - "bin": { - "cli": "bin.js" - } + "resolved": "http://localhost:4874/@org/core/-/core-0.0.1.tgz", + "integrity": "sha512-M7SyZfwbLmbHyMOxB+8D96VvU7mH480zMC+De6fbdFYWx8nOeLkXYVzXTwxtuHkErSEqk83LikGccd34fzUOKg==", + "dev": true + }, + "node_modules/@org/models": { + "version": "0.0.1", + "resolved": "http://localhost:4874/@org/models/-/models-0.0.1.tgz", + "integrity": "sha512-GEBzUXAN/xxQ/JGNEGwu2b84Se3CRdwAGdYMq804qjUOhnZ6st5tz9Ar5dmwP0BZwyaosqqDGZh46bmbtftqnQ==", + "dev": true }, "node_modules/@org/utils": { "version": "0.0.1", @@ -4729,6 +4734,15 @@ "js-yaml": "bin/js-yaml.js" } }, + "node_modules/0.0.1": { + "version": "1.0.1", + "resolved": "http://localhost:4874/0.0.1/-/0.0.1-1.0.1.tgz", + "integrity": "sha512-JFo/aW+XMmEG2MX2Yt8czayyYsvm1jwtWJatNH6gJDdA/RVR3T94W4p8/nbRKemt2OXmM3evDP0pwO3mHYarqQ==", + "dev": true, + "dependencies": { + "express": "^4.13.3" + } + }, "node_modules/abort-controller": { "version": "3.0.0", "dev": true, diff --git a/package.json b/package.json index 54dcd35b..028bfc29 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,8 @@ "@nx/vite": "18.2.4", "@nx/web": "18.2.4", "@nx/workspace": "18.2.4", - "@org/cli": "^0.0.1", + "@org/core": "^0.0.1", + "@org/models": "^0.0.1", "@org/utils": "^0.0.1", "@swc-node/register": "~1.8.0", "@swc/core": "^1.7.22", @@ -26,6 +27,7 @@ "@typescript-eslint/parser": "^7.3.0", "@vitest/coverage-v8": "^1.0.4", "@vitest/ui": "^1.3.1", + "0.0.1": "^1.0.1", "ansis": "^3.3.2", "esbuild": "^0.19.2", "eslint": "~8.57.0", diff --git a/testing/test-utils/project.json b/testing/test-utils/project.json index 67e63ba5..bb8665f0 100644 --- a/testing/test-utils/project.json +++ b/testing/test-utils/project.json @@ -3,7 +3,7 @@ "$schema": "../../node_modules/nx/schemas/project-schema.json", "sourceRoot": "projects/test-utils/src", "projectType": "library", - "tags": [], + "tags": ["scope:utils", "type:testing"], "targets": { "build": { "executor": "@nx/esbuild:esbuild", diff --git a/tools/plugins/original.plugin.ts b/tools/plugins/original.plugin.ts index cc9740ba..7d1e9fcc 100644 --- a/tools/plugins/original.plugin.ts +++ b/tools/plugins/original.plugin.ts @@ -52,7 +52,7 @@ function npmTargets(projectConfiguration: ProjectConfiguration) { ); return { 'original-npm-install': { - command: `npm install -D ${packageName}@{args.pkgVersion}`, + command: `npm install -D ${packageName}@{args.pkgVersion} --force`, options: { pkgVersion, }, diff --git a/tools/utils/npm.ts b/tools/utils/npm.ts index 739b3250..a55f10a8 100644 --- a/tools/utils/npm.ts +++ b/tools/utils/npm.ts @@ -1,9 +1,9 @@ -import { bold, gray, red, whiteBright, bgBlue } from 'ansis'; -import { execFileSync, execSync } from 'node:child_process'; -import { join } from 'node:path'; -import { objectToCliArgs } from '@org/test-utils'; -import { VercaddioServerResult, VerdaccioProcessResult } from './registry'; -import { ensureDirectoryExists } from './utils'; +import {bgBlue, bold, gray, red, whiteBright} from 'ansis'; +import {execFileSync, execSync} from 'node:child_process'; +import {join} from 'node:path'; +import {objectToCliArgs} from '@org/test-utils'; +import {VerdaccioProcessResult} from './registry'; +import {ensureDirectoryExists} from './utils'; export function configureRegistry( { @@ -14,6 +14,18 @@ export function configureRegistry( }: VerdaccioProcessResult & { userconfig?: string }, verbose?: boolean ) { + const setRegistry = `npm config set registry="${url}" ${objectToCliArgs({ + userconfig, + }).join(' ')}`; + if (verbose) { + console.info( + `${bgBlue( + whiteBright(bold(' Verdaccio-Env ')) + )} Set registry:\n${setRegistry}` + ); + } + execSync(setRegistry); + /** * Protocol-Agnostic Configuration: The use of // allows NPM to configure authentication for a registry without tying it to a specific protocol (http: or https:). * This is particularly useful when the registry might be accessible via both HTTP and HTTPS. @@ -33,18 +45,6 @@ export function configureRegistry( ); } execSync(setAuthToken); - - const setRegistry = `npm config set registry="${url}" ${objectToCliArgs({ - userconfig, - }).join(' ')}`; - if (verbose) { - console.info( - `${bgBlue( - whiteBright(bold(' Verdaccio-Env ')) - )} Set registry:\n${setRegistry}` - ); - } - execSync(setRegistry); } export function unconfigureRegistry(