Skip to content

Commit

Permalink
wip docs original
Browse files Browse the repository at this point in the history
  • Loading branch information
BioPhoton committed Sep 2, 2024
1 parent 3d5ceb8 commit 53532df
Show file tree
Hide file tree
Showing 10 changed files with 162 additions and 52 deletions.
124 changes: 109 additions & 15 deletions e2e/cli-e2e-original/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -55,6 +59,96 @@ User/

## Troubleshooting

- `nx start-server`
- `nx start-server <project-name>`
- `nx start-server <project-name> --storage tmp/e2e/<project-name>/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 <package-name>` to see if the package is installed in your workspace
Example output:
```sh
@org/[email protected] /Users/<user-name>/<workspace-root>
└── <org>/<project-name>@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 <package-name>` run:

```sh
@org/[email protected] /Users/<user-name>/<workspace-root>
└── (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 <registry-name>:_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:<port>/ 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 <project-name> --registry=http://localhost:4873`
Example of an empty web interface:

### Is my e2e script publishing to the right registry?
11 changes: 6 additions & 5 deletions e2e/cli-e2e-original/setup/global-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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({
Expand All @@ -62,3 +62,4 @@ export async function teardown() {
// unconfigureRegistry(activeRegistry, isVerbose);
// await rm(activeRegistry.storage, {recursive: true, force: true});
}
*/
1 change: 0 additions & 1 deletion e2e/cli-e2e-original/test/cli-command-sort.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ describe('CLI command - sort', () => {
_: ['@org/cli', 'sort'],
file: testPath,
}),
cwd: workspaceRoot,
verbose: true,
})
).rejects.toThrow(
Expand Down
4 changes: 2 additions & 2 deletions e2e/cli-e2e-original/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()],

Expand All @@ -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',
},
},
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 22 additions & 8 deletions package-lock.json

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

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion testing/test-utils/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion tools/plugins/original.plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
36 changes: 18 additions & 18 deletions tools/utils/npm.ts
Original file line number Diff line number Diff line change
@@ -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(
{
Expand All @@ -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.
Expand All @@ -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(
Expand Down

0 comments on commit 53532df

Please sign in to comment.