Skip to content

Commit

Permalink
test: fix smoke tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tinesoft committed Mar 29, 2024
1 parent 19b3be6 commit 981e878
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 33 deletions.
3 changes: 3 additions & 0 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion e2e/nx-ktor-e2e/tests/create-nx-ktor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('create-nx-ktor', () => {

beforeAll(() => {
// Cleanup the test project
projectDirectory && projectDirectory && rmSync(projectDirectory, {
projectDirectory && rmSync(projectDirectory, {
recursive: true,
force: true,
});
Expand Down
61 changes: 31 additions & 30 deletions e2e/smoke/tests/smoke.test.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -15,7 +16,7 @@ const execSyncOptions: (cwd?:string) => ExecSyncOptions = (cwd:string = projectD
GIT_AUTHOR_NAME: 'Smoke Test CI',
GIT_AUTHOR_EMAIL: '[email protected]',
},
stdio: 'inherit',
silentError: 'false',
});

const bootapp = 'bootapp';
Expand Down Expand Up @@ -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');
Expand All @@ -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();
Expand Down
23 changes: 21 additions & 2 deletions packages/common/testing/e2e/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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);
Expand All @@ -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<T extends object = any>(path: string, options?: JsonParseOptions): T {
return parseJson<T>(readFile(path), options);
}
Expand Down

0 comments on commit 981e878

Please sign in to comment.