diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml index 26dab7cd..3a50c9b3 100644 --- a/.github/actions/setup/action.yml +++ b/.github/actions/setup/action.yml @@ -9,6 +9,9 @@ inputs: runs: using: 'composite' + env: + npm_config_registry: http://localhost:4873 + YARN_REGISTRY: http://localhost:4873 steps: - name: Derive appropriate SHAs for base and head for `nx affected` commands uses: nrwl/nx-set-shas@v4 diff --git a/e2e/nx-ktor-e2e/tests/create-nx-ktor.spec.ts b/e2e/nx-ktor-e2e/tests/create-nx-ktor.spec.ts index 734ce05d..0aa46d1d 100644 --- a/e2e/nx-ktor-e2e/tests/create-nx-ktor.spec.ts +++ b/e2e/nx-ktor-e2e/tests/create-nx-ktor.spec.ts @@ -9,7 +9,7 @@ describe('create-nx-ktor', () => { beforeAll(() => { // Cleanup the test project - projectDirectory && projectDirectory && rmSync(projectDirectory, { + projectDirectory && rmSync(projectDirectory, { recursive: true, force: true, }); diff --git a/e2e/smoke/tests/smoke.test.ts b/e2e/smoke/tests/smoke.test.ts index 6a4dffdd..588a009a 100644 --- a/e2e/smoke/tests/smoke.test.ts +++ b/e2e/smoke/tests/smoke.test.ts @@ -1,12 +1,13 @@ +import { getPackageManagerCommand } from '@nx/devkit'; import { createTestProject, isLocalNxMatchingLatestFeatureVersion, runNxCommand} from '@nxrocks/common/testing'; -import { execSync, ExecSyncOptions } from 'child_process'; +import { execSync } from 'child_process'; import { rmSync } from 'fs-extra'; process.env.NODE_OPTIONS="--max-old-space-size=8192"; // to avoid oom error during the tests let projectDirectory: string; -const execSyncOptions: (cwd?:string) => ExecSyncOptions = (cwd:string = projectDirectory) => ({ +const execSyncOptions: (cwd?:string) => { silenceError?: boolean; env?: NodeJS.ProcessEnv; cwd?: string } = (cwd:string = projectDirectory) => ({ cwd: cwd, env: { ...process.env, @@ -15,7 +16,7 @@ const execSyncOptions: (cwd?:string) => ExecSyncOptions = (cwd:string = projectD GIT_AUTHOR_NAME: 'Smoke Test CI', GIT_AUTHOR_EMAIL: 'no-reply@fake.com', }, - stdio: 'inherit', + silentError: 'false', }); const bootapp = 'bootapp'; @@ -43,14 +44,14 @@ describe('nxrocks smoke tests', () => { }); it.each` - pkgManager | runCommand | addCommand | workspaceVersion | pluginVersion - ${'npm'} | ${'npx'} | ${'npm i'} | ${'latest'} | ${'0.0.0-e2e'} - ${'yarn'} | ${'yarn'} | ${'yarn add'} | ${'latest'} | ${'0.0.0-e2e'} - ${'pnpm'} | ${'pnpm exec'} | ${'pnpm add'} | ${'latest'} | ${'0.0.0-e2e'} - ${'npm'} | ${'npx'} | ${'npm i'} | ${'local'} | ${'0.0.0-e2e'} - ${'yarn'} | ${'yarn'} | ${'yarn add'} | ${'local'} | ${'0.0.0-e2e'} - ${'pnpm'} | ${'pnpm exec'} | ${'pnpm add'} | ${'local'} | ${'0.0.0-e2e'} -`(`should sucessfully run using '$workspaceVersion' Nx workspace, $pluginVersion plugins version and $pkgManager package manager`, async ({pkgManager, runCommand, addCommand, workspaceVersion, pluginVersion }) => { + pkgManager | workspaceVersion | pluginVersion + ${'npm'} | ${'latest'} | ${'0.0.0-e2e'} + ${'yarn'} | ${'latest'} | ${'0.0.0-e2e'} + ${'pnpm'} | ${'latest'} | ${'0.0.0-e2e'} + ${'npm'} | ${'local'} | ${'0.0.0-e2e'} + ${'yarn'} | ${'local'} | ${'0.0.0-e2e'} + ${'pnpm'} | ${'local'} | ${'0.0.0-e2e'} +`(`should sucessfully run using '$workspaceVersion' Nx workspace, $pluginVersion plugins version and $pkgManager package manager`, async ({pkgManager, workspaceVersion, pluginVersion }) => { if(!process.env.CI && !process.env.FORCE_SMOKE_TESTS) { console.log('Skipping smoke test because not running on CI and FORCE_SMOKE_TESTS is not set'); @@ -75,72 +76,72 @@ describe('nxrocks smoke tests', () => { `@nxrocks/nx-ktor@${pluginVersion}`, ].join(' '); - execSync(`${addCommand} ${pluginPkgs}`, execSyncOptions(projectDirectory)); + execSync(`${getPackageManagerCommand(pkgManager).addDev} ${pluginPkgs}`, execSyncOptions(projectDirectory)); runNxCommand( `generate @nxrocks/nx-spring-boot:new ${bootapp} --skip-format=false --projectType application --no-interactive`, - runCommand, + pkgManager, execSyncOptions(), ); runNxCommand( `generate @nxrocks/nx-spring-boot:new ${bootlib} --skip-format=false --projectType library --no-interactive`, - runCommand, + pkgManager, execSyncOptions(), ); runNxCommand( `generate @nxrocks/nx-quarkus:new ${quarkusapp} --skip-format=false --projectType application --no-interactive`, - runCommand, + pkgManager, execSyncOptions(), ); runNxCommand( `generate @nxrocks/nx-quarkus:new ${quarkuslib} --skip-format=false --projectType library --no-interactive`, - runCommand, + pkgManager, execSyncOptions(), ); runNxCommand( `generate @nxrocks/nx-micronaut:new ${mnApp} --skip-format=false --no-interactive`, - runCommand, + pkgManager, execSyncOptions(), ); runNxCommand( `generate @nxrocks/nx-melos:init --scriptNameSeparator=-`, - runCommand, + pkgManager, execSyncOptions(), ); runNxCommand( `generate @nxrocks/nx-ktor:new ${krApp} --skip-format=false --no-interactive`, - runCommand, + pkgManager, execSyncOptions(), ); runNxCommand( `generate @nxrocks/nx-flutter:new ${flutterapp} --template app --no-interactive`, - runCommand, + pkgManager, execSyncOptions(), ); runNxCommand( `generate @nxrocks/nx-flutter:new ${flutterlib} --template plugin --no-interactive`, - runCommand, + pkgManager, execSyncOptions(), ); execSync(`git add -A`, execSyncOptions()); execSync(`git commit -am "chore: scaffold projects"`, execSyncOptions()); - runNxCommand(`clean ${bootapp}`, runCommand, execSyncOptions()); - runNxCommand(`clean ${bootlib}`, runCommand, execSyncOptions()); - runNxCommand(`clean ${quarkusapp}`, runCommand, execSyncOptions()); - runNxCommand(`clean ${quarkuslib}`, runCommand, execSyncOptions()); - runNxCommand(`clean ${mnApp}`, runCommand, execSyncOptions()); - runNxCommand(`melos-bootstrap`, runCommand, execSyncOptions()); - runNxCommand(`clean ${flutterapp}`, runCommand, execSyncOptions()); - runNxCommand(`clean ${flutterlib}`, runCommand, execSyncOptions()); - runNxCommand(`clean ${krApp}`, runCommand, execSyncOptions()); + runNxCommand(`clean ${bootapp}`, pkgManager, execSyncOptions()); + runNxCommand(`clean ${bootlib}`, pkgManager, execSyncOptions()); + runNxCommand(`clean ${quarkusapp}`, pkgManager, execSyncOptions()); + runNxCommand(`clean ${quarkuslib}`, pkgManager, execSyncOptions()); + runNxCommand(`clean ${mnApp}`, pkgManager, execSyncOptions()); + runNxCommand(`melos-bootstrap`, pkgManager, execSyncOptions()); + runNxCommand(`clean ${flutterapp}`, pkgManager, execSyncOptions()); + runNxCommand(`clean ${flutterlib}`, pkgManager, execSyncOptions()); + runNxCommand(`clean ${krApp}`, pkgManager, execSyncOptions()); expect(true).toBeTruthy(); diff --git a/packages/common/testing/e2e/index.ts b/packages/common/testing/e2e/index.ts index 9b42ad33..ebf9c983 100644 --- a/packages/common/testing/e2e/index.ts +++ b/packages/common/testing/e2e/index.ts @@ -25,8 +25,9 @@ export function createTestProject(pkgManager: PackageManager = 'npm', projectNam const nxVersion = workspaceVersion === 'local' ? readLocalNxWorkspaceVersion() : 'latest'; + const confirm = pkgManager === 'npm' ? ' --yes' : ''; execSync( - `${getPackageManagerCommand(pkgManager).dlx} --yes create-nx-workspace@${nxVersion} ${projectName} --preset apps --nxCloud=skip --no-interactive --pm ${pkgManager}`, + `${getPackageManagerCommand(pkgManager).dlx}${confirm} create-nx-workspace@${nxVersion} ${projectName} --preset apps --nxCloud=skip --no-interactive --pm ${pkgManager}`, { cwd: dirname(projectDirectory), stdio: 'inherit', @@ -142,13 +143,14 @@ export function runCommandAsync( */ export function runNxCommandAsync( command: string, + pkgManager?: PackageManager, opts: { silenceError?: boolean; env?: NodeJS.ProcessEnv; cwd?: string } = { silenceError: false, } ): Promise<{ stdout: string; stderr: string }> { const cwd = opts.cwd ?? tmpProjPath(); if (fileExists(tmpProjPath('package.json'))) { - const pmc = getPackageManagerCommand(detectPackageManager(cwd)); + const pmc = getPackageManagerCommand(pkgManager || detectPackageManager(cwd)); return runCommandAsync(`${pmc.exec} nx ${command}`, opts); } else if (process.platform === 'win32') { return runCommandAsync(`./nx.bat %${command}`, opts); @@ -157,6 +159,23 @@ export function runNxCommandAsync( } } +/** + * Run a nx command synchronously inside the e2e directory + * @param command + * @param opts + */ +export async function runNxCommand( + command: string, + pkgManager?: PackageManager, + opts: { silenceError?: boolean; env?: NodeJS.ProcessEnv; cwd?: string } = { + silenceError: false, + } +): Promise<{ stdout: string; stderr: string; }> { + + return await runNxCommandAsync(command,pkgManager, opts); + +} + export function readJson(path: string, options?: JsonParseOptions): T { return parseJson(readFile(path), options); }