-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
1,178 additions
and
193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,37 @@ | ||
# cli-e2e-env | ||
|
||
End-to-end tests for the `cli` library. | ||
|
||
### Changes/generated files during e2e (already refactored to multiple verdaccio instances) | ||
|
||
```sh | ||
Root/ # 👈 this is your CWD | ||
├── dist/ | ||
│ └── packages/ | ||
│ └── <project-name>/... | ||
└── tmp/ | ||
└── e2e/ | ||
└── <project-name>/ # e2e setup | ||
├── storage/... # npm publish/unpublish | ||
├── node_modules/ | ||
│ └── <org> | ||
│ └── <package-name>/... # npm install/uninstall | ||
├── __test__/... | ||
│ └── <file-name>/... # e2e beforeEach | ||
│ └── <it-block-setup>/... | ||
├── .npmrc # local npm config configured for project specific verdaccio registry | ||
├── package-lock.json # npm install/uninstall | ||
└── package.json # npm install/uninstall | ||
``` | ||
|
||
### Troubleshooting | ||
|
||
- `nx start-server` | ||
- `nx start-server <project-name>` | ||
- `nx start-server <project-name> --storage tmp/e2e/<project-name>/storage` | ||
- `nx start-env` | ||
- `nx start-env <project-name> --workspaceRoot tmp/e2e/<project-name>` | ||
- `nx npm-publish <project-name> --envProject=<env-project-name>` | ||
- `nx run-many -t npm-publish --envProjectName=cli-e2e-env` | ||
- `nx npm-install <project-name> --envProject=<env-project-name>` | ||
- `nx run-many -t npm-install --envProjectName=cli-e2e-env` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,75 @@ | ||
import { executeProcess } from '@org/test-utils'; | ||
import { NpmTestEnvResult, startNpmEnv } from '../../../tools/utils/env'; | ||
import { executeProcess, objectToCliArgs } from '@org/test-utils'; | ||
import { NpmTestEnvResult } from '../../../tools/utils/env'; | ||
import { join, relative } from 'node:path'; | ||
import { rm } from 'node:fs/promises'; | ||
import { VerdaccioExecuterOptions } from '../../../tools/utils/registry'; | ||
import { readJsonFile } from '@nx/devkit'; | ||
|
||
const isVerbose: boolean = process.env.NX_VERBOSE_LOGGING === 'true' ?? false; | ||
const teardownEnv: boolean = process.env.E2E_TEARDOWN_ENV !== 'false'; | ||
// DEBUG FLAGS | ||
const isVerbose: boolean = true; // process.env.NX_VERBOSE_LOGGING === 'true' ?? false; | ||
const teardownEnv: boolean = true; //process.env.E2E_TEARDOWN_ENV !== 'false'; | ||
const teardownRegistry: boolean = true; //process.env.E2E_TEARDOWN_REGISTRY !== 'false'; | ||
|
||
let activeRegistry: NpmTestEnvResult; | ||
const projectName = process.env['NX_TASK_TARGET_PROJECT']; | ||
let stopRegistry; | ||
|
||
export async function setup() { | ||
// start registry | ||
activeRegistry = await startNpmEnv({ | ||
projectName, | ||
workspaceRoot: join('tmp', 'e2e', projectName), | ||
targetName: 'start-verdaccio', | ||
await executeProcess({ | ||
command: 'nx', | ||
args: objectToCliArgs< | ||
Partial< | ||
VerdaccioExecuterOptions & { | ||
_: string[]; | ||
} | ||
> | ||
>({ | ||
_: ['start-env', projectName ?? '', '--'], | ||
verbose: isVerbose, | ||
clear: true, | ||
readyWhen: 'Environment ready under', | ||
}), | ||
verbose: isVerbose, | ||
clear: true, | ||
shell: true, | ||
}); | ||
|
||
const { registry, workspaceRoot, stop } = activeRegistry; | ||
stopRegistry = stop; | ||
const workspaceRoot = join('tmp', 'npm-env', projectName); | ||
activeRegistry = await readJsonFile( | ||
join(workspaceRoot, 'verdaccio-registry.json') | ||
); | ||
const { registry } = activeRegistry; | ||
stopRegistry = () => process.kill(Number(registry.pid)); | ||
|
||
const { url } = registry; | ||
const userconfig = join(workspaceRoot, '.npmrc'); | ||
// package publish all projects | ||
await executeProcess({ | ||
command: 'nx', | ||
args: ['run-many', '-t=npm-publish', `--userconfig=${userconfig}`], | ||
observer: { | ||
onStdout: (stdout) => { | ||
if (isVerbose) { | ||
console.info(stdout); | ||
} | ||
}, | ||
onStderr: (stdout) => { | ||
if (isVerbose) { | ||
console.error(stdout); | ||
} | ||
}, | ||
}, | ||
args: objectToCliArgs({ | ||
_: ['run-many', '-t=npm-publish'], | ||
verbose: isVerbose, | ||
envProjectName: projectName, | ||
}), | ||
verbose: isVerbose, | ||
}); | ||
|
||
// package install all projects to test env folder | ||
await executeProcess({ | ||
command: 'nx', | ||
args: ['run-many', '-t=npm-install', `--prefix=${workspaceRoot}`], | ||
observer: { | ||
onStdout: (stdout) => { | ||
if (isVerbose) { | ||
console.info(stdout); | ||
} | ||
}, | ||
onStderr: (stdout) => { | ||
if (isVerbose) { | ||
console.error(stdout); | ||
} | ||
}, | ||
}, | ||
args: objectToCliArgs({ | ||
_: ['run-many', '-t=npm-install'], | ||
verbose: isVerbose, | ||
envProjectName: projectName, | ||
}), | ||
verbose: isVerbose, | ||
}); | ||
} | ||
|
||
export async function teardown() { | ||
console.table(activeRegistry); | ||
stopRegistry(); | ||
// teardownEnv && await rm(activeRegistry.workspaceRoot, {recursive: true, force: true}); | ||
if (teardownRegistry) { | ||
} | ||
await rm(activeRegistry.workspaceRoot, { recursive: true, force: true }); | ||
if (teardownEnv) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"extends": ["../../.eslintrc.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}"] | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# cli-e2e-graph | ||
|
||
End-to-end tests for the `cli` library. | ||
|
||
### Troubleshooting | ||
|
||
- `nx start-server` | ||
- `nx start-server <project-name>` | ||
- `nx start-server <project-name> --storage tmp/e2e/<project-name>/storage` | ||
- `nx start-env` | ||
- `nx start-env <project-name> --workspaceRoot tmp/e2e/<project-name>` | ||
- `nx npm-publish <project-name> --envProject=<env-project-name>` | ||
- `nx run-many -t npm-publish --envProjectName=cli-e2e-graph` | ||
- `nx npm-install <project-name> --envProject=<env-project-name>` | ||
- `nx run-many -t npm-install --envProjectName=cli-e2e-graph` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "cli-e2e-graph", | ||
"$schema": "../../node_modules/nx/schemas/project-schema.json", | ||
"sourceRoot": "projects/cli-e2e-graph/test", | ||
"projectType": "library", | ||
"tags": ["npm-env"], | ||
"targets": { | ||
"e2e": { | ||
"executor": "@nx/vite:test", | ||
"inputs": ["default", "^production"], | ||
"outputs": ["{options.reportsDirectory}"], | ||
"options": { | ||
"globalSetup": ["e2e/cli-e2e-graph/setup/global-setup.ts"], | ||
"reportsDirectory": "../../coverage/projects/cli-e2e-graph" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { executeProcess, objectToCliArgs } from '@org/test-utils'; | ||
import { NpmTestEnvResult } from '../../../tools/utils/env'; | ||
import { join, relative } from 'node:path'; | ||
import { rm } from 'node:fs/promises'; | ||
import { VerdaccioExecuterOptions } from '../../../tools/utils/registry'; | ||
import { readJsonFile } from '@nx/devkit'; | ||
|
||
const isVerbose: boolean = process.env.NX_VERBOSE_LOGGING === 'true' ?? false; | ||
const teardownEnv: boolean = process.env.E2E_TEARDOWN_ENV !== 'false'; | ||
|
||
let activeRegistry: NpmTestEnvResult; | ||
const projectName = process.env['NX_TASK_TARGET_PROJECT']; | ||
let stopRegistry; | ||
|
||
export async function setup() { | ||
// start registry | ||
await executeProcess({ | ||
command: 'nx', | ||
args: objectToCliArgs< | ||
Partial< | ||
VerdaccioExecuterOptions & { | ||
_: string[]; | ||
verbose: boolean; | ||
cwd: string; | ||
} | ||
> | ||
>({ | ||
_: ['start-verdaccio', projectName ?? ''], | ||
workspaceRoot: join('tmp', 'npm-env', projectName), | ||
verbose: isVerbose, | ||
clear: true, | ||
}), | ||
shell: true, | ||
}); | ||
|
||
activeRegistry = await readJsonFile( | ||
join('tmp', 'npm-env', projectName, 'verdaccio-registry.json') | ||
); | ||
const { registry, workspaceRoot, stop } = activeRegistry; | ||
stopRegistry = process.kill(Number(registry.pid)); | ||
|
||
const { url } = registry; | ||
const userconfig = join(workspaceRoot, '.npmrc'); | ||
// package publish all projects | ||
await executeProcess({ | ||
command: 'nx', | ||
args: ['run-many', '-t=npm-publish', `--userconfig=${userconfig}`], | ||
observer: { | ||
onStdout: (stdout) => { | ||
if (isVerbose) { | ||
console.info(stdout); | ||
} | ||
}, | ||
onStderr: (stdout) => { | ||
if (isVerbose) { | ||
console.error(stdout); | ||
} | ||
}, | ||
}, | ||
}); | ||
|
||
// package install all projects to test env folder | ||
await executeProcess({ | ||
command: 'nx', | ||
args: ['run-many', '-t=npm-install', `--prefix=${workspaceRoot}`], | ||
observer: { | ||
onStdout: (stdout) => { | ||
if (isVerbose) { | ||
console.info(stdout); | ||
} | ||
}, | ||
onStderr: (stdout) => { | ||
if (isVerbose) { | ||
console.error(stdout); | ||
} | ||
}, | ||
}, | ||
}); | ||
} | ||
|
||
export async function teardown() { | ||
const s = readJsonFile(''); | ||
stopRegistry(); | ||
teardownEnv && | ||
(await rm(activeRegistry.workspaceRoot, { recursive: true, force: true })); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { dirname, join } from 'node:path'; | ||
import { afterEach, describe, expect, it } from 'vitest'; | ||
import { mkdir, readFile, rm, writeFile } from 'node:fs/promises'; | ||
import { execSync } from 'node:child_process'; | ||
|
||
describe('CLI command - sort', () => { | ||
const baseDir = 'tmp/e2e/cli-e2e-graph/sort'; | ||
|
||
afterEach(async () => { | ||
// await rm(baseDir, {recursive: true, force: true}); | ||
}); | ||
|
||
it('should execute CLI command sort when param file is given', async () => { | ||
const testPath = join(baseDir, 'file-sort', 'users.json'); | ||
await mkdir(dirname(testPath), { recursive: true }); | ||
await writeFile( | ||
testPath, | ||
JSON.stringify([{ name: 'Michael' }, { name: 'Alice' }]) | ||
); | ||
|
||
expect(() => execSync(`npx @org/cli sort --file="${testPath}"`)).toThrow( | ||
'Command failed: npx @org/cli sort --file="tmp/cli-e2e-graph/sort/file-sort/users.json"' | ||
); | ||
/* | ||
const content = (await readFile(testPath)).toString(); | ||
expect(JSON.parse(content)).toEqual([ | ||
{name: 'Alice'}, | ||
{name: 'Michael'}, | ||
]); | ||
*/ | ||
}); | ||
}); |
Oops, something went wrong.